File tree Expand file tree Collapse file tree 2 files changed +31
-2
lines changed Expand file tree Collapse file tree 2 files changed +31
-2
lines changed Original file line number Diff line number Diff line change @@ -273,6 +273,10 @@ public class PusherConnection: WebSocketDelegate {
273
273
private func handleSubscriptionSucceededEvent( json: PusherEventJSON ) {
274
274
if let channelName = json [ " channel " ] as? String , chan = self . channels. find( channelName) {
275
275
chan. subscribed = true
276
+ if let eData = json [ " data " ] as? String {
277
+ callGlobalCallbacks ( " pusher:subscription_succeeded " , jsonObject: json)
278
+ chan. handleEvent ( " pusher:subscription_succeeded " , eventData: eData)
279
+ }
276
280
if isPresenceChannel ( channelName) {
277
281
if let presChan = self . channels. find ( channelName) as? PresencePusherChannel {
278
282
if let data = json [ " data " ] as? String , dataJSON = getPusherEventJSONFromString( data) {
@@ -384,9 +388,9 @@ public class PusherConnection: WebSocketDelegate {
384
388
}
385
389
386
390
private func callGlobalCallbacks( eventName: String, jsonObject: Dictionary < String , AnyObject > ) {
387
- if let channelName = jsonObject [ " channel " ] as? String , eName = jsonObject [ " event " ] as? String , eData = jsonObject [ " data " ] as? String {
391
+ if let channelName = jsonObject [ " channel " ] as? String , eData = jsonObject [ " data " ] as? String {
388
392
if let globalChannel = self . globalChannel {
389
- globalChannel. handleEvent ( channelName, eventName: eName , eventData: eData)
393
+ globalChannel. handleEvent ( channelName, eventName: eventName , eventData: eData)
390
394
}
391
395
}
392
396
}
Original file line number Diff line number Diff line change @@ -424,6 +424,31 @@ class PusherTopLevelApiSpec: QuickSpec {
424
424
let testChannel = pusher. connection. channels. channels [ " test-channel " ]
425
425
expect ( testChannel? . subscribed) . to ( beTruthy ( ) )
426
426
}
427
+
428
+ it ( " subscription succeeded event sent to global channel " ) {
429
+ let callback = { ( data: AnyObject ? ) -> Void in
430
+ if let eName = data ? [ " event " ] where eName == " pusher:subscription_succeeded " {
431
+ socket. appendToCallbackCheckString ( " globalCallbackCalled " )
432
+ }
433
+ }
434
+ pusher. bind ( callback)
435
+ expect ( socket. callbackCheckString) . to ( equal ( " " ) )
436
+ pusher. subscribe ( " test-channel " )
437
+ expect ( socket. callbackCheckString) . to ( equal ( " globalCallbackCalled " ) )
438
+ }
439
+
440
+ it ( " subscription succeeded event sent to private channel " ) {
441
+ let callback = { ( data: AnyObject ? ) -> Void in
442
+ if let eName = data ? [ " event " ] where eName == " pusher:subscription_succeeded " {
443
+ socket. appendToCallbackCheckString ( " channelCallbackCalled " )
444
+ }
445
+ }
446
+ pusher. bind ( callback)
447
+ expect ( socket. callbackCheckString) . to ( equal ( " " ) )
448
+ let chan = pusher. subscribe ( " test-channel " )
449
+ chan. bind ( " pusher:subscription_succeeded " , callback: callback)
450
+ expect ( socket. callbackCheckString) . to ( equal ( " channelCallbackCalled " ) )
451
+ }
427
452
428
453
it ( " sets up the channel correctly " ) {
429
454
let chan = pusher. subscribe ( " test-channel " )
You can’t perform that action at this time.
0 commit comments