feat: ws心跳消息
This commit is contained in:
@@ -119,18 +119,16 @@ export class WS {
|
||||
};
|
||||
// 用于指定当从服务器接受到信息时的回调函数。
|
||||
ws.onmessage = ev => {
|
||||
if (ev.type !== 'message') return;
|
||||
// 解析文本消息
|
||||
if (ev.type === 'message') {
|
||||
const data = ev.data;
|
||||
try {
|
||||
const jsonData = JSON.parse(data);
|
||||
const jsonData = JSON.parse(ev.data);
|
||||
if (typeof options.onmessage === 'function') {
|
||||
options.onmessage(jsonData);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('websocket message formatting error', error);
|
||||
}
|
||||
}
|
||||
};
|
||||
// 用于指定连接关闭后的回调函数。
|
||||
ws.onclose = ev => {
|
||||
@@ -221,7 +219,7 @@ export class WS {
|
||||
this.heartInterval = window.setInterval(() => {
|
||||
this.send({
|
||||
requestId: `${Date.now()}`,
|
||||
type: 'ping',
|
||||
type: 'PING',
|
||||
});
|
||||
}, heartTimer);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user