@@ -509,9 +509,11 @@ public function getPresenceChannelDataForSubscribe($app_key, $channel)
509509 public function unsubscribePublicChannel ($ connection , $ channel )
510510 {
511511 $ app_key = $ connection ->appKey ;
512- $ this ->_globalData [$ app_key ][$ channel ]['subscription_count ' ]--;
513- if ($ this ->_globalData [$ app_key ][$ channel ]['subscription_count ' ] <= 0 ) {
514- unset($ this ->_globalData [$ app_key ][$ channel ]);
512+ if (isset ($ this ->_globalData [$ app_key ][$ channel ])) {
513+ $ this ->_globalData [$ app_key ][$ channel ]['subscription_count ' ]--;
514+ if ($ this ->_globalData [$ app_key ][$ channel ]['subscription_count ' ] <= 0 ) {
515+ unset($ this ->_globalData [$ app_key ][$ channel ]);
516+ }
515517 }
516518 unset($ connection ->channels [$ channel ], $ this ->_eventClients [$ connection ->appKey ][$ channel ][$ connection ->socketID ]);
517519 }
@@ -541,25 +543,27 @@ public function unsubscribePresenceChannel($connection, $channel, $uid)
541543 {
542544 $ app_key = $ connection ->appKey ;
543545 $ member_removed = false ;
544- $ this ->_globalData [$ app_key ][$ channel ]['subscription_count ' ]--;
545- if ($ this ->_globalData [$ app_key ][$ channel ]['subscription_count ' ] <= 0 ) {
546- unset($ this ->_globalData [$ app_key ][$ channel ]);
547- $ member_removed = true ;
548- } else {
549- if (!isset ($ this ->_globalData [$ app_key ][$ channel ]['users ' ][$ uid ]['ref_count ' ])) {
550- error_log ("\$this->_globalData[ $ app_key][ $ channel]['users'][ $ uid]['ref_count'] not exist \n" );
551- return ;
552- }
553- $ this ->_globalData [$ app_key ][$ channel ]['users ' ][$ uid ]['ref_count ' ]--;
554- $ ref_count = $ this ->_globalData [$ app_key ][$ channel ]['users ' ][$ uid ]['ref_count ' ];
555- if ($ ref_count <= 0 ) {
556- unset($ this ->_globalData [$ app_key ][$ channel ]['users ' ][$ uid ]);
546+ if (isset ($ this ->_globalData [$ app_key ][$ channel ])) {
547+ $ this ->_globalData [$ app_key ][$ channel ]['subscription_count ' ]--;
548+ if ($ this ->_globalData [$ app_key ][$ channel ]['subscription_count ' ] <= 0 ) {
549+ unset($ this ->_globalData [$ app_key ][$ channel ]);
557550 $ member_removed = true ;
551+ } else {
552+ if (!isset ($ this ->_globalData [$ app_key ][$ channel ]['users ' ][$ uid ]['ref_count ' ])) {
553+ error_log ("\$this->_globalData[ $ app_key][ $ channel]['users'][ $ uid]['ref_count'] not exist \n" );
554+ return ;
555+ }
556+ $ this ->_globalData [$ app_key ][$ channel ]['users ' ][$ uid ]['ref_count ' ]--;
557+ $ ref_count = $ this ->_globalData [$ app_key ][$ channel ]['users ' ][$ uid ]['ref_count ' ];
558+ if ($ ref_count <= 0 ) {
559+ unset($ this ->_globalData [$ app_key ][$ channel ]['users ' ][$ uid ]);
560+ $ member_removed = true ;
561+ }
562+ }
563+ if ($ member_removed ) {
564+ // {"event":"pusher_internal:member_removed","data":"{\"user_id\":\"14884657801\"}","channel":"presence-channel"}
565+ $ this ->publishToClients ($ app_key , $ channel , 'pusher_internal:member_removed ' , json_encode (array ('user_id ' => $ uid ), JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES ));
558566 }
559- }
560- if ($ member_removed ) {
561- // {"event":"pusher_internal:member_removed","data":"{\"user_id\":\"14884657801\"}","channel":"presence-channel"}
562- $ this ->publishToClients ($ app_key , $ channel , 'pusher_internal:member_removed ' , json_encode (array ('user_id ' => $ uid ), JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES ));
563567 }
564568 unset($ connection ->channels [$ channel ], $ this ->_eventClients [$ connection ->appKey ][$ channel ][$ connection ->socketID ]);
565569 }
0 commit comments