Skip to content

Commit 44bd4bf

Browse files
committed
am I getting somewhere?
1 parent 6e8270c commit 44bd4bf

File tree

3 files changed

+49
-26
lines changed

3 files changed

+49
-26
lines changed

cmd/wasm/wasm.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@ func main() {
2121
}
2222

2323
func testt(this js.Value, args []js.Value) interface{} {
24-
input := make([]byte, args[0].Get("length").Int())
24+
fmt.Printf("testt: +%v\n", args[0].Get("size"))
25+
input := make([]byte, args[0].Get("size"))
2526
js.CopyBytesToGo(input, args[0])
2627

27-
fmt.Println(args[0].Get("length").Int())
28+
fmt.Println("fer")
2829

2930
gzipReader, streamErr := gzip.NewReader(bytes.NewReader(input))
3031
if streamErr != nil {

web/player/src/App.js

+46-24
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,58 @@
1-
import { Component } from "react";
1+
import { useEffect, useState } from "react";
22
import './App.css';
33
import ErrorBoundary from "./Error";
44
import MessageBus from "./MessageBus";
55
import Player from "./Player";
6-
import Connect from "./Websocket";
76
import Map2d from "./map/Map2d";
87
import InfoPanel from "./panel/InfoPanel";
8+
import './wasm_exec.js';
99

10-
class App extends Component {
11-
constructor(props) {
12-
super(props);
13-
this.messageBus = new MessageBus()
14-
this.player = new Player(this.messageBus)
15-
this.messageBus.listen([13], function (msg) {
10+
function App() {
11+
const [messageBus] = useState(new MessageBus())
12+
const [player] = useState(new Player(messageBus))
13+
const [serverHost] = useState(window.location.host.includes("localhost") ? "http://localhost:8080" : "");
14+
15+
useEffect(() => {
16+
console.log("run run run")
17+
messageBus.listen([13], function (msg) {
1618
alert(msg.message)
1719
})
18-
Connect(this.messageBus)
19-
}
20-
21-
render() {
22-
return (
23-
<ErrorBoundary>
24-
<div className="grid-container">
25-
<div className="grid-item map">
26-
<Map2d messageBus={this.messageBus}/>
27-
</div>
28-
<div className="grid-item infoPanel">
29-
<InfoPanel messageBus={this.messageBus}/>
30-
</div>
31-
</div>
32-
</ErrorBoundary>);
33-
}
20+
// Connect(this.messageBus)
21+
22+
async function loadWasm() {
23+
const go = new window.Go();
24+
WebAssembly.instantiateStreaming(fetch(serverHost + "/wasm"), go.importObject)
25+
.then((result) => {
26+
go.run(result.instance);
27+
28+
29+
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"))
30+
.then((result) => {
31+
console.log(result)
32+
result.blob().then(b => {
33+
console.log(b)
34+
window.testt(b)
35+
})
36+
})
37+
.catch(err => console.log(err))
38+
});
39+
}
40+
41+
loadWasm();
42+
}, [])
43+
44+
45+
return (
46+
<ErrorBoundary>
47+
<div className="grid-container">
48+
<div className="grid-item map">
49+
<Map2d messageBus={messageBus} />
50+
</div>
51+
<div className="grid-item infoPanel">
52+
<InfoPanel messageBus={messageBus} />
53+
</div>
54+
</div>
55+
</ErrorBoundary>);
3456
}
3557

3658
export default App;
File renamed without changes.

0 commit comments

Comments
 (0)