You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the below code (WebsocketAPI -> getDevices) when I emit the payload(res.socket.emit(payload)) it works fine when I have just one client attached. When I have another client, only one of them get the payload. I tried invoking emit method on req.socket and res.socket both seem to play up.
When I use res.json(payload) all the clients attached get the data. Since getDevices method is invoked when a client initially connects to the server, any time a new client gets connected to server, the server pushes the payload to all the clients attached. I'm not sure where I'm going wrong. Thanks
// actual API implementationexportclassWebsocketAPI{constructor(dbService,db){console.log(this.onData);this.api=newAPIInterface(dbService,db,this.onData.bind(this));this.connectedClients={};}getDevices(req,res){returnthis.api.getDevices().then((payload)=>{//req.io.respond(payload);console.log(req.socket);//req.socket.emit(payload);res.socket.emit(payload);});}}// setting up routesexportfunctionwebsocketSetup(app,dbService,db){letwebSocketAPI=newWebsocketAPI(dbService,db);console.log('Setting up websocket');app.io.route('ax-devices',{getAll: (req,res)=>{console.log('getAll called');returnwebSocketAPI.getDevices(req,res);}});app.io.route(constants.AX_DEVICE_WRITE,(req,res)=>{console.log('Write called');returnwebSocketAPI.write(req,res);});}
The text was updated successfully, but these errors were encountered:
In the below code (WebsocketAPI -> getDevices) when I emit the payload(res.socket.emit(payload)) it works fine when I have just one client attached. When I have another client, only one of them get the payload. I tried invoking emit method on req.socket and res.socket both seem to play up.
When I use res.json(payload) all the clients attached get the data. Since getDevices method is invoked when a client initially connects to the server, any time a new client gets connected to server, the server pushes the payload to all the clients attached. I'm not sure where I'm going wrong. Thanks
The text was updated successfully, but these errors were encountered: