Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use socket.io in RestApplication of loopback 4?

I have created my rest application in Loopback 4 and now I want to implement socket in it. Is there any way to do so in RestApplication?

export class MyApplication extends BootMixin(
    ServiceMixin(RepositoryMixin(RestApplication)),
) {

    constructor(
        options: ApplicationConfig = {}
    ) {
        super(options);
    }

    ....

    async start() {
        await super.start();

        const io = socketio(this.restServer);
        io.on('connection', (socket: any) => {
            console.log('connected');
        });

    }
}

const io = socketio(this.restServer); isn't working for me

like image 662
Muhammad Ali Shahzad Avatar asked Oct 30 '25 11:10

Muhammad Ali Shahzad


1 Answers

Here is a Official Loopback 4 example with socket.io integration. This example is created to explore how to expose Websocket (socket.io) endpoints in conjunction with LoopBack controllers.

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

like image 188
Manish Balodia Avatar answered Nov 02 '25 23:11

Manish Balodia



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!