Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

sockstream

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sockstream - npm Package Compare versions

Comparing version 1.3.2 to 1.3.3

96

dist/sockstream.js

@@ -11,2 +11,4 @@ 'use strict';

function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

@@ -34,2 +36,9 @@

var clientName = 'sockstream.js';
var clientVersion = '1.3.3';
var defaultKeepAlive = 800;
var defaultDebugLevel = 0;
var defaultPort = 8082;
var defaultProto = 'wss://';
var defaultHost = '127.0.0.1';
this.callbackRegister = {

@@ -44,2 +53,4 @@ ping: function ping(message) {

};
this.maxKeepAliveAttempt = 20;
this.keepAliveAttempt = 0;
this.disconnect = [];

@@ -49,13 +60,11 @@ this.connections = {};

client: {
name: 'sockstream.js',
version: 1.2,
debugLevel: 0,
keepAlive: 800
name: clientName,
version: clientVersion,
debugLevel: defaultDebugLevel,
keepAlive: defaultKeepAlive
},
server: {
name: 'sockets/php-stream-socket-server',
version: 1.3,
hostname: 'localhost',
port: 8082,
proto: 'wss://'
hostname: defaultHost,
port: defaultPort,
proto: defaultProto
}

@@ -66,7 +75,7 @@ };

this._config.client = Object.assign({
debugLevel: 0,
keepAlive: 800
debugLevel: defaultDebugLevel,
keepAlive: defaultKeepAlive
}, host.client, {
name: 'sockstream.js',
version: 0.1
name: clientName,
version: clientVersion
});

@@ -76,9 +85,6 @@ }

this._config.server = Object.assign({
hostname: 'localhost',
port: 8082,
proto: 'wss://'
}, host.server, {
name: 'sockets/php-stream-socket-server',
version: 1.3
});
hostname: defaultHost,
port: defaultPort,
proto: defaultProto
}, host.server);
}

