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 12.0.0 to 13.0.0

lib/factory.js

2

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

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

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

var SCSocket = require('./lib/scsocket');
var SCSocketCreator = require('./lib/scsocketcreator');
var SCClientSocket = require('./lib/scclientsocket');
var factory = require('./lib/factory');
module.exports.SCSocketCreator = SCSocketCreator;
module.exports.SCSocket = SCSocket;
module.exports.factory = factory;
module.exports.SCClientSocket = SCClientSocket;

@@ -10,3 +10,3 @@ module.exports.Emitter = require('component-emitter');

module.exports.create = function (options) {
return SCSocketCreator.create(options);
return factory.create(options);
};

@@ -17,7 +17,7 @@

module.exports.destroy = function (socket) {
return SCSocketCreator.destroy(socket);
return factory.destroy(socket);
};
module.exports.clients = SCSocketCreator.clients;
module.exports.clients = factory.clients;
module.exports.version = '12.0.0';
module.exports.version = '13.0.0';
{
"name": "socketcluster-client",
"description": "SocketCluster JavaScript client",
"version": "12.0.0",
"version": "13.0.0",
"homepage": "http://socketcluster.io",

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

@@ -102,4 +102,2 @@ SocketCluster JavaScript Client

See https://socketcluster.io/#!/docs/api-scsocket-client for details
```js

@@ -106,0 +104,0 @@ socket.on('subscribe', function(channelname) {

@@ -86,14 +86,16 @@ var assert = require('assert');

global.localStorage.removeItem('socketCluster.authToken');
if (client && client.state != client.CLOSED) {
cleanupTasks.push(new Promise(function (resolve, reject) {
client.once('disconnect', function () {
resolve();
});
client.once('connectAbort', function () {
resolve();
});
}));
client.destroy();
} else {
client.destroy();
if (client) {
if (client.state != client.CLOSED) {
cleanupTasks.push(new Promise(function (resolve, reject) {
client.once('disconnect', function () {
resolve();
});
client.once('connectAbort', function () {
resolve();
});
}));
client.destroy();
} else {
client.destroy();
}
}

@@ -109,2 +111,141 @@ cleanupTasks.push(new Promise(function (resolve) {

describe('Creation', function () {
it('Should reuse socket if multiplex is true and options are the same', function (done) {
clientOptions = {
hostname: '127.0.0.1',
port: portNumber,
multiplex: true
};
var clientA = socketClusterClient.create(clientOptions);
var clientB = socketClusterClient.create(clientOptions);
assert.equal(clientA, clientB);
clientA.destroy();
clientB.destroy();
done();
});
it('Should automatically connect socket on creation by default', function (done) {
clientOptions = {
hostname: '127.0.0.1',
port: portNumber,
multiplex: false
};
client = socketClusterClient.create(clientOptions);
assert.equal(client.state, client.CONNECTING);
done();
});
it('Should not automatically connect socket if autoConnect is set to false', function (done) {
clientOptions = {
hostname: '127.0.0.1',
port: portNumber,
multiplex: false,
autoConnect: false
};
client = socketClusterClient.create(clientOptions);
assert.equal(client.state, client.CLOSED);
done();
});
it('Should automatically connect socket if multiplex is true, autoConnect is set to false the first time and socket create is called with autoConnect true the second time', function (done) {
var clientOptionsA = {
hostname: '127.0.0.1',
port: portNumber,
multiplex: true,
autoConnect: false
};
var clientA = socketClusterClient.create(clientOptionsA);
assert.equal(clientA.state, clientA.CLOSED);
var clientOptionsB = {
hostname: '127.0.0.1',
port: portNumber,
multiplex: true,
autoConnect: true
};
var clientB = socketClusterClient.create(clientOptionsB);
assert.equal(clientB.state, clientB.CONNECTING);
clientA.destroy();
clientB.destroy();
done();
});
it('Should not automatically connect socket if multiplex is true, autoConnect is set to false and socket create is called a second time with autoConnect false', function (done) {
clientOptions = {
hostname: '127.0.0.1',
port: portNumber,
multiplex: true,
autoConnect: false
};
var clientA = socketClusterClient.create(clientOptions);
assert.equal(clientA.state, clientA.CLOSED);
var clientB = socketClusterClient.create(clientOptions);
assert.equal(clientB.state, clientB.CLOSED);
clientA.destroy();
clientB.destroy();
done();
});
});
describe('Errors', function () {
it('Should not be able to emit reserved events on the socket', function (done) {
client = socketClusterClient.create(clientOptions);
var error = null;
client.on('error', function (err) {
error = err;
});
client.on('connect', function () {
client.emit('message', 123);
});
setTimeout(function () {
assert.notEqual(error, null);
assert.equal(error.name, 'InvalidActionError');
done();
}, 100);
});
it('Should be able to emit the error event locally on the socket', function (done) {
client = socketClusterClient.create(clientOptions);
var error = null;
client.on('error', function (err) {
error = err;
});
client.on('connect', function () {
var error = new Error('Custom error');
error.name = 'CustomError';
client.emit('error', error);
});
setTimeout(function () {
assert.notEqual(error, null);
assert.equal(error.name, 'CustomError');
done();
}, 100);
});
});
describe('Authentication', function () {

@@ -111,0 +252,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