Skip to content

Commit a5526ee

Browse files
committed
upload which is not upload somehow works, almost ...
1 parent 58050d4 commit a5526ee

File tree

7 files changed

+111
-90
lines changed

7 files changed

+111
-90
lines changed

web/src/App.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { LocationProvider, Router, Route, lazy } from 'preact-iso';
22
import { Home } from './Index/Home'
3-
import { PlayerApp } from './Player/App'
3+
import { PlayerApp } from './Player/PlayerApp'
44

55
export function App() {
66
return <LocationProvider>

web/src/Index/Home.jsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export function Home() {
4444
// console.log(err)
4545
// setContent(<span className="w3-xxxlarge rotate">failed to contact server ...</span>)
4646
// })
47-
}, [serverHost, auth, isWasmLoaded])
47+
}, [serverHost, auth])
4848

4949
// let faceitAuth = (
5050
// <div className='faceitAuth'>
@@ -146,9 +146,9 @@ export function Home() {
146146
}
147147

148148
function clickeeedd() {
149-
console.log("fjasklfjklas")
150-
window.open("/player", '_blank').focus();
151-
const channel = new BroadcastChannel("my-channel");
149+
const uuid = crypto.randomUUID()
150+
window.open("/player?platform=upload&uuid=" + uuid, '_blank').focus();
151+
const channel = new BroadcastChannel(uuid);
152152
setTimeout(() => {
153153
channel.postMessage("Hey, how's it going mate? I'm from a different tab!");
154154
}, 100)

web/src/Index/Uploader/Uploader.jsx

+6-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,12 @@ const Uploader = (props) => {
2626
const arrayBuffer = e.target.result;
2727
const byteArray = new Uint8Array(arrayBuffer);
2828

29-
window.testt(byteArray)
29+
const uuid = crypto.randomUUID()
30+
window.open("/player?platform=upload&uuid=" + uuid, '_blank').focus();
31+
const channel = new BroadcastChannel(uuid);
32+
setTimeout(() => {
33+
channel.postMessage(byteArray);
34+
}, 1000)
3035
};
3136
reader.readAsArrayBuffer(file);
3237
}

web/src/Player/App.jsx

-78
This file was deleted.

web/src/Player/App.test.js

-6
This file was deleted.
File renamed without changes.

web/src/Player/PlayerApp.jsx

+100
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
import { useEffect, useState } from "react";
2+
import './PlayerApp.css';
3+
import ErrorBoundary from "./Error.jsx";
4+
import MessageBus from "./MessageBus.js";
5+
import Player from "./Player.js";
6+
import Map2d from "./map/Map2d.jsx";
7+
import InfoPanel from "./panel/InfoPanel.jsx";
8+
import '../libs/wasm_exec.js';
9+
import './protos/Message_pb.js'
10+
11+
export function PlayerApp() {
12+
const [messageBus] = useState(new MessageBus())
13+
const [player] = useState(new Player(messageBus))
14+
const [serverHost] = useState(window.location.host.includes("localhost") ? "http://localhost:8080" : "");
15+
const [isWasmLoaded, setIsWasmLoaded] = useState(false)
16+
17+
useEffect(() => {
18+
console.log("run run run")
19+
20+
if (!isWasmLoaded) {
21+
loadWasm();
22+
return
23+
}
24+
25+
const urlParams = new URLSearchParams(window.location.search);
26+
const channel = new BroadcastChannel(urlParams.get("uuid"));
27+
channel.addEventListener("message", e => {
28+
console.log("received", e, isWasmLoaded)
29+
window.testt(e.data, function (data) {
30+
if (data instanceof Uint8Array) {
31+
const msg = proto.Message.deserializeBinary(data).toObject()
32+
messageBus.emit(msg)
33+
} else {
34+
// text frame
35+
// console.log(event.data);
36+
console.log("[message] text data received from server, this is weird. We're using protobufs ?!?!?", data);
37+
messageBus.emit(JSON.parse(data))
38+
}
39+
40+
// console.log(`[message] Data received from server: ${event.data}`);
41+
// let msg = JSON.parse(event.data)
42+
// messageBus.emit(msg)
43+
})
44+
});
45+
messageBus.listen([13], function (msg) {
46+
alert(msg.message)
47+
// window.testt(byteArray)
48+
})
49+
// Connect(this.messageBus)
50+
51+
async function loadWasm() {
52+
const go = new window.Go();
53+
WebAssembly.instantiateStreaming(fetch(serverHost + "/wasm"), go.importObject)
54+
.then((result) => {
55+
go.run(result.instance);
56+
console.log("should be loaded now")
57+
setIsWasmLoaded(true)
58+
// window.withDownload("https://corsproxy.io/?" + encodeURIComponent("https://github.com/sparkoo/csgo-2d-demo-viewer/raw/refs/heads/master/test_demos/1-c26b4e22-66ac-4904-87cc-3b2b65a67ddb-1-1.dem.gz"))
59+
// fetch("https://corsproxy.io/?" + encodeURIComponent("https://github.com/sparkoo/csgo-2d-demo-viewer/raw/refs/heads/master/test_demos/1-c26b4e22-66ac-4904-87cc-3b2b65a67ddb-1-1.dem.gz"))
60+
// .then((result) => {
61+
// console.log(result)
62+
// result.arrayBuffer().then(b => {
63+
// const data = new Uint8Array(b)
64+
// console.log(data)
65+
// window.testt(data, function (data) {
66+
// if(data instanceof Uint8Array) {
67+
// const msg = proto.Message.deserializeBinary(data).toObject()
68+
// messageBus.emit(msg)
69+
// } else {
70+
// // text frame
71+
// // console.log(event.data);
72+
// console.log("[message] text data received from server, this is weird. We're using protobufs ?!?!?", data);
73+
// messageBus.emit(JSON.parse(data))
74+
// }
75+
76+
// // console.log(`[message] Data received from server: ${event.data}`);
77+
// // let msg = JSON.parse(event.data)
78+
// // messageBus.emit(msg)
79+
// })
80+
// })
81+
// })
82+
// .catch(err => console.log(err))
83+
});
84+
}
85+
86+
}, [isWasmLoaded])
87+
88+
89+
return (
90+
<ErrorBoundary>
91+
<div className="grid-container">
92+
<div className="grid-item map">
93+
<Map2d messageBus={messageBus} />
94+
</div>
95+
<div className="grid-item infoPanel">
96+
<InfoPanel messageBus={messageBus} />
97+
</div>
98+
</div>
99+
</ErrorBoundary>);
100+
}

0 commit comments

Comments
 (0)