55
66var client = require ( 'redis' ) . createClient ;
77var parser = require ( 'socket.io-parser' ) ;
8- var hasBin = require ( 'has-binary' ) ;
9- var msgpack = require ( 'msgpack-lite' ) ;
8+ var msgpack = require ( 'notepack.io' ) ;
109var debug = require ( 'debug' ) ( 'socket.io-emitter' ) ;
1110
1211/**
@@ -117,13 +116,10 @@ Emitter.prototype.of = function(nsp) {
117116 */
118117
119118Emitter . 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 }
0 commit comments