@@ -674,8 +674,24 @@ public function onApiClientMessage($connection, Request $request)
674674 }
675675 return $ connection ->send ('{} ' );
676676 case 'channels ' :
677+ // info
678+ $ request_info = explode (', ' , $ request ->get ('info ' , '' ));
677679 if (!isset ($ explode [3 ])) {
678- return $ connection ->send (new Response (400 , [], 'Bad Request ' ));
680+ $ channels = [];
681+ $ prefix = $ request ->get ('filter_by_prefix ' );
682+ $ return_subscription_count = in_array ('subscription_count ' , $ request_info );
683+ foreach ($ this ->_globalData [$ app_key ] ?? [] as $ channel => $ item ) {
684+ if ($ prefix !== null ) {
685+ if (strpos ($ channel , $ prefix ) !== 0 ) {
686+ continue ;
687+ }
688+ }
689+ $ channels [$ channel ] = [];
690+ if ($ return_subscription_count ) {
691+ $ channels [$ channel ]['subscription_count ' ] = $ item ['subscription_count ' ];
692+ }
693+ }
694+ return $ connection ->send (json_encode (['channels ' => $ channels ], JSON_UNESCAPED_UNICODE ));
679695 }
680696 $ channel = $ explode [3 ];
681697 // users
@@ -692,16 +708,14 @@ public function onApiClientMessage($connection, Request $request)
692708
693709 $ connection ->send (json_encode ($ user_id_array , JSON_UNESCAPED_UNICODE ));
694710 }
695- // info
696- $ info = explode (', ' , $ request ->get ('info ' , '' ));
697711 $ occupied = isset ($ this ->_globalData [$ app_key ][$ channel ]);
698712 $ user_count = isset ($ this ->_globalData [$ app_key ][$ channel ]['users ' ]) ? count ($ this ->_globalData [$ app_key ][$ channel ]['users ' ]) : 0 ;
699713 $ subscription_count = $ occupied ? $ this ->_globalData [$ app_key ][$ channel ]['subscription_count ' ] : 0 ;
700714 $ channel_info = array (
701715 'occupied ' => $ occupied
702716 );
703- foreach ($ info as $ item ) {
704- switch ($ item ) {
717+ foreach ($ request_info as $ name ) {
718+ switch ($ name ) {
705719 case 'user_count ' :
706720 $ channel_info ['user_count ' ] = $ user_count ;
707721 break ;
0 commit comments