Commit 9b55b152 authored by Chunchi Che's avatar Chunchi Che

update replay

parent 2439957d
Pipeline #22613 failed with stages
in 1 minute and 39 seconds
......@@ -27,7 +27,10 @@ export interface socketAction {
passWd: string;
};
isReplay?: boolean; // 是否是回放模式
replayUrl?: string; // 提供回放服务的地址,当`isReplay`为true时,必传
replayInfo?: {
Url: string; // 提供回放服务的地址
data: ArrayBuffer; // 回放数据
};
// 通过长连接发送的数据
payload?: Uint8Array;
}
......@@ -38,17 +41,18 @@ let ws: WebSocketStream | null = null;
export default async function (action: socketAction) {
switch (action.cmd) {
case socketCmd.CONNECT: {
const { initInfo: info, isReplay, replayUrl } = action;
const { initInfo: info, isReplay, replayInfo } = action;
if (info) {
ws = new WebSocketStream(info.ip, (conn, _event) =>
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.")
);
} else if (isReplay && replayInfo) {
ws = new WebSocketStream(replayInfo.Url, (conn, _event) => {
console.info("replay websocket open.");
conn.send(replayInfo.data);
});
await ws.execute(handleSocketMessage);
}
......
......@@ -5,6 +5,8 @@ import { Button, message, Modal, Upload, UploadProps } from "antd";
import React, { useState } from "react";
import { useNavigate } from "react-router-dom";
import socketMiddleWare, { socketCmd } from "@/middleware/socket";
const ReplayModal: React.FC = () => {
const [replay, setReplay] = useState<null | ArrayBuffer>(null);
const uploadProps: UploadProps = {
......@@ -31,13 +33,23 @@ const ReplayModal: React.FC = () => {
if (replay === null) {
message.error("请先上传录像文件");
} else {
// 连接回放websocket服务
socketMiddleWare({
cmd: socketCmd.CONNECT,
isReplay: true,
replayInfo: {
Url: "replay.neos.moe", // TODO: useConfig
data: replay,
},
});
// 跳转
// TODO
navigate("/duel/neos/replay/replay.neos.moe");
}
}}
onCancel={() => {
// 断开websocket连接
// TODO
socketMiddleWare({ cmd: socketCmd.DISCONNECT });
// 回到初始界面
navigate("/");
}}
......
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