If writing a separate Node.js app, using the ws
package is simple. Basically:
const WebSocket = require('./meteor-app/node_modules/ws')
const ws = new WebSocket('ws://192.168.0.5:3000/websocket')
ws.on('open', () => {
console.log('connection open.')
ws.send('something')
})
ws.on('message', msg => console.log(msg))
// etc
And similarly from in a browser:
const ws = new WebSocket("ws://192.168.0.5:3000/websocket");
ws.addEventListener('open', () => {
console.log('connection open.')
ws.send('something')
})
ws.addEventListener('message', msg => console.log(msg))
// etc...
where 192.168.0.5:3000
is where the Meteor app is hosted. By default, it will be localhost:3000
when deving locally.
I couldn’t find the answer on how to do it in these forums, so thought I’d post it.