tlaverdure / laravel-echo-server

Socket.io server for Laravel Echo
MIT License
2.65k stars 511 forks source link

Laravel-echo-server events listeners custom callbacks #589

Open Vytautas-RA opened 2 years ago

Vytautas-RA commented 2 years ago

I need to process laravel-echo-server some events like onConnect, onDisconnecting and others.

Would be nice to have possibility to process this events with custom code additionally (for example with javascript). I've found events processing in src/echo-server.ts file. For example declare in laravel-echo-server.json file with custom functions to process events (process_onConnect, process_onDisconnecting and etc., for example) and import these functions in src/echo-servers.ts file on file with custom functions existense and invoke function in events at the end of processing function. For example:

onDisconnecting(socket: any): void {
        socket.on('disconnecting', (reason) => {
            Object.keys(socket.rooms).forEach(room => {
                if (room !== socket.id) {
                    this.channel.leave(socket, room, reason);
                }
            });
        });

       // statements to invode custom code
        if(!process_onDisconnecting)
               process_onDisconnecting(reason); 
    }