express-ws
express-ws copied to clipboard
- message event is not firing in Router
Hello I have express-generated app and i followed and implemented the Hack as suggested at https://github.com/HenningM/express-ws/issues/104
And then i added route in app.js as follows.. app.use('/customer', customerChatHandler);
And relevant code snippet in "customerChathandler.js" is..
custChatRouter.ws('/chat', (ws, req) => {
console.log('Inside /customer/chat WebSocket Request Handler and client IP is...'+ req.connection.remoteAddress);
ws.on('message', (message) => {
console.log('received ws message as ...' + message);
})
ws.send('hello from ws conn of Custo Chat Router');
})
And relevant code on Client side html is...
const url = 'ws://localhost:3000/customer/chat';
const wsConnection = new WebSocket(url);
wsConnection.onopen(()=> {
wsConnection.send('hello ..from your WS client');
alert('open event fired');
})
wsConnection.onmessage((message) => {
alert(message);
})
- None of the OnOpen and OnMessage events on client side are fired
- also the "Onmessage" event on server side router is not getting fired.
Appreciate any hep and thanks in advance