function setupWebcam() { function capture() { Webcam.capture( "picture", function( err, data ) { if( err ) { throw err; } WSS.broadcast( data ); setTimeout( capture, 25 ); }); } capture(); }
wss.on("connection", (ws) => { app.logger.info(`Web Socket Connected`) ws.on("message", (message) => { app.logger.info(`Received: ${message}`) wss.broadcast(message) }) ws.send(JSON.stringify({ user: "Node", text: "Hello from Node.js Server" })) })
// TCP Server net.createServer(function (socket) { // Identify this client socket.name = socket.remoteAddress + ":" + socket.remotePort; console.log('TCP: Receiving data from ', socket.name); socket.on('data', function (data) { if (!moov) { initFragment(data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength)); } socketServer.broadcast(data); }); socket.on('close', function(code, message){ moov = undefined; }); }).listen(STREAM_PORT);
/** successful connection */ wss.on('connection', function (ws) { /** incomming message */ ws.on('message', function (message) { /** broadcast message to all clients */ wss.broadcast(message); }); });
require('http').createServer( function(request, response) { var params = request.url.substr(1).split('/'); if( params[0] == STREAM_SECRET ) { response.connection.setTimeout(0); width = (params[1] || 320)|0; height = (params[2] || 240)|0; console.log( 'Stream Connected: ' + request.socket.remoteAddress + ':' + request.socket.remotePort + ' size: ' + width + 'x' + height ); request.on('data', function(data){ socketServer.broadcast(data, {binary:true}); }); } else { console.log( 'Failed Stream Connection: '+ request.socket.remoteAddress + request.socket.remotePort + ' - wrong secret.' ); response.end(); } }).listen(STREAM_PORT)
app.setPathMap(absolutePath, true).then(() => { log(); wss.broadcast(['log', 'reload'], [`${filename} => ${eventType}`, null], filter); }); } else { let relativePath = htmlPath.substr(this.filename.length); relativePath = relativePath.startsWith('/') ? relativePath.substr(1) : relativePath; wss.broadcast( ['log', isCssChange ? 'refreshCSS' : 'reload'], [`${filename}(${string}) => ${eventType}`, isCssChange ? [string] : null],
break default: wss.broadcast(`Error: Undefined Action: ${data.action}`) break