Skip to content

Commit

Permalink
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 4, 2021
1 parent 6a1fdfd commit d68692a
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 9 deletions.
17 changes: 12 additions & 5 deletions src/Api/WebSocket/SocketClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,10 @@ public function subscribe(array $sub=[]){
'connection'=>0,
]);
}
//print_r($this->resub($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 @@ -193,9 +195,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/WebSocket/SocketFunction.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,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));
}
}
3 changes: 2 additions & 1 deletion src/Api/WebSocket/SocketGlobal.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ protected function saveQueue($key,$value){
}

protected function addSubUpdate($data=[]){

do{
$old_value=$new_value=$this->client->add_sub;

Expand All @@ -121,7 +122,7 @@ protected function addSubUpdate($data=[]){
}else{
foreach ($new_value as $k=>$v){
foreach ($data as $dk=>$dv){
if($v[0]==$dv[0]){
if($v[0]==$dv[0] && $v[1]['key']==$dv[1]['key']){
unset($data[$dk]);
unset($new_value[$k]);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Api/WebSocket/SocketServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -340,10 +340,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 d68692a

Please sign in to comment.