Commit 4b9f3813 authored by Chunchi Che's avatar Chunchi Che

fix something

parent 9b55b152
Pipeline #22614 passed with stages
in 10 minutes and 58 seconds
......@@ -51,6 +51,7 @@ export default async function (action: socketAction) {
} else if (isReplay && replayInfo) {
ws = new WebSocketStream(replayInfo.Url, (conn, _event) => {
console.info("replay websocket open.");
conn.binaryType = "arraybuffer";
conn.send(replayInfo.data);
});
......
......@@ -4,8 +4,13 @@ import { UploadOutlined } from "@ant-design/icons";
import { Button, message, Modal, Upload, UploadProps } from "antd";
import React, { useState } from "react";
import { useNavigate } from "react-router-dom";
import rustInit from "rust-src";
import { initStrings } from "@/api";
import { useConfig } from "@/config";
import socketMiddleWare, { socketCmd } from "@/middleware/socket";
import sqliteMiddleWare, { sqliteCmd } from "@/middleware/sqlite";
const NeosConfig = useConfig();
const ReplayModal: React.FC = () => {
const [replay, setReplay] = useState<null | ArrayBuffer>(null);
......@@ -29,10 +34,20 @@ const ReplayModal: React.FC = () => {
title="选择回放"
open={true}
maskClosable={false}
onOk={() => {
onOk={async () => {
if (replay === null) {
message.error("请先上传录像文件");
} else {
// 初始化wasm
const url =
import.meta.env.BASE_URL === "/"
? undefined
: new URL(
"rust_src_bg.wasm",
`${import.meta.env.BASE_URL}assets/`
);
await rustInit(url);
// 连接回放websocket服务
socketMiddleWare({
cmd: socketCmd.CONNECT,
......@@ -43,6 +58,15 @@ const ReplayModal: React.FC = () => {
},
});
// 初始化sqlite
await sqliteMiddleWare({
cmd: sqliteCmd.INIT,
initInfo: { dbUrl: NeosConfig.cardsDbUrl },
});
// 初始化文案
await initStrings();
// 跳转
navigate("/duel/neos/replay/replay.neos.moe");
}
......
......@@ -59,6 +59,14 @@ const WaitRoom = () => {
useEffect(() => {
if (ip && player && player.length != 0 && passWd && passWd.length != 0) {
const init = async () => {
// 初始化wasm
// 需要在连接websocket之前
const url =
import.meta.env.BASE_URL === "/"
? undefined
: new URL("rust_src_bg.wasm", `${import.meta.env.BASE_URL}assets/`);
await rustInit(url);
// 页面第一次渲染时,通过socket中间件向ygopro服务端请求建立长连接
socketMiddleWare({
cmd: socketCmd.CONNECT,
......@@ -77,13 +85,6 @@ const WaitRoom = () => {
// 初始化文案
await initStrings();
// 初始化wasm
const url =
import.meta.env.BASE_URL === "/"
? undefined
: new URL("rust_src_bg.wasm", `${import.meta.env.BASE_URL}assets/`);
await rustInit(url);
};
init();
......
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