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

socketcluster-client

Package Overview
Dependencies
Maintainers
1
Versions
236
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

socketcluster-client - npm Package Compare versions

Comparing version 11.0.0 to 11.0.1

2

bower.json
{
"name": "socketcluster-client",
"main": "socketcluster.js",
"version": "11.0.0",
"version": "11.0.1",
"homepage": "https://github.com/SocketCluster/socketcluster-client",

@@ -6,0 +6,0 @@ "description": "SocketCluster JavaScript client",

@@ -15,4 +15,4 @@ var SCSocket = require('./lib/scsocket');

module.exports.destroy = function (options) {
return SCSocketCreator.destroy(options);
module.exports.destroy = function (socket) {
return SCSocketCreator.destroy(socket);
};

@@ -22,2 +22,2 @@

module.exports.version = '11.0.0';
module.exports.version = '11.0.1';

@@ -298,4 +298,4 @@ var Emitter = require('component-emitter');

SCSocket.prototype.reconnect = function () {
this.disconnect();
SCSocket.prototype.reconnect = function (code, data) {
this.disconnect(code, data);
this.connect();

@@ -320,7 +320,7 @@ };

SCSocket.prototype.destroy = function () {
SCSocket.prototype.destroy = function (code, data) {
if (this._unloadHandler) {
global.removeEventListener('beforeunload', this._unloadHandler, false);
}
this.disconnect();
this.disconnect(code, data);
delete this._clientMap[this.clientId];

@@ -327,0 +327,0 @@ };

{
"name": "socketcluster-client",
"description": "SocketCluster JavaScript client",
"version": "11.0.0",
"version": "11.0.1",
"homepage": "http://socketcluster.io",

@@ -6,0 +6,0 @@ "contributors": [

@@ -642,4 +642,43 @@ var assert = require('assert');

describe('reconnecting socket', function () {
it('should disconnect socket with code 1000 and reconnect', function (done) {
client = socketClusterClient.create(clientOptions);
client.once('connect', function () {
var disconnectCode;
var disconnectReason;
client.once('disconnect', function (code, reason) {
disconnectCode = code;
disconnectReason = reason;
});
client.once('connect', function () {
assert.equal(disconnectCode, 1000);
assert.equal(disconnectReason, undefined);
done();
});
client.reconnect();
});
});
it('should disconnect socket with custom code and data when socket.reconnect() is called with arguments', function (done) {
client = socketClusterClient.create(clientOptions);
client.once('connect', function () {
var disconnectCode;
var disconnectReason;
client.once('disconnect', function (code, reason) {
disconnectCode = code;
disconnectReason = reason;
});
client.once('connect', function () {
assert.equal(disconnectCode, 1000);
assert.equal(disconnectReason, 'About to reconnect');
done();
});
client.reconnect(1000, 'About to reconnect');
});
});
});
describe('destroying socket', function () {
it('should disconnect socket when socket.destroy() is called', function (done) {

@@ -662,2 +701,21 @@ client = socketClusterClient.create(clientOptions);

it('should disconnect socket with custom code and data when socket.destroy() is called with arguments', function (done) {
client = socketClusterClient.create(clientOptions);
var clientError;
client.on('error', function (err) {
clientError = err;
});
client.on('connect', function () {
client.destroy(4321, 'Custom disconnect reason');
});
client.on('disconnect', function (code, reason) {
assert.equal(code, 4321);
assert.equal(reason, 'Custom disconnect reason');
done();
});
});
it('should destroy all references of socket when socket.destroy() is called before connect', function (done) {

@@ -671,2 +729,18 @@ client = socketClusterClient.create(clientOptions);

var connectAbortTriggered = false;
var disconnectTriggered = false;
var closeTriggered = false;
client.on('connectAbort', function (n) {
connectAbortTriggered = true;
});
client.on('disconnect', function (n) {
disconnectTriggered = true;
});
client.on('close', function (n) {
closeTriggered = true;
});
assert.equal(Object.keys(socketClusterClient.clients).length, 1);

@@ -679,2 +753,5 @@ assert.equal(socketClusterClient.clients[client.clientId] === client, true);

assert.equal(socketClusterClient.clients[client.clientId], null);
assert.equal(connectAbortTriggered, true);
assert.equal(disconnectTriggered, false);
assert.equal(closeTriggered, true);
done();

@@ -691,2 +768,18 @@ });

var connectAbortTriggered = false;
var disconnectTriggered = false;
var closeTriggered = false;
client.on('connectAbort', function (n) {
connectAbortTriggered = true;
});
client.on('disconnect', function (n) {
disconnectTriggered = true;
});
client.on('close', function (n) {
closeTriggered = true;
});
assert.equal(Object.keys(socketClusterClient.clients).length, 1);

@@ -699,2 +792,5 @@ assert.equal(socketClusterClient.clients[client.clientId] === client, true);

assert.equal(socketClusterClient.clients[client.clientId], null);
assert.equal(connectAbortTriggered, false);
assert.equal(disconnectTriggered, true);
assert.equal(closeTriggered, true);
done();

@@ -706,4 +802,4 @@ });

clientOptions.multiplex = true;
clientA = socketClusterClient.create(clientOptions);
clientB = socketClusterClient.create(clientOptions);
var clientA = socketClusterClient.create(clientOptions);
var clientB = socketClusterClient.create(clientOptions);

@@ -749,2 +845,58 @@ var clientAError;

});
it('should destroy all references of socket when socketClusterClient.destroy(socket) is called if the socket was created with query parameters', function () {
var clientOptionsB = {
hostname: '127.0.0.1',
port: PORT,
multiplex: true,
ackTimeout: 200,
query: {foo: 123, bar: 456}
};
var clientA = socketClusterClient.create(clientOptionsB);
var clientOptionsB = {
hostname: '127.0.0.1',
port: PORT,
multiplex: true,
ackTimeout: 200,
query: {foo: 123, bar: 789}
};
var clientB = socketClusterClient.create(clientOptionsB);
var clientOptionsB2 = {
hostname: '127.0.0.1',
port: PORT,
multiplex: true,
ackTimeout: 200,
query: {foo: 123, bar: 789}
};
var clientB2 = socketClusterClient.create(clientOptionsB2);
return Promise.all([
new Promise(function (resolve) {
clientA.on('connect', function () {
resolve();
});
}),
new Promise(function (resolve) {
clientB.on('connect', function () {
resolve();
});
}),
new Promise(function (resolve) {
clientB2.on('connect', function () {
resolve();
});
})
]).then(function () {
assert.equal(Object.keys(socketClusterClient.clients).length, 2);
clientA.destroy();
assert.equal(Object.keys(socketClusterClient.clients).length, 1);
clientB.destroy();
assert.equal(Object.keys(socketClusterClient.clients).length, 0);
});
});
});

@@ -751,0 +903,0 @@

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

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