Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
this.on('upgrade', (req, socket, head) => {
if (!Faye.isWebSocket(req)) return socket.destroy();
let websocket = new Faye(req, socket, head, null, options);
//
// The WebSocket handshake is complete only when the `open` event is fired.
//
websocket.on('open', () => {
const spark = new this.Spark(
req.headers // HTTP request headers.
, req // IP address location.
, url.parse(req.url).query // Optional query string.
, null // We don't have an unique id.
, req // Reference to the HTTP req.
, websocket // Reference to the WebSocket.
);
var app = function (req, res) {
if (!req.url) {
res.end(0);
return;
}
var socket = webSocket.isWebSocket(req);
req.path = exports.getNormalizedPath(req.url.split('?')[0]);
getSetCookies(req, res);
if(helpers.emitEvent('request', req, res) === false){
return;
}
if (serve(req, res)) {
return;
}
req = fillReq(req, res);
if (!req) {
return;
var app = function (req, res) {
if (!req.url) {
res.end(0);
return;
}
var socket = webSocket.isWebSocket(req);
req.path = exports.getNormalizedPath(req.url.split('?')[0]);
getSetCookies(req, res);
if(helpers.emitEvent('request', req, res) === false){
return;
}
if (serve(req, res)) {
return;
}
req = fillReq(req, res);
if (!req) {
return;
wsserver.on('upgrade', function (request, socket, body) {
if (WebSocket.isWebSocket(request)) {
/^\/client/i.test(request.url)
? startws(request, socket, body, clients, servers)
: startws(request, socket, body, servers, clients);
}
});
wsserver.on('upgrade', function (request: http.IncomingMessage, socket: WebSocket, body: any) {
try {
if (WebSocket.isWebSocket(request)) {
console.log('ws connection at ' + request.url);
if (request.url == "/" + serveOptions.localToken + "/serial")
startSerial(request, socket, body);
else if (request.url == "/" + serveOptions.localToken + "/debug")
startDebug(request, socket, body);
else if (request.url == "/" + serveOptions.localToken + "/hid")
startHID(request, socket, body);
else if (request.url == "/" + serveOptions.localToken + "/tcp")
startTCP(request, socket, body);
else {
console.log('refused connection at ' + request.url);
socket.close(403);
}
}
} catch (e) {
console.log('upgrade failed...')
Server.prototype.authorizationHandler = function(request, socket, head)
{
return WebSocket.isWebSocket(request) ? this.onSocketConnection(new WebSocket(request, socket, head, ['websocket'], {ping: 5})) : socket.end();
}
var setupWebsocket = function(request, socket, body) {
if (WebSocket.isWebSocket(request) && request.url == '/ws/v2') {
var meshbluEventEmitter = new MeshbluEventEmitter(config.uuid, config.forwardEventUuids, sendMessage);
var ws = new WebSocket(request, socket, body);
var websocketHandler = new MeshbluWebsocketHandler({
sendMessage: sendMessage,
meshbluEventEmitter: meshbluEventEmitter
});
websocketHandler.initialize(ws, request);
}
};
this.app.on('upgrade', (request, socket, body) => {
if (!WebSocket.isWebSocket(request)) return;
var ws = new WebSocket(request, socket, body);
ws.on('message', event => {
var data = event.data, json;
try {
json = JSON.parse(event.data);
if (typeof json.command === 'string') {
this.handleCommand(json);
}
} catch(e) { }
});
ws.on('close', event => {
this.sockets = this.sockets.filter( sock => (sock !== ws) );
ws = null;
});
server.on('upgrade', function(request, socket, body) {
var ws;
var ind;
if (WebSocket.isWebSocket(request)) {
ws = new WebSocket(request, socket, body);
ind = sockets.push(ws) - 1;
onSourceCodeChange.subscribe(notify);
ws.send(JSON.stringify({ start: true, url: customFrameURL || '/run' }));
ws.on('message', onMessage);
ws.on('close', function(event) {
ws = null;
sockets[ind] = undefined;
onSourceCodeChange.unsubscribe(notify);
});
}
function notify () {
ws.send(restartNotification);