-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix build of WASM-page using Go instead of TinyGo
- Loading branch information
Showing
6 changed files
with
66 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,38 @@ | ||
// SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly> | ||
// SPDX-License-Identifier: MIT | ||
|
||
/* global WebAssembly, TextDecoder, TextEncoder */ | ||
|
||
require('./wasm_exec.js') | ||
const go = new global.Go() | ||
const importObject = go.importObject | ||
|
||
const remoteDescription = `{"type": "offer", "sdp": "v=0\r\no=- 0 0 IN IP4 127.0.0.1\r\ns=-\r\nc=IN IP4 127.0.0.1\r\nt=0 0\r\nm=audio 4000 RTP/AVP 111\r\na=rtpmap:111 OPUS/48000/2\r\nm=video 4002 RTP/AVP 96\r\na=rtpmap:96 VP8/90000"}` | ||
const localDescription = `{"type": "answer", "sdp": "v=0\r\no=- 0 0 IN IP4 127.0.0.1\r\ns=-\r\nc=IN IP4 127.0.0.1\r\nt=0 0\r\nm=audio 4000 RTP/AVP 111\r\na=rtpmap:111 OPUS/48000/2\r\nm=video 4002 RTP/AVP 96\r\na=rtpmap:96 VP8/90000"}` | ||
|
||
WebAssembly.instantiate(require('fs').readFileSync('wasm.wasm'), importObject).then(wasmModule => { | ||
go.run(wasmModule.instance) | ||
let exports = wasmModule.instance.exports | ||
|
||
let wasmMemory = () => { | ||
return new Uint8Array(exports.memory.buffer) | ||
} | ||
let memoryOffset = exports.getWasmMemoryBufferOffset() | ||
|
||
wasmMemory().set((new TextEncoder().encode(remoteDescription)), memoryOffset) | ||
exports.SetRemoteDescription(remoteDescription.length) | ||
|
||
wasmMemory().set((new TextEncoder().encode(localDescription)), memoryOffset) | ||
exports.SetLocalDescription(localDescription.length) | ||
|
||
let explainSize = exports.Explain() | ||
console.log(new TextDecoder().decode(wasmMemory().subarray(memoryOffset, memoryOffset + explainSize))) | ||
}) | ||
globalThis.require = require; | ||
globalThis.fs = require("fs"); | ||
globalThis.TextEncoder = require("util").TextEncoder; | ||
globalThis.TextDecoder = require("util").TextDecoder; | ||
|
||
globalThis.performance = { | ||
now() { | ||
const [sec, nsec] = process.hrtime(); | ||
return sec * 1000 + nsec / 1000000; | ||
}, | ||
}; | ||
|
||
const crypto = require("crypto"); | ||
globalThis.crypto = { | ||
getRandomValues(b) { | ||
crypto.randomFillSync(b); | ||
}, | ||
}; | ||
|
||
require("./wasm_exec"); | ||
|
||
const go = new Go(); | ||
WebAssembly.instantiate(fs.readFileSync('wasm.wasm'), go.importObject).then((result) => { | ||
go.run(result.instance); | ||
|
||
result_str = explain(localDescription, remoteDescription) | ||
result = JSON.parse(result_str) | ||
console.log(result) | ||
}).catch((err) => { | ||
console.error(err); | ||
process.exit(1); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters