Skip to content

Commit

Permalink
v6.4.0 - Removed sc-emitter and replaced with component-emitter
Browse files Browse the repository at this point in the history
  • Loading branch information
jondubois committed Aug 8, 2017
1 parent 816d8ac commit 731fc0c
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 162 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "socketcluster-client",
"main": "socketcluster.js",
"version": "6.3.0",
"version": "6.4.0",
"homepage": "https://github.com/SocketCluster/socketcluster-client",
"description": "SocketCluster JavaScript client",
"authors": [
Expand Down
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var SCSocketCreator = require('./lib/scsocketcreator');
module.exports.SCSocketCreator = SCSocketCreator;
module.exports.SCSocket = SCSocket;

module.exports.SCEmitter = require('sc-emitter').SCEmitter;
module.exports.Emitter = require('component-emitter');

module.exports.connect = function (options) {
return SCSocketCreator.connect(options);
Expand All @@ -16,4 +16,4 @@ module.exports.destroy = function (options) {

module.exports.connections = SCSocketCreator.connections;

module.exports.version = '6.3.0';
module.exports.version = '6.4.0';
54 changes: 27 additions & 27 deletions lib/scsocket.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var SCEmitter = require('sc-emitter').SCEmitter;
var Emitter = require('component-emitter');
var SCChannel = require('sc-channel').SCChannel;
var Response = require('./response').Response;
var AuthEngine = require('./auth').AuthEngine;
Expand All @@ -22,7 +22,7 @@ var isBrowser = typeof window != 'undefined';
var SCSocket = function (opts) {
var self = this;

SCEmitter.call(this);
Emitter.call(this);

this.id = null;
this.state = this.CLOSED;
Expand Down Expand Up @@ -137,7 +137,7 @@ var SCSocket = function (opts) {
this.connect();
}

this._channelEmitter = new SCEmitter();
this._channelEmitter = new Emitter();

if (isBrowser && this.disconnectOnUnload) {
var unloadHandler = function () {
Expand All @@ -152,7 +152,7 @@ var SCSocket = function (opts) {
}
};

SCSocket.prototype = Object.create(SCEmitter.prototype);
SCSocket.prototype = Object.create(Emitter.prototype);

SCSocket.CONNECTING = SCSocket.prototype.CONNECTING = SCTransport.prototype.CONNECTING;
SCSocket.OPEN = SCSocket.prototype.OPEN = SCTransport.prototype.OPEN;
Expand All @@ -178,7 +178,7 @@ SCSocket.prototype._privateEventHandlerMap = {
var undecoratedChannelName = this._undecorateChannelName(data.channel);
var channel = this.channels[undecoratedChannelName];
if (channel) {
SCEmitter.prototype.emit.call(this, 'kickOut', data.message, undecoratedChannelName);
Emitter.prototype.emit.call(this, 'kickOut', data.message, undecoratedChannelName);
channel.emit('kickOut', data.message, undecoratedChannelName);
this._triggerChannelUnsubscribe(channel);
}
Expand Down Expand Up @@ -214,7 +214,7 @@ SCSocket.prototype._privateEventHandlerMap = {
response.error(err);
self._onSCError(err);
} else {
SCEmitter.prototype.emit.call(self, 'removeAuthToken', oldToken);
Emitter.prototype.emit.call(self, 'removeAuthToken', oldToken);
self._changeToUnauthenticatedState();
response.end();
}
Expand Down Expand Up @@ -242,7 +242,7 @@ SCSocket.prototype.deauthenticate = function (callback) {
self._onSCError(err);
} else {
self.emit('#removeAuthToken');
SCEmitter.prototype.emit.call(self, 'removeAuthToken', oldToken);
Emitter.prototype.emit.call(self, 'removeAuthToken', oldToken);
self._changeToUnauthenticatedState();
}
callback && callback(err);
Expand All @@ -258,7 +258,7 @@ SCSocket.prototype.connect = SCSocket.prototype.open = function () {
clearTimeout(this._reconnectTimeoutRef);

this.state = this.CONNECTING;
SCEmitter.prototype.emit.call(this, 'connecting');
Emitter.prototype.emit.call(this, 'connecting');

this._changeToPendingAuthState();

Expand Down Expand Up @@ -322,7 +322,7 @@ SCSocket.prototype._changeToPendingAuthState = function () {
oldState: oldState,
newState: this.authState
};
SCEmitter.prototype.emit.call(this, 'authStateChange', stateChangeData);
Emitter.prototype.emit.call(this, 'authStateChange', stateChangeData);
}
};

Expand All @@ -337,11 +337,11 @@ SCSocket.prototype._changeToUnauthenticatedState = function () {
oldState: oldState,
newState: this.authState
};
SCEmitter.prototype.emit.call(this, 'authStateChange', stateChangeData);
Emitter.prototype.emit.call(this, 'authStateChange', stateChangeData);
if (oldState == this.AUTHENTICATED) {
SCEmitter.prototype.emit.call(this, 'deauthenticate');
Emitter.prototype.emit.call(this, 'deauthenticate');
}
SCEmitter.prototype.emit.call(this, 'authTokenChange', this.signedAuthToken);
Emitter.prototype.emit.call(this, 'authTokenChange', this.signedAuthToken);
}
};

Expand All @@ -362,10 +362,10 @@ SCSocket.prototype._changeToAuthenticatedState = function (signedAuthToken) {
this.processPendingSubscriptions();
}

SCEmitter.prototype.emit.call(this, 'authStateChange', stateChangeData);
SCEmitter.prototype.emit.call(this, 'authenticate', signedAuthToken);
Emitter.prototype.emit.call(this, 'authStateChange', stateChangeData);
Emitter.prototype.emit.call(this, 'authenticate', signedAuthToken);
}
SCEmitter.prototype.emit.call(this, 'authTokenChange', signedAuthToken);
Emitter.prototype.emit.call(this, 'authTokenChange', signedAuthToken);
};

SCSocket.prototype.decodeBase64 = function (encodedString) {
Expand Down Expand Up @@ -506,7 +506,7 @@ SCSocket.prototype._onSCOpen = function (status) {

// If the user invokes the callback while in autoSubscribeOnConnect mode, it
// won't break anything.
SCEmitter.prototype.emit.call(this, 'connect', status, function () {
Emitter.prototype.emit.call(this, 'connect', status, function () {
self.processPendingSubscriptions();
});

Expand All @@ -522,7 +522,7 @@ SCSocket.prototype._onSCError = function (err) {
if (self.listeners('error').length < 1) {
throw err;
} else {
SCEmitter.prototype.emit.call(self, 'error', err);
Emitter.prototype.emit.call(self, 'error', err);
}
}, 0);
};
Expand Down Expand Up @@ -605,9 +605,9 @@ SCSocket.prototype._onSCClose = function (code, data, openAbort) {
}

if (openAbort) {
SCEmitter.prototype.emit.call(self, 'connectAbort', code, data);
Emitter.prototype.emit.call(self, 'connectAbort', code, data);
} else {
SCEmitter.prototype.emit.call(self, 'disconnect', code, data);
Emitter.prototype.emit.call(self, 'disconnect', code, data);
}

if (!SCSocket.ignoreStatuses[code]) {
Expand All @@ -629,7 +629,7 @@ SCSocket.prototype._onSCEvent = function (event, data, res) {
if (handler) {
handler.call(this, data, res);
} else {
SCEmitter.prototype.emit.call(this, event, data, function () {
Emitter.prototype.emit.call(this, event, data, function () {
res && res.callback.apply(res, arguments);
});
}
Expand Down Expand Up @@ -709,7 +709,7 @@ SCSocket.prototype.emit = function (event, data, callback) {
if (this._localEvents[event] == null) {
this._emit(event, data, callback);
} else {
SCEmitter.prototype.emit.call(this, event, data);
Emitter.prototype.emit.call(this, event, data);
}
};

Expand All @@ -736,8 +736,8 @@ SCSocket.prototype._triggerChannelSubscribe = function (channel, subscriptionOpt
};
channel.emit('subscribeStateChange', stateChangeData);
channel.emit('subscribe', channelName, subscriptionOptions);
SCEmitter.prototype.emit.call(this, 'subscribeStateChange', stateChangeData);
SCEmitter.prototype.emit.call(this, 'subscribe', channelName, subscriptionOptions);
Emitter.prototype.emit.call(this, 'subscribeStateChange', stateChangeData);
Emitter.prototype.emit.call(this, 'subscribe', channelName, subscriptionOptions);
}
};

Expand All @@ -749,7 +749,7 @@ SCSocket.prototype._triggerChannelSubscribeFail = function (err, channel, subscr
channel.state = channel.UNSUBSCRIBED;

channel.emit('subscribeFail', err, channelName, subscriptionOptions);
SCEmitter.prototype.emit.call(this, 'subscribeFail', err, channelName, subscriptionOptions);
Emitter.prototype.emit.call(this, 'subscribeFail', err, channelName, subscriptionOptions);
}
};

Expand Down Expand Up @@ -810,7 +810,7 @@ SCSocket.prototype._trySubscribe = function (channel) {
}
}
);
SCEmitter.prototype.emit.call(this, 'subscribeRequest', channel.name, subscriptionOptions);
Emitter.prototype.emit.call(this, 'subscribeRequest', channel.name, subscriptionOptions);
}
};

