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