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.

41 lines
741 B

5 years ago
const socketio = require("socket.io");
5 years ago
let io: any
5 years ago
5 years ago
function connect(server) {
io = socketio(server, {
5 years ago
// path: '/socket',
5 years ago
serveClient: false,
// below are engine.IO options
pingInterval: 10000,
pingTimeout: 5000,
cookie: false
});
5 years ago
5 years ago
io.on('connection', client => {
console.log("=> [socket.io] connected!")
client.on('event', data => { /* … */ });
client.on('disconnect', () => { /* … */ });
5 years ago
io.sockets.send('{"try":"try"}')
5 years ago
client.send('{"try":"try"}')
5 years ago
});
5 years ago
}
const send = (body) => {
5 years ago
// srvr.clients.forEach(c=>{
// if(c) c.send(body)
// })
io.sockets.send(body)
5 years ago
}
const sendJson = (object) => {
send(JSON.stringify(object))
}
export {
connect,
send,
sendJson
}