Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
var EventEmitter = require('events').EventEmitter;
var path = require('path');
var util = require('util');
var uuid = require('uuid');
var spdy = require('spdy');
var Logger = require('./logger');
var WebSocket = require('./web_socket');
// monkey patch spdy connection to get access to ping event
var originalPingHandler = spdy.Connection.prototype._handlePing;
spdy.Connection.prototype._handlePing = function() {
this.socket.emit('spdyPing', this);
originalPingHandler.apply(this, arguments);
};
function calculatePeerUrl(url, name){
var wsUrl = url.replace(/^http/, 'ws');
var peerPath = '/peers/' + name;
if(wsUrl.indexOf('/', wsUrl.length - 1) === -1) {
wsUrl = wsUrl + peerPath;
} else {
wsUrl = wsUrl.slice(0, wsUrl.length - 1) + peerPath;
}
return wsUrl;
}
var PeerClient = module.exports = function(url, server) {
var EventEmitter = require('events').EventEmitter;
var path = require('path');
var util = require('util');
var uuid = require('uuid');
var spdy = require('spdy');
var Logger = require('./logger');
var WebSocket = require('./web_socket');
// monkey patch spdy connection to get access to ping event
var originalPingHandler = spdy.Connection.prototype._handlePing;
spdy.Connection.prototype._handlePing = function() {
this.socket.emit('spdyPing', this);
originalPingHandler.apply(this, arguments);
};
function calculatePeerUrl(url, name){
var wsUrl = url.replace(/^http/, 'ws');
var peerPath = '/peers/' + name;
if(wsUrl.indexOf('/', wsUrl.length - 1) === -1) {
wsUrl = wsUrl + peerPath;
} else {
wsUrl = wsUrl.slice(0, wsUrl.length - 1) + peerPath;
}
return wsUrl;
}