4

I'm working on a project which is built on loopback 4, and now the client is asking to have notifications and messaging.

I searched a lot to find the best way to integrate socket.io with loopback 4, no luck, I found nothing

Any ideas?

Raeef Refai
  • 1,471
  • 14
  • 26

1 Answers1

2

LoopBack 4 does not have a first-class support for websockets yet. Raymond Feng, LoopBack's architect, created an example project to demonstrate how to route socket.io messages to Controller classes, you can find the project here:

https://github.com/raymondfeng/loopback4-example-websocket/

Quoting from the README:

This example is created to explore how to expose Websocket (socket.io) endpoints in conjunction with LoopBack controllers.

Similarly as @loopback/rest, each websocket server is attached to an http/https server. WebSocket controllers are mapped to different routes (namespaces), for example:

  • /admins -> AdminController
  • /chats -> ChatController

When a client connects to the endpoint, a controller is instantiated upon the connection event of the namespace with the socket object. Controller methods can subscribe to one or more message types and send messages to one or more clients.

Miroslav Bajtoš
  • 10,667
  • 1
  • 41
  • 99
  • 2
    Is there any example or tutorial to how integrate socket with rest in loopback 4? something like sailsjs – Raeef Refai Jan 15 '19 at 11:01
  • I opened an issue on that repo asking for step to step instructions on how to integrate that code with an lb4 app generated through the CLI – Edo May 23 '19 at 16:56