Expand Down Expand Up @@ -851,8 +851,8 @@ SCSocket.prototype._triggerChannelUnsubscribe = function (channel, newState) {
};
channel.emit('subscribeStateChange', stateChangeData);
channel.emit('unsubscribe', channelName);
SCEmitter.prototype.emit.call(this, 'subscribeStateChange', stateChangeData);
SCEmitter.prototype.emit.call(this, 'unsubscribe', channelName);
Emitter.prototype.emit.call(this, 'subscribeStateChange', stateChangeData);
Emitter.prototype.emit.call(this, 'unsubscribe', channelName);
}
};

Expand Down
18 changes: 9 additions & 9 deletions lib/sctransport.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var SCEmitter = require('sc-emitter').SCEmitter;
var Emitter = require('component-emitter');
var Response = require('./response').Response;
var querystring = require('querystring');
var WebSocket;
Expand Down Expand Up @@ -36,7 +36,7 @@ var SCTransport = function (authEngine, codecEngine, options) {
this.open();
};

SCTransport.prototype = Object.create(SCEmitter.prototype);
SCTransport.prototype = Object.create(Emitter.prototype);

SCTransport.CONNECTING = SCTransport.prototype.CONNECTING = 'connecting';
SCTransport.OPEN = SCTransport.prototype.OPEN = 'open';
Expand Down Expand Up @@ -135,7 +135,7 @@ SCTransport.prototype._onOpen = function () {
self.socket.close(4003);
} else {
self.state = self.OPEN;
SCEmitter.prototype.emit.call(self, 'open', status);
Emitter.prototype.emit.call(self, 'open', status);
self._resetPingTimeout();
}
});
Expand Down Expand Up @@ -199,18 +199,18 @@ SCTransport.prototype._onClose = function (code, data) {

if (this.state == this.OPEN) {
this.state = this.CLOSED;
SCEmitter.prototype.emit.call(this, 'close', code, data);
Emitter.prototype.emit.call(this, 'close', code, data);
this._abortAllPendingEventsDueToBadConnection('disconnect');

} else if (this.state == this.CONNECTING) {
this.state = this.CLOSED;
SCEmitter.prototype.emit.call(this, 'openAbort', code, data);
Emitter.prototype.emit.call(this, 'openAbort', code, data);
this._abortAllPendingEventsDueToBadConnection('connectAbort');
}
};