@@ -88,4 +94,4 @@ } else {

client: {
name: 'sockstream.js',
version: 0.1,
name: clientName,
version: clientVersion,
debugLevel: debugLevel,

@@ -95,4 +101,2 @@ keepAlive: keepAlive

server: {
name: 'sockets/php-stream-socket-server',
version: 1.3,
hostname: host,

@@ -119,2 +123,4 @@ port: port,

}(function (message) {
var _console2;
var type = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'log';

@@ -129,3 +135,3 @@

};
this._config.client.debugLevel >= (levelMap[type] || 0) && console[type](message);
this._config.client.debugLevel >= (levelMap[type] || 0) && (_console2 = console)[type].apply(_console2, _toConsumableArray(message));
})

@@ -209,6 +215,11 @@

this.lastConnectionId = connectionId;
this.connections[connectionId] = new WebSocket('' + this._config.server.proto + this._config.server.hostname + ':' + this._config.server.port);
try {
this.connections[connectionId] = new WebSocket('' + this._config.server.proto + this._config.server.hostname + ':' + this._config.server.port);
} catch (e) {
return;
}
if (this.connections[connectionId].readyState === this.connections[connectionId].CONNECTING) {
this.connections[connectionId].onopen = function () {
_this2.console('connected', 'info');
_this2.keepAliveAttempt = 0;
setTimeout(function () {

@@ -219,3 +230,3 @@ _this2.send('connecting', cb);

this.connections[connectionId].onerror = function (e) {
_this2.console(['WebSocket error', e], 'error');
_this2.console(e, 'error');
};

@@ -228,7 +239,9 @@ this.connections[connectionId].onmessage = function (e) {

} else if (typeof _this2.callbackRegister[parsed['@meta']._id] === 'function') {
_this2.callbackRegister[parsed['@meta']._id].call(_this2._config, parsed.message || null);
_this2.callbackRegister[parsed['@meta']._id].call(_this2._config, parsed.message);
delete _this2.callbackRegister[parsed['@meta']._id];
}
_this2.console(['[RCVD]', parsed.message], 'debug');
} else {
_this2.console(['[RCVD]', e.data], 'debug');
}
_this2.console(['[RCVD]', parsed], 'debug');
};

@@ -238,6 +251,15 @@ this.connections[connectionId].onclose = function (e) {

if (_this2.disconnect.indexOf(connectionId) === -1 && typeof _this2._config.client.keepAlive === 'number' && _this2._config.client.keepAlive > 0) {
if (++_this2.keepAliveAttempt > _this2.maxKeepAliveAttempt) {
return;
}
var timeout = _this2._config.client.keepAlive;
if (_this2.keepAliveAttempt > 5) {
timeout = timeout + timeout / 2;
} else if (_this2.keepAliveAttempt > 10) {
timeout = timeout * 2;
}
setTimeout(function () {
_this2.console('Attempting to reestablish WebSocket', 'info');
_this2.open();
}, _this2._config.client.keepAlive);
}, timeout);
}

@@ -250,2 +272,13 @@ delete _this2.connections[connectionId];

}
/**
* @param number int
*/
}, {
key: 'setMaxKeepAliveAttempt',
value: function setMaxKeepAliveAttempt(number) {
this.maxKeepAliveAttempt = typeof number === 'number' ? number : this.maxKeepAliveAttempt;
return this;
}
}], [{

@@ -280,3 +313,2 @@ key: 'generateUUID',

exports.default = StreamSock;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInNvY2tzdHJlYW0uanMiXSwibmFtZXMiOlsiU3RyZWFtU29jayIsImhvc3QiLCJwb3J0Iiwic2VjdXJlIiwia2VlcEFsaXZlIiwiZGVidWdMZXZlbCIsImNhbGxiYWNrUmVnaXN0ZXIiLCJwaW5nIiwic2VuZCIsImNvbnNvbGUiLCJtZXNzYWdlIiwic3lzdGVtIiwiZGlzY29ubmVjdCIsImNvbm5lY3Rpb25zIiwiX2NvbmZpZyIsImNsaWVudCIsIm5hbWUiLCJ2ZXJzaW9uIiwic2VydmVyIiwiaG9zdG5hbWUiLCJwcm90byIsIk9iamVjdCIsImFzc2lnbiIsInR5cGUiLCJsZXZlbE1hcCIsInNldHRpbmciLCJkZWJ1ZyIsImNvbm5lY3Rpb25JZCIsImlkIiwibGFzdENvbm5lY3Rpb25JZCIsInB1c2giLCJjbG9zZSIsImNiIiwicmVhZHlTdGF0ZSIsIk9QRU4iLCJfaWQiLCJnZW5lcmF0ZVVVSUQiLCJKU09OIiwic3RyaW5naWZ5IiwiV2ViU29ja2V0IiwiQ09OTkVDVElORyIsIm9ub3BlbiIsInNldFRpbWVvdXQiLCJvbmVycm9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nvbm5lY3Rpb25JZF0ub25jbG9zZSA9IGUgPT4ge1xuICAgICAgICB0aGlzLmNvbnNvbGUoWydXZWJTb2NrZXQgY2xvc2VkJywgZV0sICd3YXJuJylcbiAgICAgICAgaWYgKHRoaXMuZGlzY29ubmVjdC5pbmRleE9mKGNvbm5lY3Rpb25JZCkgPT09IC0xICYmIHR5cGVvZiB0aGlzLl9jb25maWcuY2xpZW50LmtlZXBBbGl2ZSA9PT0gJ251bWJlcicgJiYgdGhpcy5fY29uZmlnLmNsaWVudC5rZWVwQWxpdmUgPiAwKSB7XG4gICAgICAgICAgc2V0VGltZW91dCgoKSA9PiB7XG4gICAgICAgICAgICB0aGlzLmNvbnNvbGUoJ0F0dGVtcHRpbmcgdG8gcmVlc3RhYmxpc2ggV2ViU29ja2V0JywgJ2luZm8nKVxuICAgICAgICAgICAgdGhpcy5vcGVuKClcbiAgICAgICAgICB9LCB0aGlzLl9jb25maWcuY2xpZW50LmtlZXBBbGl2ZSlcbiAgICAgICAgfVxuICAgICAgICBkZWxldGUgdGhpcy5jb25uZWN0aW9uc1tjb25uZWN0aW9uSWRdXG4gICAgICB9XG4gICAgfVxuXG4gICAgcmV0dXJuIGNvbm5lY3Rpb25JZDtcbiAgfVxufVxuIl19
exports.default = StreamSock;

@@ -1,1 +0,1 @@

"use strict";function _classCallCheck(e,n){if(!(e instanceof n))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(exports,"__esModule",{value:!0});var _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},_createClass=function(){function e(e,n){for(var t=0;t<n.length;t++){var o=n[t];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}return function(n,t,o){return t&&e(n.prototype,t),o&&e(n,o),n}}(),StreamSock=function(){function e(){var n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"localhost",t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:8082,o=!(arguments.length>2&&void 0!==arguments[2])||arguments[2],i=this,s=arguments.length>3&&void 0!==arguments[3]?arguments[3]:800,c=arguments.length>4&&void 0!==arguments[4]?arguments[4]:0;_classCallCheck(this,e),this.callbackRegister={ping:function(e){i.send("pong"),i.console(["[PING]",e])},system:function(e){i.console(["[SYSTEM]",e])}},this.disconnect=[],this.connections={},this._config={client:{name:"sockstream.js",version:1.2,debugLevel:0,keepAlive:800},server:{name:"sockets/php-stream-socket-server",version:1.3,hostname:"localhost",port:8082,proto:"wss://"}},"object"===("undefined"==typeof n?"undefined":_typeof(n))?("object"===_typeof(n.client)&&(this._config.client=Object.assign({debugLevel:0,keepAlive:800},n.client,{name:"sockstream.js",version:.1})),"object"===_typeof(n.server)&&(this._config.server=Object.assign({hostname:"localhost",port:8082,proto:"wss://"},n.server,{name:"sockets/php-stream-socket-server",version:1.3}))):this._config={client:{name:"sockstream.js",version:.1,debugLevel:c,keepAlive:s},server:{name:"sockets/php-stream-socket-server",version:1.3,hostname:n,port:t,proto:o?"wss://":"ws://"}}}return _createClass(e,[{key:"console",value:function(e){function n(n){return e.apply(this,arguments)}return n.toString=function(){return e.toString()},n}(function(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"log",t={log:4,debug:3,info:2,warn:1,error:0};this._config.client.debugLevel>=(t[n]||0)&&console[n](e)})},{key:"debug",value:function(e){return"undefined"!=typeof e&&(this._config.client.debug=!!e),this._config.client.debug}},{key:"close",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,n=e||this.lastConnectionId;return"undefined"!=typeof this.connections[n]&&(this.disconnect.push(n),this.connections[n].close()),!0}},{key:"send",value:function(n,t){var o=this.lastConnectionId;if("function"!=typeof t&&"undefined"!=typeof this.connections[t]&&(this.lastConnectionId=o=t),"undefined"==typeof this.connections[o])return!1;if(this.connections[o].readyState===this.connections[o].OPEN){var i=e.generateUUID();return"function"==typeof t&&(this.callbackRegister[i]=t),this.connections[o].send(JSON.stringify({"@meta":Object.assign({_id:i},this._config),message:n})),!0}return this.console("WebSocket not open","warn"),!1}},{key:"open",value:function(n){var t=this;this.console(["[CONNECTING]",""+this._config.server.proto+this._config.server.hostname+":"+this._config.server.port],"info");var o=e.generateUUID();return this.lastConnectionId=o,this.connections[o]=new WebSocket(""+this._config.server.proto+this._config.server.hostname+":"+this._config.server.port),this.connections[o].readyState===this.connections[o].CONNECTING&&(this.connections[o].onopen=function(){t.console("connected","info"),setTimeout(function(){t.send("connecting",n)},20)},this.connections[o].onerror=function(e){t.console(["WebSocket error",e],"error")},this.connections[o].onmessage=function(n){var o=e.parseMessage(n.data);o&&"undefined"!=typeof o["@meta"]&&("function"==typeof t.callbackRegister[o["@meta"]._type]?t.callbackRegister[o["@meta"]._type].call(t._config,o["@meta"]._system):"function"==typeof t.callbackRegister[o["@meta"]._id]&&(t.callbackRegister[o["@meta"]._id].call(t._config,o.message||null),delete t.callbackRegister[o["@meta"]._id])),t.console(["[RCVD]",o],"debug")},this.connections[o].onclose=function(e){t.console(["WebSocket closed",e],"warn"),t.disconnect.indexOf(o)===-1&&"number"==typeof t._config.client.keepAlive&&t._config.client.keepAlive>0&&setTimeout(function(){t.console("Attempting to reestablish WebSocket","info"),t.open()},t._config.client.keepAlive),delete t.connections[o]}),o}}],[{key:"generateUUID",value:function(){var e=(new Date).getTime();return window.performance&&"function"==typeof window.performance.now&&(e+=performance.now()),"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(n){var t=(e+16*Math.random())%16|0;return e=Math.floor(e/16),("x"==n?t:3&t|8).toString(16)})}},{key:"parseMessage",value:function(e){return"undefined"==typeof e?null:"string"==typeof e?JSON.parse(e):e}}]),e}();exports.default=StreamSock;
"use strict";function _toConsumableArray(e){if(Array.isArray(e)){for(var t=0,n=Array(e.length);t<e.length;t++)n[t]=e[t];return n}return Array.from(e)}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(exports,"__esModule",{value:!0});var _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},_createClass=function(){function e(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}return function(t,n,o){return n&&e(t.prototype,n),o&&e(t,o),t}}(),StreamSock=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"localhost",n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:8082,o=!(arguments.length>2&&void 0!==arguments[2])||arguments[2],i=this,s=arguments.length>3&&void 0!==arguments[3]?arguments[3]:800,r=arguments.length>4&&void 0!==arguments[4]?arguments[4]:0;_classCallCheck(this,e);var c="sockstream.js",a="1.3.3",l=800,f=0,u=8082,p="wss://",g="127.0.0.1";this.callbackRegister={ping:function(e){i.send("pong"),i.console(["[PING]",e])},system:function(e){i.console(["[SYSTEM]",e])}},this.maxKeepAliveAttempt=20,this.keepAliveAttempt=0,this.disconnect=[],this.connections={},this._config={client:{name:c,version:a,debugLevel:f,keepAlive:l},server:{hostname:g,port:u,proto:p}},"object"===("undefined"==typeof t?"undefined":_typeof(t))?("object"===_typeof(t.client)&&(this._config.client=Object.assign({debugLevel:f,keepAlive:l},t.client,{name:c,version:a})),"object"===_typeof(t.server)&&(this._config.server=Object.assign({hostname:g,port:u,proto:p},t.server))):this._config={client:{name:c,version:a,debugLevel:r,keepAlive:s},server:{hostname:t,port:n,proto:o?"wss://":"ws://"}}}return _createClass(e,[{key:"console",value:function(e){function t(t){return e.apply(this,arguments)}return t.toString=function(){return e.toString()},t}(function(e){var t,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"log",o={log:4,debug:3,info:2,warn:1,error:0};this._config.client.debugLevel>=(o[n]||0)&&(t=console)[n].apply(t,_toConsumableArray(e))})},{key:"debug",value:function(e){return"undefined"!=typeof e&&(this._config.client.debug=!!e),this._config.client.debug}},{key:"close",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,t=e||this.lastConnectionId;return"undefined"!=typeof this.connections[t]&&(this.disconnect.push(t),this.connections[t].close()),!0}},{key:"send",value:function(t,n){var o=this.lastConnectionId;if("function"!=typeof n&&"undefined"!=typeof this.connections[n]&&(this.lastConnectionId=o=n),"undefined"==typeof this.connections[o])return!1;if(this.connections[o].readyState===this.connections[o].OPEN){var i=e.generateUUID();return"function"==typeof n&&(this.callbackRegister[i]=n),this.connections[o].send(JSON.stringify({"@meta":Object.assign({_id:i},this._config),message:t})),!0}return this.console("WebSocket not open","warn"),!1}},{key:"open",value:function(t){var n=this;this.console(["[CONNECTING]",""+this._config.server.proto+this._config.server.hostname+":"+this._config.server.port],"info");var o=e.generateUUID();this.lastConnectionId=o;try{this.connections[o]=new WebSocket(""+this._config.server.proto+this._config.server.hostname+":"+this._config.server.port)}catch(e){return}return this.connections[o].readyState===this.connections[o].CONNECTING&&(this.connections[o].onopen=function(){n.console("connected","info"),n.keepAliveAttempt=0,setTimeout(function(){n.send("connecting",t)},20)},this.connections[o].onerror=function(e){n.console(e,"error")},this.connections[o].onmessage=function(t){var o=e.parseMessage(t.data);o&&"undefined"!=typeof o["@meta"]?("function"==typeof n.callbackRegister[o["@meta"]._type]?n.callbackRegister[o["@meta"]._type].call(n._config,o["@meta"]._system):"function"==typeof n.callbackRegister[o["@meta"]._id]&&(n.callbackRegister[o["@meta"]._id].call(n._config,o.message),delete n.callbackRegister[o["@meta"]._id]),n.console(["[RCVD]",o.message],"debug")):n.console(["[RCVD]",t.data],"debug")},this.connections[o].onclose=function(e){if(n.console(["WebSocket closed",e],"warn"),n.disconnect.indexOf(o)===-1&&"number"==typeof n._config.client.keepAlive&&n._config.client.keepAlive>0){if(++n.keepAliveAttempt>n.maxKeepAliveAttempt)return;var t=n._config.client.keepAlive;n.keepAliveAttempt>5?t+=t/2:n.keepAliveAttempt>10&&(t=2*t),setTimeout(function(){n.console("Attempting to reestablish WebSocket","info"),n.open()},t)}delete n.connections[o]}),o}},{key:"setMaxKeepAliveAttempt",value:function(e){return this.maxKeepAliveAttempt="number"==typeof e?e:this.maxKeepAliveAttempt,this}}],[{key:"generateUUID",value:function(){var e=(new Date).getTime();return window.performance&&"function"==typeof window.performance.now&&(e+=performance.now()),"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(t){var n=(e+16*Math.random())%16|0;return e=Math.floor(e/16),("x"==t?n:3&n|8).toString(16)})}},{key:"parseMessage",value:function(e){return"undefined"==typeof e?null:"string"==typeof e?JSON.parse(e):e}}]),e}();exports.default=StreamSock;

@@ -42,3 +42,4 @@ 'use strict';

.pipe(babel({
presets: ['es2015', 'es2016', 'stage-0']
presets: ['es2015', 'es2016', 'stage-0'],
plugins: ['transform-es2015-destructuring']
}))

@@ -75,2 +76,2 @@ .pipe(gulp.dest('./build'))

.pipe(gulp.dest('./dist'))
});
});
{
"name": "sockstream",
"version": "1.3.2",
"version": "1.3.3",
"description": "Provides a standard WebSocket thin manager",

@@ -31,2 +31,3 @@ "main": "src/sockstream.js",

"babel-core": "^6.17.0",
"babel-plugin-transform-es2015-destructuring": "^6.16.0",
"babel-polyfill": "^6.16.0",

@@ -43,7 +44,7 @@ "babel-preset-es2015": "^6.16.0",

"gulp-if": "^2.0.1",
"gulp-minify": "latest",
"gulp-sourcemaps": "^2.1.1",
"gulp-uglify": "^2.0.0",
"run-sequence": "^1.2.2",
"gulp-minify": "latest"
"run-sequence": "^1.2.2"
}
}

@@ -11,5 +11,3 @@ export default class StreamSock {

let clientName = 'sockstream.js';
let clientVersion = '1.3.2';
let serverName = 'sockets/php-stream-socket-server';
let serverVersion = '1.3';
let clientVersion = '1.3.3';
let defaultKeepAlive = 800;

@@ -29,2 +27,4 @@ let defaultDebugLevel = 0;

}
this.maxKeepAliveAttempt = 20;
this.keepAliveAttempt = 0;
this.disconnect = [];

@@ -40,4 +40,2 @@ this.connections = {};

server: {
name: serverName,
version: serverVersion,
hostname: defaultHost,

@@ -63,6 +61,3 @@ port: defaultPort,

proto: defaultProto
}, host.server, {
name: serverName,
version: serverVersion
})
}, host.server)
}

