/** * @param {string} message */ send(message) { if (this._ws.readyState === WebSocket.OPEN) { protocolDebug('>', message); this._ws.send(message); } }
// Broadcast stream to client (front-end). function clientBroadcast (data, settings) { stream_client_server.clients.forEach((client) => { if (client.readyState !== WebSocket.OPEN) { return; } // If this client's stream id and token match, broadcast. if (client.stream_id === settings.stream_id && client.stream_token === settings.stream_token) { client.send(data); } }); }
sendToMiner(payload: CoinHiveResponse) { const coinhiveMessage = JSON.stringify(payload); if (this.online && this.ws.readyState === WebSocket.OPEN) { try { this.ws.send(coinhiveMessage); } catch (e) { this.kill(); } } }
wss.on("connection", function(ws) { console.log("websocket connection open") ws.on("close", function() { console.log("websocket connection close") }) ws.on('error', () => console.log('errored')); ws.on('message', function incoming(data) { // Broadcast to everyone else. wss.clients.forEach(function each(client) { if (client !== ws && client.readyState === ws.OPEN) { client.send(data, function ack(error) { }); } }); }); })
/** * Function to send info to all sockets * * @param instruction * @param data */ informAllSockets(instruction, data) { if(this.socket === null) { return; } this.socket.getWss().clients.forEach(client => { // Check if connection is still open if (client.readyState !== client.OPEN) return; client.send(this.encrypt({ instruction, data })); }); }
stop() { this.stoped = true if (this.ws.readyState === 1) { this.ws.close() } }
/** * Send a payload to the Grapevine server * @param {Object} event Payload for Grapevine */ send(event) { if (this.ws.readyState === WebSocket.OPEN) { this.ws.send(JSON.stringify(event)); } }
function broadcast(type="log", data, filter=()=>true) { wss.clients.forEach(function (client) { if (client.readyState === WebSocket.OPEN && filter(client)) { client.send(obj(type, data)); } }); }
// Broadcast to all connected clients const broadcast = (data, ws) => { wss.clients.forEach(client => { if (client.readyState === WebSocket.OPEN && client !== ws) { client.send(JSON.stringify(data)); } }); }
secureSend(data) { if (this.ws.readyState === 1) { this.ws.send(data) return true } }
/** * 在线用户列表信息分发 */ function sendAllLive() { const msg = { event: 'user', from: 'server', to: 'all', username: 'server', type: 'text', data: clientLive //将所有在线用户列表分发给所有在线用户,简便处理 }; wss.clients.forEach(function each(client) { if (client.readyState === WebSocket.OPEN) { client.send( sendFormatMsg(msg, 'user') ); } }); }
socketServer.clients.forEach(function each(client) { if (client.readyState === WebSocket.OPEN) { client.send(data); } });
function broadcast(data) { wss.clients.forEach((client) => { if (client.readyState == WebSockets.OPEN) { client.send(JSON.stringify(data)) } }) }
/** * Send a payload to the Grapevine server * @param {Object} event Payload for Grapevine */ send(event) { if (this.ws.readyState === WebSocket.OPEN) { this.ws.send(JSON.stringify(event)); } }
sendToMiner(payload: CoinHiveResponse) { const coinhiveMessage = JSON.stringify(payload); if (this.online && this.ws.readyState === WebSocket.OPEN) { try { this.ws.send(coinhiveMessage); } catch (e) { this.kill(); } } }