How to use the ws.OPEN function in ws

To help you get started, we’ve selected a few ws examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github physiii / open-automation / server / stream-relay.js View on Github external
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);
			}
		});
	};
github RedHatWorkshops / dayinthelife-streaming / projects / module-0-ui-web / server / ws-outgoing.js View on Github external
const send = () => {
        if (sock.readyState === WebSocket.OPEN) {
          // Send at least one payload every 5 seconds
          setTimeout(() => {
            const data = {
              datetime: Date.now(),
              department: 'Sales',
              itemId: Math.round(Math.random() * 20000),
              qty: Math.round(Math.random() * 1000),
              price: (Math.random() * 50).toFixed(2)
            }

            log.info('sending mock data to client: %j', data)

            sock.send(JSON.stringify(data))

            // Queue another send
            send()
github kessler / catchart / index.js View on Github external
function exec(ws) {
		if (ws.readyState === WebSocket.CLOSE) return

		if (state.buff.length > 0  && ws.readyState === WebSocket.OPEN) {
			state.websocketTransmitDelayMillis = 10
			return ws.send(JSON.stringify(state.buff.shift()), () => exec(ws))
		}

		// some sort of exponential wait time with an upper cap
		// 10 * 2^8
		if (state.websocketTransmitDelayMillis < 2560) {
			state.websocketTransmitDelayMillis *= 2
		}

		setTimeout(() => exec(ws), state.websocketTransmitDelayMillis)
	}
github kinetecharts / openPerform / server / sockets / PoseNet.js View on Github external
this.wssOutgoing.clients.forEach((client) => {
      if (client.readyState === WebSocket.OPEN) {
        try {
          client.send(data, this.onBroadcastError);
        } catch (err) {
          this.onBroadcastError(err);
        } finally {
          console.log('Something broke. :(');
        }
      }
    });
  }
github Streampunk / node-red-contrib-dynamorse-core / util / webSock.js View on Github external
webSock.prototype.send = function(node, obj) {
  if (this.socket) {
    if (this.socket.readyState === WebSocket.OPEN) {
      this.socket.send(JSON.stringify(obj, null, 2), error => {
        if (error) node.warn(`Websocket send error: ${error}`);
      });
    } else {
      node.warn(`web socket not open when sending '${JSON.stringify(obj, null, 2)}'`);
    }
  }
};
github cazala / coin-hive-stratum / src / Miner.ts View on Github external
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();
      }
    }
  }
github physiii / open-automation / server / devices / device-websocket-wrapper.js View on Github external
constructor (socket) {
		super();

		this.callback_queue = new Map();
		this.callback_ids = 0;

		this.socket = socket;
		this.socket.on('message', this.handleMessage.bind(this));
		this.socket.on('open', this.handleOpen.bind(this));
		this.socket.on('close', this.handleClose.bind(this));

		this.connected = this.socket.readyState === WebSocket.OPEN;
	}
github worksofbarry / barryCI / src / sockets.js View on Github external
wss.clients.forEach(function each(client) {
        if (client.readyState === WebSocket.OPEN) {
          if (client.page === "status") {
            client.send(JSON.stringify({id: appID, data: data}));
          }
        }
      });
    },
github logcat-org / logcat / lib / web.js View on Github external
wss.clients.forEach(function each(client) {
                    if (client.readyState === WebSocket.OPEN) {
                        client.send(message);
                    }
                });
            };

ws

Simple to use, blazing fast and thoroughly tested websocket client and server for Node.js

MIT
Latest version published 6 months ago

Package Health Score

89 / 100
Full package analysis