@@ -78,4 +73,2 @@ } else {

server: {
name: serverName,
version: serverVersion,
hostname: host,

@@ -97,3 +90,3 @@ port: port,

}
this._config.client.debugLevel >= (levelMap[type]||0) && console[type](message)
this._config.client.debugLevel >= (levelMap[type]||0) && console[type](...message)
}

@@ -185,6 +178,9 @@

this.lastConnectionId = connectionId
this.connections[connectionId] = new WebSocket(`${this._config.server.proto}${this._config.server.hostname}:${this._config.server.port}`)
try {
this.connections[connectionId] = new WebSocket(`${this._config.server.proto}${this._config.server.hostname}:${this._config.server.port}`)
} catch(e){return}
if (this.connections[connectionId].readyState === this.connections[connectionId].CONNECTING) {
this.connections[connectionId].onopen = () => {
this.console('connected', 'info')
this.keepAliveAttempt = 0
setTimeout(() => {

@@ -195,3 +191,3 @@ this.send('connecting', cb)

this.connections[connectionId].onerror = e => {
this.console(['WebSocket error', e], 'error')
this.console(e, 'error')
}

@@ -204,7 +200,9 @@ this.connections[connectionId].onmessage = e => {

} else if (typeof this.callbackRegister[parsed['@meta']._id] === 'function') {
this.callbackRegister[parsed['@meta']._id].call(this._config, parsed.message || null)
this.callbackRegister[parsed['@meta']._id].call(this._config, parsed.message)
delete this.callbackRegister[parsed['@meta']._id]
}
this.console(['[RCVD]', parsed.message], 'debug')
} else {
this.console(['[RCVD]', e.data], 'debug')
}
this.console(['[RCVD]', parsed], 'debug')
}

@@ -214,6 +212,15 @@ this.connections[connectionId].onclose = e => {

if (this.disconnect.indexOf(connectionId) === -1 && typeof this._config.client.keepAlive === 'number' && this._config.client.keepAlive > 0) {
if (++this.keepAliveAttempt > this.maxKeepAliveAttempt) {
return;
}
let timeout = this._config.client.keepAlive;
if (this.keepAliveAttempt > 5) {
timeout = timeout + (timeout/2)
} else if (this.keepAliveAttempt > 10) {
timeout = timeout*2
}
setTimeout(() => {
this.console('Attempting to reestablish WebSocket', 'info')
this.open()
}, this._config.client.keepAlive)
}, timeout)
}

@@ -226,2 +233,10 @@ delete this.connections[connectionId]

}
/**
* @param number int
*/
setMaxKeepAliveAttempt(number) {
this.maxKeepAliveAttempt = typeof number === 'number' ? number : this.maxKeepAliveAttempt
return this
}
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc