Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b6b98bd

Browse files
committed
update: 支持 TabId 不传递模式
1 parent 56384a4 commit b6b98bd

File tree

2 files changed

+19
-14
lines changed

2 files changed

+19
-14
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,6 @@
4141
// 端到端加密密钥(最少 8 位长度,不配置为空或移除)
4242
'e2e_encryption_key' => 'CTZ4PH9JALN375ZXJDJ4',
4343
// 发送异常日志(必须确保目录可写,不配置为空或移除)
44-
'socket_error_log' => runtime_path() . 'socklog_send.log',
44+
'socket_error_log' => runtime_path() . 'socklog_send.log',
4545
]
4646
```

think/SocketV2.php

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class SocketV2 implements LogHandlerInterface
5050

5151
protected array $allowForceClientIds = []; //配置强制推送且被授权的client_id
5252

53-
protected $clientArg = [];
53+
private array $clientArg = [];
5454

5555
protected App $app;
5656
protected SocketClient $client;
@@ -159,7 +159,7 @@ public function save(array $log = []): bool
159159
'css' => '',
160160
];
161161

162-
$tabid = $this->getClientArg('tabid');
162+
$tabId = (int) $this->getClientArg('tabid');
163163

164164
if (!$clientId = $this->getClientArg('client_id')) {
165165
$clientId = '';
@@ -169,10 +169,10 @@ public function save(array $log = []): bool
169169
//强制推送到多个client_id
170170
foreach ($this->allowForceClientIds as $forceClientId) {
171171
$clientId = $forceClientId;
172-
$this->sendToClient($tabid, $clientId, $trace, $forceClientId);
172+
$this->sendToClient($tabId, $clientId, $trace, $forceClientId);
173173
}
174174
} else {
175-
$this->sendToClient($tabid, $clientId, $trace, '');
175+
$this->sendToClient($tabId, $clientId, $trace, '');
176176
}
177177

178178
return true;
@@ -204,14 +204,13 @@ protected function sendToClient($tabId, $clientId, $logs, $forceClientId)
204204

205205
/**
206206
* 检测客户授权
207-
* @return bool
208207
*/
209-
protected function check()
208+
protected function check(): bool
210209
{
211-
$tabid = $this->getClientArg('tabid');
210+
$tabid = (int) $this->getClientArg('tabid');
212211

213212
//是否记录日志的检查
214-
if (!$tabid && !$this->config['force_client_ids']) {
213+
if ($tabid === 0 && !$this->config['force_client_ids']) {
215214
return false;
216215
}
217216

@@ -238,10 +237,8 @@ protected function check()
238237

239238
/**
240239
* 获取客户参数
241-
* @param string $name
242-
* @return string
243240
*/
244-
protected function getClientArg(string $name)
241+
protected function getClientArg(string $name): string
245242
{
246243
if (!$this->app->exists('request')) {
247244
return '';
@@ -254,10 +251,18 @@ protected function getClientArg(string $name)
254251
}
255252

256253
if (!preg_match('/SocketLog\((.*?)\)/', $socketLog, $match)) {
257-
$this->clientArg = ['tabid' => null, 'client_id' => null];
254+
$this->clientArg = [
255+
'tabid' => '-1',
256+
'client_id' => null,
257+
];
258258
return '';
259259
}
260-
parse_str($match[1] ?? '', $this->clientArg);
260+
$tmp = [];
261+
parse_str($match[1] ?? '', $tmp);
262+
$this->clientArg = [
263+
'tabid' => $tmp['tabid'] ?? '-1',
264+
'client_id' => $tmp['client_id'] ?? null,
265+
];
261266
}
262267

263268
if (isset($this->clientArg[$name])) {

0 commit comments

Comments
 (0)