How to use the websocket.Client.connect function in websocket

To help you get started, we’ve selected a few websocket 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 Moddable-OpenSource / moddable / examples / network / websocket / websocketclient / main.js View on Github external
ws.callback = function(message, value) {
	switch (message) {
		case Client.connect:
			trace("socket connect\n");
			break;

		case Client.handshake:
			trace("websocket handshake success\n");
			this.write(JSON.stringify({count: 1, toggle: true}));
			break;

		case Client.receive:
			trace(`websocket message received: ${value}\n`);
			value = JSON.parse(value);
			value.count += 1;
			value.toggle = !value.toggle;
			value.random = Math.round(Math.random() * 1000);
			this.write(JSON.stringify(value));
			break;