Example #1
0
 ws.on('open', function() {
     ws.send('{"subscribe":"topic3"}');
     comms.publish('topic3', 'new');
 });
 setTimeout(function() {
     ws.send(Date.now().toString(), {mask: true});
 }, 500);
Example #3
0
    rl.on('line', function(message) {
        ws.send(message);

    })
Example #4
0
 send = function(o) {
   try {ws.send(JSON.stringify(o))}
   catch(e) {stderr.write("warning: exception in WebSocket send\n")}
 }
Example #5
0
 const onReply = (replyID, result) => { ws.send(JSON.stringify({replyID, result})); };
Example #6
0
 user.on("open", () => {
   return user.send(JSON.stringify(message));
 });
Example #7
0
setTimeout(function () {
  webSocket.send(JSON.stringify(filter));
}, 1000);
Example #8
0
 websocket.on('open', () => {
   websocket.send('hello world');
 });
Example #9
0
 ws.on("message",function(message){
   var moo = cowsay.say({text: message});
     ws.send(moo);
 });
Example #10
0
ws.on('open', function(req) {
	console.log(req);
	ws.send('I am an Open Event from ws client');
});
Example #11
0
 send (msg) {
   debug('Sending %j', msg)
   this.ws.send(JSON.stringify(msg))
 }
Example #12
0
	setTimeout(function() {
		ws.send(host + '');
	}, 1000);
Example #13
0
File: stress.js Project: hcit/ircd
 var send = function() {
     var args = Array.prototype.slice.call(arguments);
     var data = args.join(' ') + '\r\n';
     ws.send(data);
     //console.log('> ' + data.trim());
 };
Example #14
0
 function send(msg) {
   ws.send(JSON.stringify(msg), { mask: true }, function(err) {
     if (err) onError(err)
   })
 }
ws.on('open', function() {
    console.log("connected to SublimeSocket.");
    
    var inputIdentityJSON = 
    {
        "to" : "nodetail"
    }
    var compilationFilterJSON = 
    {
        "name": "typescript",
        "filters": [
            {
                "(.*?)[(]([0-9].*?)[,].*: error .*: (.*)": {
                    "injects": {
                        "groups[0]": "name",
                        "groups[1]": "line",
                        "groups[2]": "message"
                    },
                    "selectors": [
                        {
                            "showStatusMessage<-message": {
                                
                            }
                        },
                        {
                            "showAtLog<-message": {

                            }
                        },
                        {
                            "appendRegion<-name, line, message": {
                                "condition": "keyword"
                            }
                        }
                    ]
                }
            },
            {
                "(.*)": {
                    "injects": {
                        "groups[0]": "message"
                    },
                    "selectors": [
                        {
                            "showAtLog<-message": {}
                        }
                    ]
                }
            },
            {
                 "^typescript compile succeeded.": {
                    "selectors": [
                        {
                            "showStatusMessage": {
                                "message": "typescript compile succeeded."
                            }
                        }
                    ]
                }
            },
            {
                 "^typescript compile failure.": {
                    "selectors": [
                        {
                            "showStatusMessage": {
                                "message": "typescript compile failure."
                            }
                        }
                    ]
                }
            }
        ]
    };

    var quickfixFilterJSON = {
        "name": "quickfix",
        "filters": [
            {
                // open it.
                "^open:(.*) :.*": {
                    "injects": {
                        "groups[0]": "path"
                    },
                    "selectors": [
                        {
                            "openFile<-path": {}
                        }
                    ]
                }
            },
            {
                "(.*)": {
                    "injects": {
                        "groups[0]": "message"
                    },
                    "selectors": [
                        {
                            "showAtLog<-message": {}
                        }
                    ]
                }
            }
        ]
    }

    var cursorModifyReactorJSON = {
        "react": "on_selection_modified",
        "delay": 100,
        "reactors": [
            {
                "selectedRegions<-name, selecteds": {
                    "selectors":[
                        {
                            "generate filtring source for quickfix/transform<-path, crossed, messages, to, line": {
                                "code": "import os\nname = os.path.basename(inputs[\"path\"])\nonselected = []\nmessages = inputs[\"messages\"]\nto = inputs[\"to\"]\nline = inputs[\"line\"]\nfor message in messages:\n\tselector = []\n\tfilteringContents = {\"name\":\"quickfix\", \"source\":message+\" @to \"+str(to)+\"  @line \"+str(line)+\" @on \"+name}\n\tfilteringAPI = {\"filtering\":filteringContents}\n\tselector.append(filteringAPI)\n\ttooltipItem = {}\n\ttooltipItem[message] = selector\n\tonselected.append(tooltipItem)\noutput({\"name\":name, \"onselected\":onselected, \"message\": messages[0]})\n",
                                "selectors": [
                                    {
                                        "clearSelection<-name": {

                                        }
                                    },
                                    {
                                        "afterAsync<-name, onselected": {
                                            "identity": "waitForClearSelection",
                                            "ms": 100,
                                            "selectors": [
                                                {
                                                    "showToolTip<-name, onselected": {
                                                        "oncancelled": [
                                                        ]
                                                    }
                                                }
                                            ]
                                        }
                                    }
                                ]
                            }
                        }
                    ]
                }
            }
        ]
    };

    var saveReactorJSON = {
        "react": "on_post_save",
        "delay": 100,
        "reactors": [
            {
                "eraseAllRegions":{
                    "selectors": [
                        {
                            "showAtLog<-deletes": {
                                "format": "the [deletes]"
                            }
                        }
                    ]
                }
            },
            {
                "afterAsync": {
                    "identity": "typescript-compilation",
                    "ms": 1,
                    "selectors": [
                        {
                            "showStatusMessage": {
                                "message": "typescript compiling..."
                            }
                        },
                        {
                            "showAtLog": {
                                "message": "typescript compiling..."
                            }
                        },
                        {
                            "runShell": {
                                "main": "/bin/sh",
                                "":[
                                    tscwithenvPath, projectPath
                                ]
                                // , "debug": true
                            }
                        }
                    ]
                }
            }
            
        ] 
    };

    var showUnopenedFile = {
        "react": "ss_f_noViewFound",
        "injects": {
            "name": "targetViewName",
            "message": "reason"
        },
        "reactors": [
            {
                "appendRegion<-targetViewName, reason": {
                    "format": "open:[targetViewName] :[reason]",
                    "name": "ss_viewkey_current",
                    "line": 1,
                    "condition": "constant.language"
                }
            }
        ]
    }
    
    var setUpDone = {
        "message": "SublimeSocket : typescript-compilation sequence ready!"
    };

    ws.send("ss@changeIdentity:"+JSON.stringify(inputIdentityJSON)
        +"->defineFilter:"+JSON.stringify(compilationFilterJSON)
        +"->defineFilter:"+JSON.stringify(quickfixFilterJSON)
        +"->setViewReactor:"+JSON.stringify(cursorModifyReactorJSON)
        +"->setViewReactor:"+JSON.stringify(saveReactorJSON)
        +"->setViewReactor:"+JSON.stringify(showUnopenedFile)
        +"->showAtLog:"+JSON.stringify(setUpDone)
        +"->showStatusMessage:"+JSON.stringify(setUpDone)
    );

    tail = new Tail(logPath);
    tail.on("line", function(message) {
        console.log("tsc: "+message);

        var tailedLogMessage = {
            "name": "typescript",
            "source": message
            // , "debug": true
        };
        
        ws.send("ss@filtering:" + JSON.stringify(tailedLogMessage));
    });
});
ws.on('open', function open() {
  ws.send('something');
});
Example #17
0
 transport.send = function (msg) {
    var payload = transport.serializer.serialize(msg);
    websocket.send(payload, {binary: transport.serializer.BINARY});
 };
