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