Commit 2439957d authored by Chunchi Che's avatar Chunchi Che

update middleware/socket.ts

parent 8934af06
Pipeline #22612 passed with stages
in 13 minutes and 5 seconds
...@@ -26,6 +26,8 @@ export interface socketAction { ...@@ -26,6 +26,8 @@ export interface socketAction {
player: string; player: string;
passWd: string; passWd: string;
}; };
isReplay?: boolean; // 是否是回放模式
replayUrl?: string; // 提供回放服务的地址,当`isReplay`为true时,必传
// 通过长连接发送的数据 // 通过长连接发送的数据
payload?: Uint8Array; payload?: Uint8Array;
} }
...@@ -36,12 +38,18 @@ let ws: WebSocketStream | null = null; ...@@ -36,12 +38,18 @@ let ws: WebSocketStream | null = null;
export default async function (action: socketAction) { export default async function (action: socketAction) {
switch (action.cmd) { switch (action.cmd) {
case socketCmd.CONNECT: { case socketCmd.CONNECT: {
const info = action.initInfo; const { initInfo: info, isReplay, replayUrl } = action;
if (info) { if (info) {
ws = new WebSocketStream(info.ip, (conn, _event) => ws = new WebSocketStream(info.ip, (conn, _event) =>
handleSocketOpen(conn, info.ip, info.player, info.passWd) handleSocketOpen(conn, info.ip, info.player, info.passWd)
); );
await ws.execute(handleSocketMessage);
} else if (isReplay && replayUrl) {
ws = new WebSocketStream(replayUrl, () =>
console.info("replay websocket open.")
);
await ws.execute(handleSocketMessage); await ws.execute(handleSocketMessage);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment