You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

28 lines
476 B

import * as WebSocket from 'ws'
let srvr: any
const connect = (server) => {
srvr = new WebSocket.Server({ server, clientTracking:true })
console.log('=> [socket] connected to server')
srvr.on('connection', socket => {
console.log('=> [socket] connection received')
})
}
const send = (body) => {
srvr.clients.forEach(c=>{
if(c) c.send(body)
})
}
const sendJson = (object) => {
send(JSON.stringify(object))
}
export {
connect,
send,
sendJson
}