Skip to content

Commit

Permalink
Private and Public channel reconnect
Browse files Browse the repository at this point in the history
  • Loading branch information
zhouaini528 committed Jul 15, 2021
1 parent 8b6fde5 commit 8d09794
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 16 deletions.
27 changes: 15 additions & 12 deletions src/Api/WebSocket/SocketClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,21 @@ protected function getData($global,$callback=null,$sub=[]){
return $temp;
}

/*
*
* */
function reconPrivate(string $key){
$this->client->debug=[
'private'=>[$key=>'close'],
];
}

function reconPublic(){
$this->client->debug=[
'public'=>['public'=>'close','kline'=>'close'],
];
}

function test(){
print_r($this->client->all_sub);
print_r($this->client->add_sub);
Expand All @@ -185,19 +200,7 @@ function test2(){
}
}

function test_reconnection(){
$this->client->debug=[
'public'=>['public'=>'close','kline'=>'close'],
];
}

function test_reconnection2(){
$this->client->debug2=1;
}

function test_reconnection3($key){
$this->client->debug=[
'private'=>[$key=>'close'],
];
}
}
8 changes: 7 additions & 1 deletion src/Api/WebSocket/SocketServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,12 @@ private function debug($con,$global){
$debug['private'][$con->tag_keysecret['key']]='recon';
$global->save('debug',$debug);

//更改登录状态
$this->keysecretInit($con->tag_keysecret,[
'connection'=>2,
'auth'=>0,
]);

$con->close();
}
}
Expand Down Expand Up @@ -303,7 +309,7 @@ private function subscribe($con,$global){
if($con->tag!='public' && !empty($temp['private'])){
//判断是否鉴权登录
$keysecret=$global->get('keysecret');
if($keysecret[$con->tag_keysecret['key']]['auth']==0) {
if($keysecret[$con->tag_keysecret['key']]['auth']!=1 || $keysecret[$con->tag_keysecret['key']]['key']!=$con->tag_keysecret['key']) {
$this->log($con->tag_keysecret['key'].' subscribe need login ');
return;
}
Expand Down
14 changes: 14 additions & 0 deletions src/BitmexWebSocket.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,18 @@ public function getSubscribes($callback=null,$daemon=false){
return $this->client()->getSubscribes($callback,$daemon);
}

/**
* Private channel reconnect
* @param string $key
*/
public function reconPrivate(string $key){
$this->client()->reconPrivate($key);
}

/**
* Public channel reconnect
*/
public function reconPublic(){
$this->client()->reconPublic();
}
}
5 changes: 2 additions & 3 deletions tests/websocket/client.php
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,7 @@
}

case 10005:{
$bitmex->client()->test_reconnection();

$bitmex->reconPublic();
break;
}

Expand All @@ -283,7 +282,7 @@
}

case 10008:{
$bitmex->client()->test_reconnection3($key_secret[0]['key']);
$bitmex->reconPrivate($key_secret[0]['key']);
break;
}
}
Expand Down

0 comments on commit 8d09794

Please sign in to comment.