Skip to content

Commit

Permalink
websocket v5 multiple users subscribe to channels at the same time
Browse files Browse the repository at this point in the history
  • Loading branch information
zhouaini528 committed Aug 13, 2021
1 parent 92568ee commit bc50379
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
15 changes: 11 additions & 4 deletions src/Api/WebSocketV5/SocketClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ function keysecret(array $keysecret=[]){
* @param array $sub
*/
public function subscribe(array $sub=[]){
$this->save('add_sub',$this->resub($sub));
$add_sub=$this->get('add_sub');
if(empty($add_sub)) $this->save('add_sub',$this->resub($sub));
else $this->save('add_sub',array_merge($this->resub($sub),$add_sub));
}

/**
Expand Down Expand Up @@ -183,9 +185,14 @@ protected function getData($global,$callback=null,$sub=[]){
*
* */
function reconPrivate(string $key){
$this->client->debug=[
'private'=>[$key=>'close'],
];
$debug=$this->client->debug;
if(empty($debug)){
$this->client->debug=[
'private'=>[$key=>$key],
];
}else{
$this->client->debug=['private'=>array_merge($this->client->debug['private'],[$key=>$key])];
}
}

function reconPublic(){
Expand Down
11 changes: 7 additions & 4 deletions src/Api/WebSocketV5/SocketFunction.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,17 @@ private function reconnection($global,$type='public',array $keysecret=[]){
$this->keysecret=$keysecret;

$temp=[];
foreach ($all_sub as $v){
if(is_array($v) && $keysecret['key']==$v[1]['key']){
$temp[]=$v[0];
foreach ($all_sub as $k=>$v){
$t=explode(self::$USER_DELIMITER,$k);
if(count($t)>1 && $t[0]==$keysecret['key']) {
$temp[]=$v;
}
}
}

$global->save('add_sub',$this->resub($temp));
$add_sub=$global->get('add_sub');
if(empty($add_sub)) $global->save('add_sub',$this->resub($temp));
else $global->save('add_sub',array_merge($this->resub($temp),$add_sub));
}

}
6 changes: 3 additions & 3 deletions src/Api/WebSocketV5/SocketServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -272,10 +272,10 @@ private function debug($con,$global){
}
}else{
//private
if(isset($debug['private'][$con->tag_keysecret['key']]) && $debug['private'][$con->tag_keysecret['key']]=='close'){
if(isset($debug['private'][$con->tag_keysecret['key']]) && $debug['private'][$con->tag_keysecret['key']]==$con->tag_keysecret['key']){
$this->log($con->tag_keysecret['key'].' debug '.json_encode($debug));

$debug['private'][$con->tag_keysecret['key']]='recon';
unset($debug['private'][$con->tag_keysecret['key']]);
$global->save('debug',$debug);

//更改登录状态
Expand Down Expand Up @@ -431,7 +431,7 @@ private function login($global,$key){
}

if($old_client_keysecret[$key]['login']==2) {
$this->log('private doing return '.$key);
$this->log('private login doing return '.$key);
return;
}

Expand Down

0 comments on commit bc50379

Please sign in to comment.