screenFront/src/utils/websocket2.ts
2023-05-12 16:41:33 +08:00

30 lines
912 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// websocket实例
let wsObj = null
// ws连接地址
let wsUrl = 'ws://192.168.2.109:9018/'
// let userId = null;
// 是否执行重连 true/不执行 false/执行
let lockReconnect = false
// 重连定时器
let wsCreateHandler = null
// 连接成功,执行回调函数
let messageCallback = null
// 连接失败,执行回调函数
let errorCallback = null
// 发送给后台的数据
let sendDatas = {}
/**
* 发起websocket请求函数
* @param {string} url ws连接地址
* @param {Object} agentData 传给后台的参数
* @param {function} successCallback 接收到ws数据对数据进行处理的回调函数
* @param {function} errCallback ws连接错误的回调函数
*/
export const connectWebsocket = (url, agentData, successCallback, errCallback) => {
wsUrl = url
// createWebSoket()
messageCallback = successCallback
errorCallback = errCallback
sendDatas = agentData
}