mirror of
https://github.com/LLOneBot/LLOneBot.git
synced 2024-11-22 01:56:33 +00:00
fix: send ws heart packet
This commit is contained in:
parent
3c73826788
commit
b23170e24f
@ -7,9 +7,10 @@ import {ActionName} from "../../action/types";
|
|||||||
import {OB11Response} from "../../action/utils";
|
import {OB11Response} from "../../action/utils";
|
||||||
import BaseAction from "../../action/BaseAction";
|
import BaseAction from "../../action/BaseAction";
|
||||||
import {actionMap} from "../../action";
|
import {actionMap} from "../../action";
|
||||||
import {registerWsEventSender, unregisterWsEventSender} from "../postOB11Event";
|
import {postWsEvent, registerWsEventSender, unregisterWsEventSender} from "../postOB11Event";
|
||||||
import {wsReply} from "./reply";
|
import {wsReply} from "./reply";
|
||||||
import {WebSocket as WebSocketClass} from "ws";
|
import {WebSocket as WebSocketClass} from "ws";
|
||||||
|
import {OB11HeartbeatEvent} from "../../event/meta/OB11HeartbeatEvent";
|
||||||
|
|
||||||
export let rwsList: ReverseWebsocket[] = [];
|
export let rwsList: ReverseWebsocket[] = [];
|
||||||
|
|
||||||
@ -76,7 +77,7 @@ export class ReverseWebsocket {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private connect() {
|
private connect() {
|
||||||
const {token} = getConfigUtil().getConfig()
|
const {token, heartInterval} = getConfigUtil().getConfig()
|
||||||
this.websocket = new WebSocketClass(this.url, {
|
this.websocket = new WebSocketClass(this.url, {
|
||||||
handshakeTimeout: 2000,
|
handshakeTimeout: 2000,
|
||||||
perMessageDeflate: false,
|
perMessageDeflate: false,
|
||||||
@ -101,7 +102,11 @@ export class ReverseWebsocket {
|
|||||||
|
|
||||||
this.websocket.on("error", log);
|
this.websocket.on("error", log);
|
||||||
|
|
||||||
|
const wsClientInterval = setInterval(() => {
|
||||||
|
postWsEvent(new OB11HeartbeatEvent(selfInfo.online, true, heartInterval));
|
||||||
|
}, heartInterval); // 心跳包
|
||||||
this.websocket.on("close", () => {
|
this.websocket.on("close", () => {
|
||||||
|
clearInterval(wsClientInterval);
|
||||||
log("The websocket connection: " + this.url + " closed, trying reconnecting...");
|
log("The websocket connection: " + this.url + " closed, trying reconnecting...");
|
||||||
this.onclose();
|
this.onclose();
|
||||||
});
|
});
|
||||||
|
@ -10,6 +10,7 @@ import {OB11HeartbeatEvent} from "../../event/meta/OB11HeartbeatEvent";
|
|||||||
import {WebsocketServerBase} from "../../../common/server/websocket";
|
import {WebsocketServerBase} from "../../../common/server/websocket";
|
||||||
import {IncomingMessage} from "node:http";
|
import {IncomingMessage} from "node:http";
|
||||||
import {wsReply} from "./reply";
|
import {wsReply} from "./reply";
|
||||||
|
import {selfInfo} from "../../../common/data";
|
||||||
|
|
||||||
let heartbeatRunning = false;
|
let heartbeatRunning = false;
|
||||||
|
|
||||||
@ -58,7 +59,7 @@ class OB11WebsocketServer extends WebsocketServerBase {
|
|||||||
}
|
}
|
||||||
const {heartInterval} = getConfigUtil().getConfig();
|
const {heartInterval} = getConfigUtil().getConfig();
|
||||||
const wsClientInterval = setInterval(() => {
|
const wsClientInterval = setInterval(() => {
|
||||||
postWsEvent(new OB11HeartbeatEvent(true, true, heartInterval));
|
postWsEvent(new OB11HeartbeatEvent(selfInfo.online, true, heartInterval));
|
||||||
}, heartInterval); // 心跳包
|
}, heartInterval); // 心跳包
|
||||||
wsClient.on("close", () => {
|
wsClient.on("close", () => {
|
||||||
log("event上报ws客户端已断开")
|
log("event上报ws客户端已断开")
|
||||||
|
@ -74,7 +74,7 @@ async function onSettingWindowCreated(view: Element) {
|
|||||||
</setting-item>
|
</setting-item>
|
||||||
<div id="config-ob11-wsHosts-list"></div>
|
<div id="config-ob11-wsHosts-list"></div>
|
||||||
</div>`,
|
</div>`,
|
||||||
SettingItem('反向 WebSocket 服务心跳间隔',
|
SettingItem(' WebSocket 服务心跳间隔',
|
||||||
'控制每隔多久发送一个心跳包,单位为毫秒',
|
'控制每隔多久发送一个心跳包,单位为毫秒',
|
||||||
`<div class="q-input"><input class="q-input__inner" data-config-key="heartInterval" type="number" min="1000" value="${config.heartInterval}" placeholder="${config.heartInterval}" /></div>`,
|
`<div class="q-input"><input class="q-input__inner" data-config-key="heartInterval" type="number" min="1000" value="${config.heartInterval}" placeholder="${config.heartInterval}" /></div>`,
|
||||||
),
|
),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user