Example #18
0
 out.on('open', function() {
   isOutOpen = true;
   while (initialIncomingBuffer.length) {
     out.send(initialIncomingBuffer.pop());
   }
 });
Example #19
0
 this.socket.on('open', () => {
   debug.log('Connected')
   this.socket.send('login:'******':' + this.options.userSecret)
 })
 ws.addEventListener('open', function(event) {
   ws.send("ejiejie");
 });
Example #21
0
ws.on('open',function(){
    ws.send('hello world');
});
Example #22
0
		function broadcastAssign(symbol, value) {
			ws.send(JSON.stringify({action: "assign", symbol: symbol, value: value}));
		}
Example #23
0
process.stdin.on('readable', function() {
  var chunk = process.stdin.read();
  if (chunk !== null) {
    ws.send(chunk.trim());
  }
});
Example #24
0
	ws.on('open', function() {
		console.log("Network connection open...");
		ws.send(nrKey);

		var sp = new SerialPort(arduinoDevice, { baudrate: 115200, autoOpen: false });

		var arduino_connected = false;

		pinModes = [];

		for (var i=0; i<14; i++) {
			pinModes[i] = "IN";
		}

		function sendCommand(pin, value, command) {
			var buf = new Buffer(4);
			buf.writeUInt8(pin, 0);
			buf.writeUInt16LE(value, 1);
			buf.writeUInt8(command, 3);
			//console.log(buf);
			sp.write(buf);
		}

		function pinMode(pin, mode) {
			var val = 0;
	
			pinModes[pin] = mode;

			switch(mode) {
			case "IN":	val = 1; break;
			case "OUT":	val = 0; break;
			default:	return;
			}

			sendCommand(pin, val, 1);
		}

		function writeDigitalPin(pin, val) {
			//if (val > 255) val = true;
			if (val < 0) val = false;

			var type = typeof val;
			if (type == "boolean") {
				if (pinModes[pin] != "OUT") {
					pinMode(pin, "OUT");
				}
				sendCommand(pin, (val) ? 1 : 0, 3);
			} else if (type == "number") {
				if (pinModes[pin] != "OUT") {
						pinMode(pin, "OUT");
				}
				sendCommand(pin, val, 4);
			}
		}

		function inputHandler(name, value) {
			if (name.charAt(0) == "d") {
				if (value) pinMode(parseInt(name.substring(1)), "IN");
				else pinMode(parseInt(name.substring(1)), "OUT");
			}
		}

		function enabledHandler(name, value) {
			if (value) {
				sendCommand(50+parseInt(name.substring(1)), 1, 1);
			} else {
				sendCommand(50+parseInt(name.substring(1)), 0, 1);
			}
		}

		function digitalHandler(name, value) {
			writeDigitalPin(parseInt(name.substring(1)), value);
		}

		function analogHandler(name, value) {
			// Doesn't accept writes
		}

		function servoHandler(name, value) {
			if (value && name == "d9") {
				sendCommand(9, 1, 5);
			}
		}

		function toneHandler(dummy, pin) {
			sendCommand(pin, 1, 6);
		}

		arduinoHandlers = {
			"input": inputHandler,
			"enabled": enabledHandler,
			"digital": digitalHandler,
			"analog": analogHandler,
			"servo": servoHandler,
			"tone": toneHandler
		}

		/**
		 * Process assign events by parsing arduino observable names and directing
		 * to correct handler.
		 */
		ws.on('message', function(data, flags) {
			var struct = JSON.parse(data);

			if (!arduino_connected) return;

			for (var i=0; i<struct.length; i++) {
				if (struct[i].code && struct[i].code.action == "assign") {
					var name = struct[i].code.symbol;
					var val = struct[i].code.value;

					// Send change to arduino device...
					var components = name.split("_");
					if (components.length >= 2 && components[0] == "arduino") {
						if (arduinoHandlers[components[1]]) {
							arduinoHandlers[components[1]]((components.length == 3) ? components[2] : undefined, val);
						} else if (components[1].charAt(0) == "d") {
							arduinoHandlers.digital(components[1], val);
						} else if (components[1].charAt(0) == "a") {
							arduinoHandlers.analog(components[1], val);
						}
					}
				}
			}
		});

		var cacheData = [];

		function broadcastAssign(symbol, value) {
			ws.send(JSON.stringify({action: "assign", symbol: symbol, value: value}));
		}

		function processSerialData(obj) {
			var pin = obj[0];

			if (pin < 50) {
				var val = obj[1];
				//ws.send(JSON.stringify({action: "assign", symbol: "arduino_d"+pin, value: (val > 0) ? true : false}));
				broadcastAssign("arduino_d"+pin, (val > 0) ? true : false);
			} else {
				var val = obj[1] + (obj[2]*256);
				//ws.send(JSON.stringify({action: "assign", symbol: "arduino_a"+(pin-50), value: val}));
				broadcastAssign("arduino_a"+(pin-50), val);
			}
		}

		function serialHandlers() {
			sp.on('error', function(error) {
				console.log(error);
				arduino_connected = false;
				broadcastAssign("arduino_connected", false);
				broadcastAssign("arduino_error", error);

				setTimeout(function() {
					sp.open();
				}, 2000);
			});


			sp.on('open', function() {
				arduino_connected = true;
				broadcastAssign("arduino_connected", true);
				console.log("Arduino connected...");

				sp.on('close', function() {
					arduino_connected = false;
					broadcastAssign("arduino_connected", false);
					console.log("Arduino disconnected.");
					setTimeout(function() {
						serialHandlers();
						sp.open();
					}, 10000);
				});


				sp.on('data', function(data) {
					var i = 0;

					while (i < data.length) {
						if (cacheData.length == 0) {
							cacheData.push(data[i]);
							i++;
						}

						var pin = cacheData[0];
						var expect = (pin < 50) ? 2 : 3;

						while (i < data.length && cacheData.length < expect) {
							cacheData.push(data[i]);
							i++;
						}

						if (expect == cacheData.length) {
							processSerialData(cacheData);
							cacheData = [];
						}
					}
				});
			});
		}

		serialHandlers();
		sp.open();
	});
Example #25
0
File: hw.js Project: wwilco/wdiall
ws.on("message", function(message){
  ws.send("hey server");
});
 setTimeout(function timeout() {
   ws.send(`Presence: siddharth mishra on client.${Date.now()}`); 
 }, 500);
ws.on('open', function() {
    console.log('connected');
    ws.send(Date.now().toString(), {mask: true});
});
ws.on('open', ()=>{
    console.log(`Connected at : ${Date.now()}`);
    ws.send(`Presence: siddharth mishra on client.${Date.now()}`); 
    console.log('Message sent.')
});
Example #29
0
ws.on('open', function () {
    console.log(`[CLIENT] open()`);
    ws.send('Hello!');
});
Example #30
0
 ws.on('open', function() {
     ws.send('{"subscribe":"topic2"}');
 });