From 5511b10d1bf16a6a9080fd9f690ddc76c265d37e Mon Sep 17 00:00:00 2001 From: zhouaini528 <465382251@qq.com> Date: Tue, 20 Aug 2024 13:47:13 +0800 Subject: [PATCH] unsubscribe all --- src/Api/WebSocketV5/SocketServer.php | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/src/Api/WebSocketV5/SocketServer.php b/src/Api/WebSocketV5/SocketServer.php index 9e59b43..87c4f83 100644 --- a/src/Api/WebSocketV5/SocketServer.php +++ b/src/Api/WebSocketV5/SocketServer.php @@ -371,15 +371,14 @@ private function unsubscribe($con,$global){ ]; $temp=$global->get('del_sub'); - foreach ($temp as $v){ - if(array_key_exists('key',$v)) { - unset($v['key']); - $sub['private'][]=$v; - } - else $sub['public'][]=$v; - } if($con->tag=='public'){ + + foreach ($temp as $v){ + if(!array_key_exists('key',$v)) $sub['public'][]=$v; + } + if(empty($sub['public'])) return; + $data=[ 'op' => "unsubscribe", 'args' => $sub['public'], @@ -397,13 +396,25 @@ private function unsubscribe($con,$global){ //*******订阅成功后 更改 all_sub public 值 $global->unAllSubUpdate('public',['sub'=>$sub['public']]); }else{ + //获取当前用户 $keysecret=$con->tag_keysecret; + //判断private取消订阅是当前用户 + foreach ($temp as $v){ + if(array_key_exists('key',$v)) { + if($keysecret['key']!==$v['key']) return; + unset($v['key']); + + $sub['private'][]=$v;//TODO 有BUG 全部私有数据 + } + } + $data=[ 'op' => "unsubscribe", 'args' => $sub['private'], ]; - + //print_r($temp); + //print_r($data); $data=json_encode($data); $con->send($data);