|
@@ -13,7 +13,11 @@ let reconnectNumber = 0;
|
|
export function openWS({ examRecordDataId }) {
|
|
export function openWS({ examRecordDataId }) {
|
|
window._hmt.push(["_trackEvent", "websocket", "准备连接"]);
|
|
window._hmt.push(["_trackEvent", "websocket", "准备连接"]);
|
|
console.log("in openWS", examRecordDataId);
|
|
console.log("in openWS", examRecordDataId);
|
|
- createLog({ type: "websocket", action: "准备连接", examRecordDataId });
|
|
|
|
|
|
+ createLog({
|
|
|
|
+ type: "微信小程序websocket",
|
|
|
|
+ action: "准备连接",
|
|
|
|
+ examRecordDataId,
|
|
|
|
+ });
|
|
ws = new WebSocket(
|
|
ws = new WebSocket(
|
|
VUE_APP_WK_SERVER_SOCKET_FOR_AUDIO +
|
|
VUE_APP_WK_SERVER_SOCKET_FOR_AUDIO +
|
|
`?key=${store.state.user.key}&token=${store.state.user.token}`
|
|
`?key=${store.state.user.key}&token=${store.state.user.token}`
|
|
@@ -21,7 +25,7 @@ export function openWS({ examRecordDataId }) {
|
|
|
|
|
|
ws.onopen = event => {
|
|
ws.onopen = event => {
|
|
console.log("open ws", event);
|
|
console.log("open ws", event);
|
|
- createLog({ type: "websocket", action: "连接成功" });
|
|
|
|
|
|
+ createLog({ type: "微信小程序websocket", action: "连接成功" });
|
|
reconnectNumber = 0;
|
|
reconnectNumber = 0;
|
|
|
|
|
|
ws.onmessage = processWSMessage;
|
|
ws.onmessage = processWSMessage;
|
|
@@ -29,7 +33,7 @@ export function openWS({ examRecordDataId }) {
|
|
ws.onclose = event => {
|
|
ws.onclose = event => {
|
|
console.log("ws closed by server");
|
|
console.log("ws closed by server");
|
|
createLog({
|
|
createLog({
|
|
- type: "websocket",
|
|
|
|
|
|
+ type: "微信小程序websocket",
|
|
action: "ws closed by server",
|
|
action: "ws closed by server",
|
|
detail: JSON.stringify(event),
|
|
detail: JSON.stringify(event),
|
|
});
|
|
});
|
|
@@ -61,7 +65,7 @@ export function openWS({ examRecordDataId }) {
|
|
"连接被关闭后-准备连接",
|
|
"连接被关闭后-准备连接",
|
|
]);
|
|
]);
|
|
createLog({
|
|
createLog({
|
|
- type: "websocket",
|
|
|
|
|
|
+ type: "微信小程序websocket",
|
|
action: "连接被关闭后-准备连接",
|
|
action: "连接被关闭后-准备连接",
|
|
detail: "onclose",
|
|
detail: "onclose",
|
|
});
|
|
});
|
|
@@ -77,7 +81,7 @@ export function openWS({ examRecordDataId }) {
|
|
|
|
|
|
ws.onerror = event => {
|
|
ws.onerror = event => {
|
|
createLog({
|
|
createLog({
|
|
- type: "websocket",
|
|
|
|
|
|
+ type: "微信小程序websocket",
|
|
action: "onerror",
|
|
action: "onerror",
|
|
error: JSON.stringify(event),
|
|
error: JSON.stringify(event),
|
|
});
|
|
});
|
|
@@ -93,7 +97,7 @@ export function openWS({ examRecordDataId }) {
|
|
closable: true,
|
|
closable: true,
|
|
});
|
|
});
|
|
createLog({
|
|
createLog({
|
|
- type: "websocket",
|
|
|
|
|
|
+ type: "微信小程序websocket",
|
|
action: "Websocket重连失败",
|
|
action: "Websocket重连失败",
|
|
detail: "onerror",
|
|
detail: "onerror",
|
|
});
|
|
});
|
|
@@ -104,7 +108,7 @@ export function openWS({ examRecordDataId }) {
|
|
if (location.href.includes("/order/")) {
|
|
if (location.href.includes("/order/")) {
|
|
window._hmt.push(["_trackEvent", "websocket", "连接错误后-重新连接"]);
|
|
window._hmt.push(["_trackEvent", "websocket", "连接错误后-重新连接"]);
|
|
createLog({
|
|
createLog({
|
|
- type: "websocket",
|
|
|
|
|
|
+ type: "微信小程序websocket",
|
|
action: "连接被关闭后-准备连接",
|
|
action: "连接被关闭后-准备连接",
|
|
detail: "onerror",
|
|
detail: "onerror",
|
|
});
|
|
});
|
|
@@ -133,13 +137,17 @@ function heartbeat() {
|
|
}
|
|
}
|
|
|
|
|
|
export function closeWsWithoutReconnect() {
|
|
export function closeWsWithoutReconnect() {
|
|
- createLog({ type: "websocket", action: "客户端准备关闭ws。" });
|
|
|
|
|
|
+ createLog({ type: "微信小程序websocket", action: "客户端准备关闭ws。" });
|
|
shouldReconnect = false;
|
|
shouldReconnect = false;
|
|
try {
|
|
try {
|
|
if (ws && ws.readyState === 1) ws.close();
|
|
if (ws && ws.readyState === 1) ws.close();
|
|
} catch (e) {
|
|
} catch (e) {
|
|
console.log("关闭ws异常。");
|
|
console.log("关闭ws异常。");
|
|
- createLog({ type: "websocket", action: "关闭ws异常。", detail: e });
|
|
|
|
|
|
+ createLog({
|
|
|
|
+ type: "微信小程序websocket",
|
|
|
|
+ action: "关闭ws异常。",
|
|
|
|
+ detail: e,
|
|
|
|
+ });
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|