perf: 优化ws重连规则

This commit is contained in:
kuaifan 2023-02-17 06:01:48 +08:00
parent 1bc614abd2
commit 150462354f
2 changed files with 34 additions and 3 deletions

View File

@ -14,6 +14,7 @@ use App\Models\UserDelete;
use App\Models\UserDepartment;
use App\Models\UserEmailVerification;
use App\Models\UserTransfer;
use App\Models\WebSocket;
use App\Models\WebSocketDialog;
use App\Models\WebSocketDialogMsg;
use App\Module\AgoraIO\AgoraTokenGenerator;
@ -1532,4 +1533,28 @@ class UsersController extends AbstractController
//
return Base::retSuccess('success', $array);
}
/**
* @api {get} api/users/socket/status 27. 获取socket状态
*
* @apiDescription 需要token身份
* @apiVersion 1.0.0
* @apiGroup users
* @apiName socket__status
*
* @apiParam {String} [fd]
*
* @apiSuccess {Number} ret 返回状态码1正确、0错误
* @apiSuccess {String} msg 返回信息(错误描述)
* @apiSuccess {Object} data 返回数据
*/
public function socket__status()
{
$fd = Request::exists('fd') ? Request::input('fd') : Request::header('fd');
$row = WebSocket::select(['id', 'fd', 'userid', 'updated_at'])->whereFd($fd)->first();
if (empty($row)) {
return Base::retError('error');
}
return Base::retSuccess('suceess', $row);
}
}

View File

@ -149,10 +149,16 @@ export default {
if (active) {
this.__windowTimer && clearTimeout(this.__windowTimer)
this.__windowTimer = setTimeout(_ => {
this.$store.dispatch("websocketSend", {
type: 'handshake',
this.$store.dispatch("call", {
url: "users/socket/status",
}).then(_ => {
this.$store.dispatch("websocketSend", {
type: 'handshake',
}).catch(_ => {
this.$store.dispatch("websocketConnection")
})
}).catch(_ => {
this.$store.dispatch("websocketConnection");
this.$store.dispatch("websocketConnection")
})
if (this.themeMode === "auto") {
$A.dark.autoDarkMode()