SCTransport.prototype._onMessage = function (message) {
SCEmitter.prototype.emit.call(this, 'event', 'message', message);
Emitter.prototype.emit.call(this, 'event', 'message', message);

var obj = this.decode(message);

Expand All @@ -225,7 +225,7 @@ SCTransport.prototype._onMessage = function (message) {

if (event) {
var response = new Response(this, obj.cid);
SCEmitter.prototype.emit.call(this, 'event', event, obj.data, response);
Emitter.prototype.emit.call(this, 'event', event, obj.data, response);
} else if (obj.rid != null) {

var eventObject = this._callbackMap[obj.rid];
Expand All @@ -240,13 +240,13 @@ SCTransport.prototype._onMessage = function (message) {
}
}
} else {
SCEmitter.prototype.emit.call(this, 'event', 'raw', obj);
Emitter.prototype.emit.call(this, 'event', 'raw', obj);
}
}
};

SCTransport.prototype._onError = function (err) {
SCEmitter.prototype.emit.call(this, 'error', err);
Emitter.prototype.emit.call(this, 'error', err);
};

SCTransport.prototype._resetPingTimeout = function () {
Expand Down
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "socketcluster-client",
"description": "SocketCluster JavaScript client",
"version": "6.3.0",
"version": "6.4.0",
"homepage": "http://socketcluster.io",
"contributors": [
{
Expand All @@ -18,14 +18,14 @@
},
"dependencies": {
"base-64": "0.1.0",
"linked-list": "0.1.0",
"clone": "2.1.1",
"component-emitter": "1.2.1",
"linked-list": "0.1.0",
"querystring": "0.2.0",
"sc-channel": "~1.0.6",
"sc-emitter": "~1.1.0",
"sc-channel": "~1.1.0",
"sc-errors": "~1.3.3",
"sc-formatter": "~3.0.0",
"ws": "3.0.0"
"ws": "3.1.0"
},
"browser": {
"ws": "./lib/ws-browser.js"
Expand All @@ -34,6 +34,6 @@
"license": "MIT",
"devDependencies": {
"browserify": "^13.3.0",
"uglify-js": "^2.7.5"
"uglify-js": "^2.8.29"
}
}
Loading

0 comments on commit 731fc0c

Please sign in to comment.