Skip to content

Commit

Permalink
websocket v3 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 9, 2021
1 parent ca27ed8 commit 92568ee
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
15 changes: 11 additions & 4 deletions src/Api/WebSocketV3/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 @@ -176,9 +178,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
4 changes: 3 additions & 1 deletion src/Api/WebSocketV3/SocketFunction.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ private function reconnection($global,$type='public',array $keysecret=[]){
}
}

$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));
}
}
4 changes: 2 additions & 2 deletions src/Api/WebSocketV3/SocketServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,10 +252,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

0 comments on commit 92568ee

Please sign in to comment.