|
1 |
| -import { Component } from "react"; |
| 1 | +import { useEffect, useState } from "react"; |
2 | 2 | import './App.css';
|
3 | 3 | import ErrorBoundary from "./Error";
|
4 | 4 | import MessageBus from "./MessageBus";
|
5 | 5 | import Player from "./Player";
|
6 |
| -import Connect from "./Websocket"; |
7 | 6 | import Map2d from "./map/Map2d";
|
8 | 7 | import InfoPanel from "./panel/InfoPanel";
|
| 8 | +import './wasm_exec.js'; |
9 | 9 |
|
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) { |
16 | 18 | alert(msg.message)
|
17 | 19 | })
|
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>); |
34 | 56 | }
|
35 | 57 |
|
36 | 58 | export default App;
|
0 commit comments