Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

loopback 4 integration with socket.io

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?

like image 678
Raeef Refai Avatar asked Oct 16 '25 19:10

Raeef Refai


1 Answers

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.

like image 87
Miroslav Bajtoš Avatar answered Oct 19 '25 11:10

Miroslav Bajtoš