@@ -179,7 +179,7 @@ export class Pusher {
179
179
const eventName = event . eventName ;
180
180
const data = event . data ;
181
181
const userId = event . userId ;
182
- const channel = this . channels . get ( channelName ) ! ;
182
+ const channel = this . channels . get ( channelName ) ;
183
183
184
184
switch ( eventName ) {
185
185
case 'pusher_internal:subscription_succeeded' :
@@ -188,8 +188,8 @@ export class Pusher {
188
188
for ( const _userId in decodedData ?. presence ?. hash ) {
189
189
const userInfo = decodedData ?. presence ?. hash [ _userId ] ;
190
190
var member = new PusherMember ( _userId , userInfo ) ;
191
- channel . members . set ( member . userId , member ) ;
192
- if ( _userId === userId ) {
191
+ channel ? .members . set ( member . userId , member ) ;
192
+ if ( _userId === userId && channel ) {
193
193
channel . me = member ;
194
194
}
195
195
}
@@ -199,12 +199,14 @@ export class Pusher {
199
199
case 'pusher_internal:subscription_count' :
200
200
// Depending on the platform implementation we get json or a Map.
201
201
var decodedData = data instanceof Object ? data : JSON . parse ( data ) ;
202
- channel . subscriptionCount = decodedData . subscription_count ;
202
+ if ( channel ) {
203
+ channel . subscriptionCount = decodedData . subscription_count ;
204
+ }
203
205
args . onSubscriptionCount ?.(
204
206
channelName ,
205
207
decodedData . subscription_count
206
208
) ;
207
- channel . onSubscriptionCount ?.( decodedData . subscription_count ) ;
209
+ channel ? .onSubscriptionCount ?.( decodedData . subscription_count ) ;
208
210
break ;
209
211
default :
210
212
const pusherEvent = new PusherEvent ( event ) ;
@@ -322,7 +324,7 @@ export class Pusher {
322
324
return await PusherWebsocketReactNative . getSocketId ( ) ;
323
325
}
324
326
325
- public getChannel ( channelName : string ) : PusherChannel {
326
- return this . channels . get ( channelName ) ! ;
327
+ public getChannel ( channelName : string ) : PusherChannel | undefined {
328
+ return this . channels . get ( channelName ) ;
327
329
}
328
330
}
0 commit comments