Skip to content

Commit 119b3e6

Browse files
v4l3r10darrachequesne
authored andcommitted
[feat] Make the module compatible with socket.io-redis 5.x (#55)
- removed old namespace tag - updated dependencies - removed hasBinary package. - fixed socketIo multiroom event.
1 parent 8a1f38b commit 119b3e6

File tree

3 files changed

+9
-19
lines changed

3 files changed

+9
-19
lines changed

.travis.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
sudo: false
22
language: node_js
33
node_js:
4-
- "0.10"
5-
- "0.12"
64
- "4"
75
- "6"
86
- "7"

index.js

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55

66
var client = require('redis').createClient;
77
var parser = require('socket.io-parser');
8-
var hasBin = require('has-binary');
9-
var msgpack = require('msgpack-lite');
8+
var msgpack = require('notepack.io');
109
var debug = require('debug')('socket.io-emitter');
1110

1211
/**
@@ -117,13 +116,10 @@ Emitter.prototype.of = function(nsp) {
117116
*/
118117

119118
Emitter.prototype.emit = function(){
120-
var self = this;
121-
122119
// packet
123120
var args = Array.prototype.slice.call(arguments);
124-
var packet = {};
125-
packet.type = hasBin(args) ? parser.BINARY_EVENT : parser.EVENT;
126-
packet.data = args;
121+
var packet = { type: parser.EVENT, data: args };
122+
127123
// set namespace to packet
128124
if (this._flags.nsp) {
129125
packet.nsp = this._flags.nsp;
@@ -140,11 +136,8 @@ Emitter.prototype.emit = function(){
140136
var msg = msgpack.encode([uid, packet, opts]);
141137

142138
// publish
143-
if (opts.rooms && opts.rooms.length) {
144-
opts.rooms.forEach(function(room) {
145-
var chnRoom = chn + room + '#';
146-
self.redis.publish(chnRoom, msg);
147-
});
139+
if (opts.rooms && opts.rooms.length === 1) {
140+
this.redis.publish(chn + opts.rooms[0], msg);
148141
} else {
149142
this.redis.publish(chn, msg);
150143
}

package.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,14 @@
1313
"dependencies": {
1414
"debug": "2.3.3",
1515
"redis": "2.6.3",
16-
"msgpack-lite": "0.1.26",
17-
"has-binary": "0.1.7",
16+
"notepack.io": "~1.0.1",
1817
"socket.io-parser": "2.3.2"
1918
},
2019
"devDependencies": {
2120
"mocha": "~3.2.0",
2221
"expect.js": "~0.3.1",
23-
"socket.io": "~1.7.2",
24-
"socket.io-client": "~1.7.2",
25-
"socket.io-redis": "~3.0.0"
22+
"socket.io": "~2.0.1",
23+
"socket.io-client": "~2.0.1",
24+
"socket.io-redis": "~5.0.0"
2625
}
2726
}

0 commit comments

Comments
 (0)