1
- var SCEmitter = require ( 'sc -emitter' ) . SCEmitter ;
1
+ var Emitter = require ( 'component -emitter' ) ;
2
2
var SCChannel = require ( 'sc-channel' ) . SCChannel ;
3
3
var Response = require ( './response' ) . Response ;
4
4
var AuthEngine = require ( './auth' ) . AuthEngine ;
@@ -22,7 +22,7 @@ var isBrowser = typeof window != 'undefined';
22
22
var SCSocket = function ( opts ) {
23
23
var self = this ;
24
24
25
- SCEmitter . call ( this ) ;
25
+ Emitter . call ( this ) ;
26
26
27
27
this . id = null ;
28
28
this . state = this . CLOSED ;
@@ -137,7 +137,7 @@ var SCSocket = function (opts) {
137
137
this . connect ( ) ;
138
138
}
139
139
140
- this . _channelEmitter = new SCEmitter ( ) ;
140
+ this . _channelEmitter = new Emitter ( ) ;
141
141
142
142
if ( isBrowser && this . disconnectOnUnload ) {
143
143
var unloadHandler = function ( ) {
@@ -152,7 +152,7 @@ var SCSocket = function (opts) {
152
152
}
153
153
} ;
154
154
155
- SCSocket . prototype = Object . create ( SCEmitter . prototype ) ;
155
+ SCSocket . prototype = Object . create ( Emitter . prototype ) ;
156
156
157
157
SCSocket . CONNECTING = SCSocket . prototype . CONNECTING = SCTransport . prototype . CONNECTING ;
158
158
SCSocket . OPEN = SCSocket . prototype . OPEN = SCTransport . prototype . OPEN ;
@@ -178,7 +178,7 @@ SCSocket.prototype._privateEventHandlerMap = {
178
178
var undecoratedChannelName = this . _undecorateChannelName ( data . channel ) ;
179
179
var channel = this . channels [ undecoratedChannelName ] ;
180
180
if ( channel ) {
181
- SCEmitter . prototype . emit . call ( this , 'kickOut' , data . message , undecoratedChannelName ) ;
181
+ Emitter . prototype . emit . call ( this , 'kickOut' , data . message , undecoratedChannelName ) ;
182
182
channel . emit ( 'kickOut' , data . message , undecoratedChannelName ) ;
183
183
this . _triggerChannelUnsubscribe ( channel ) ;
184
184
}
@@ -214,7 +214,7 @@ SCSocket.prototype._privateEventHandlerMap = {
214
214
response . error ( err ) ;
215
215
self . _onSCError ( err ) ;
216
216
} else {
217
- SCEmitter . prototype . emit . call ( self , 'removeAuthToken' , oldToken ) ;
217
+ Emitter . prototype . emit . call ( self , 'removeAuthToken' , oldToken ) ;
218
218
self . _changeToUnauthenticatedState ( ) ;
219
219
response . end ( ) ;
220
220
}
@@ -242,7 +242,7 @@ SCSocket.prototype.deauthenticate = function (callback) {
242
242
self . _onSCError ( err ) ;
243
243
} else {
244
244
self . emit ( '#removeAuthToken' ) ;
245
- SCEmitter . prototype . emit . call ( self , 'removeAuthToken' , oldToken ) ;
245
+ Emitter . prototype . emit . call ( self , 'removeAuthToken' , oldToken ) ;
246
246
self . _changeToUnauthenticatedState ( ) ;
247
247
}
248
248
callback && callback ( err ) ;
@@ -258,7 +258,7 @@ SCSocket.prototype.connect = SCSocket.prototype.open = function () {
258
258
clearTimeout ( this . _reconnectTimeoutRef ) ;
259
259
260
260
this . state = this . CONNECTING ;
261
- SCEmitter . prototype . emit . call ( this , 'connecting' ) ;
261
+ Emitter . prototype . emit . call ( this , 'connecting' ) ;
262
262
263
263
this . _changeToPendingAuthState ( ) ;
264
264
@@ -322,7 +322,7 @@ SCSocket.prototype._changeToPendingAuthState = function () {
322
322
oldState : oldState ,
323
323
newState : this . authState
324
324
} ;
325
- SCEmitter . prototype . emit . call ( this , 'authStateChange' , stateChangeData ) ;
325
+ Emitter . prototype . emit . call ( this , 'authStateChange' , stateChangeData ) ;
326
326
}
327
327
} ;
328
328
@@ -337,11 +337,11 @@ SCSocket.prototype._changeToUnauthenticatedState = function () {
337
337
oldState : oldState ,
338
338
newState : this . authState
339
339
} ;
340
- SCEmitter . prototype . emit . call ( this , 'authStateChange' , stateChangeData ) ;
340
+ Emitter . prototype . emit . call ( this , 'authStateChange' , stateChangeData ) ;
341
341
if ( oldState == this . AUTHENTICATED ) {
342
- SCEmitter . prototype . emit . call ( this , 'deauthenticate' ) ;
342
+ Emitter . prototype . emit . call ( this , 'deauthenticate' ) ;
343
343
}
344
- SCEmitter . prototype . emit . call ( this , 'authTokenChange' , this . signedAuthToken ) ;
344
+ Emitter . prototype . emit . call ( this , 'authTokenChange' , this . signedAuthToken ) ;
345
345
}
346
346
} ;
347
347
@@ -362,10 +362,10 @@ SCSocket.prototype._changeToAuthenticatedState = function (signedAuthToken) {
362
362
this . processPendingSubscriptions ( ) ;
363
363
}
364
364
365
- SCEmitter . prototype . emit . call ( this , 'authStateChange' , stateChangeData ) ;
366
- SCEmitter . prototype . emit . call ( this , 'authenticate' , signedAuthToken ) ;
365
+ Emitter . prototype . emit . call ( this , 'authStateChange' , stateChangeData ) ;
366
+ Emitter . prototype . emit . call ( this , 'authenticate' , signedAuthToken ) ;
367
367
}
368
- SCEmitter . prototype . emit . call ( this , 'authTokenChange' , signedAuthToken ) ;
368
+ Emitter . prototype . emit . call ( this , 'authTokenChange' , signedAuthToken ) ;
369
369
} ;
370
370
371
371
SCSocket . prototype . decodeBase64 = function ( encodedString ) {
@@ -506,7 +506,7 @@ SCSocket.prototype._onSCOpen = function (status) {
506
506
507
507
// If the user invokes the callback while in autoSubscribeOnConnect mode, it
508
508
// won't break anything.
509
- SCEmitter . prototype . emit . call ( this , 'connect' , status , function ( ) {
509
+ Emitter . prototype . emit . call ( this , 'connect' , status , function ( ) {
510
510
self . processPendingSubscriptions ( ) ;
511
511
} ) ;
512
512
@@ -522,7 +522,7 @@ SCSocket.prototype._onSCError = function (err) {
522
522
if ( self . listeners ( 'error' ) . length < 1 ) {
523
523
throw err ;
524
524
} else {
525
- SCEmitter . prototype . emit . call ( self , 'error' , err ) ;
525
+ Emitter . prototype . emit . call ( self , 'error' , err ) ;
526
526
}
527
527
} , 0 ) ;
528
528
} ;
@@ -605,9 +605,9 @@ SCSocket.prototype._onSCClose = function (code, data, openAbort) {
605
605
}
606
606
607
607
if ( openAbort ) {
608
- SCEmitter . prototype . emit . call ( self , 'connectAbort' , code , data ) ;
608
+ Emitter . prototype . emit . call ( self , 'connectAbort' , code , data ) ;
609
609
} else {
610
- SCEmitter . prototype . emit . call ( self , 'disconnect' , code , data ) ;
610
+ Emitter . prototype . emit . call ( self , 'disconnect' , code , data ) ;
611
611
}
612
612
613
613
if ( ! SCSocket . ignoreStatuses [ code ] ) {
@@ -629,7 +629,7 @@ SCSocket.prototype._onSCEvent = function (event, data, res) {
629
629
if ( handler ) {
630
630
handler . call ( this , data , res ) ;
631
631
} else {
632
- SCEmitter . prototype . emit . call ( this , event , data , function ( ) {
632
+ Emitter . prototype . emit . call ( this , event , data , function ( ) {
633
633
res && res . callback . apply ( res , arguments ) ;
634
634
} ) ;
635
635
}
@@ -709,7 +709,7 @@ SCSocket.prototype.emit = function (event, data, callback) {
709
709
if ( this . _localEvents [ event ] == null ) {
710
710
this . _emit ( event , data , callback ) ;
711
711
} else {
712
- SCEmitter . prototype . emit . call ( this , event , data ) ;
712
+ Emitter . prototype . emit . call ( this , event , data ) ;
713
713
}
714
714
} ;
715
715
@@ -736,8 +736,8 @@ SCSocket.prototype._triggerChannelSubscribe = function (channel, subscriptionOpt
736
736
} ;
737
737
channel . emit ( 'subscribeStateChange' , stateChangeData ) ;
738
738
channel . emit ( 'subscribe' , channelName , subscriptionOptions ) ;
739
- SCEmitter . prototype . emit . call ( this , 'subscribeStateChange' , stateChangeData ) ;
740
- SCEmitter . prototype . emit . call ( this , 'subscribe' , channelName , subscriptionOptions ) ;
739
+ Emitter . prototype . emit . call ( this , 'subscribeStateChange' , stateChangeData ) ;
740
+ Emitter . prototype . emit . call ( this , 'subscribe' , channelName , subscriptionOptions ) ;
741
741
}
742
742
} ;
743
743
@@ -749,7 +749,7 @@ SCSocket.prototype._triggerChannelSubscribeFail = function (err, channel, subscr
749
749
channel . state = channel . UNSUBSCRIBED ;
750
750
751
751
channel . emit ( 'subscribeFail' , err , channelName , subscriptionOptions ) ;
752
- SCEmitter . prototype . emit . call ( this , 'subscribeFail' , err , channelName , subscriptionOptions ) ;
752
+ Emitter . prototype . emit . call ( this , 'subscribeFail' , err , channelName , subscriptionOptions ) ;
753
753
}
754
754
} ;
755
755
@@ -810,7 +810,7 @@ SCSocket.prototype._trySubscribe = function (channel) {
810
810
}
811
811
}
812
812
) ;
813
- SCEmitter . prototype . emit . call ( this , 'subscribeRequest' , channel . name , subscriptionOptions ) ;
813
+ Emitter . prototype . emit . call ( this , 'subscribeRequest' , channel . name , subscriptionOptions ) ;
814
814
}
815
815
} ;
816
816
@@ -851,8 +851,8 @@ SCSocket.prototype._triggerChannelUnsubscribe = function (channel, newState) {
851
851
} ;
852
852
channel . emit ( 'subscribeStateChange' , stateChangeData ) ;
853
853
channel . emit ( 'unsubscribe' , channelName ) ;
854
- SCEmitter . prototype . emit . call ( this , 'subscribeStateChange' , stateChangeData ) ;
855
- SCEmitter . prototype . emit . call ( this , 'unsubscribe' , channelName ) ;
854
+ Emitter . prototype . emit . call ( this , 'subscribeStateChange' , stateChangeData ) ;
855
+ Emitter . prototype . emit . call ( this , 'unsubscribe' , channelName ) ;
856
856
}
857
857
} ;
858
858
0 commit comments