summaryrefslogtreecommitdiffhomepage
path: root/ssh/browser/src/index.js
diff options
context:
space:
mode:
authorMihai Parparita <mihai@tailscale.com>2022-06-08 22:55:55 -0700
committerMihai Parparita <mihai@tailscale.com>2022-06-08 22:55:55 -0700
commit2cbcdc4ba8bae7704b11089993e831161dc64ce2 (patch)
tree550f07d21fb9f0ffa20c114070121235cb116df0 /ssh/browser/src/index.js
parentdecc3ee30d78a68575a74ffced766c5bead8ea08 (diff)
downloadtailscale-mihaip/wasm-taildrop.tar.xz
tailscale-mihaip/wasm-taildrop.zip
wasm: implement Taildrop receivingmihaip/wasm-taildrop
We need to make sure that there's a filesystem (implemented by BrowserFS for now) and then things mostly work. File contents are sent to the JS side as base64 encoded data, which may not work for large files. Signed-off-by: Mihai Parparita <mihai@tailscale.com>
Diffstat (limited to 'ssh/browser/src/index.js')
-rw-r--r--ssh/browser/src/index.js28
1 files changed, 21 insertions, 7 deletions
diff --git a/ssh/browser/src/index.js b/ssh/browser/src/index.js
index f5095f873..72003963b 100644
--- a/ssh/browser/src/index.js
+++ b/ssh/browser/src/index.js
@@ -4,14 +4,25 @@
import "./wasm_exec"
import wasmUrl from "./main.wasm"
-import { notifyState, notifyNetMap, notifyBrowseToURL } from "./notifier"
+import {
+ notifyState,
+ notifyNetMap,
+ notifyBrowseToURL,
+ notifyIncomingFiles,
+} from "./notifier"
import { sessionStateStorage } from "./js-state-store"
+import { injectFS } from "./fs"
-const go = new window.Go()
-WebAssembly.instantiateStreaming(
- fetch(`./dist/${wasmUrl}`),
- go.importObject
-).then((result) => {
+async function main() {
+ // Inject in-memory filesystem (otherwise wasm_exec.js will use a stub that
+ // always returns errors).
+ await injectFS()
+
+ const go = new globalThis.Go()
+ const result = await WebAssembly.instantiateStreaming(
+ fetch(`./dist/${wasmUrl}`),
+ go.importObject
+ )
go.run(result.instance)
const ipn = newIPN({
// Persist IPN state in sessionStorage in development, so that we don't need
@@ -22,5 +33,8 @@ WebAssembly.instantiateStreaming(
notifyState: notifyState.bind(null, ipn),
notifyNetMap: notifyNetMap.bind(null, ipn),
notifyBrowseToURL: notifyBrowseToURL.bind(null, ipn),
+ notifyIncomingFiles: notifyIncomingFiles.bind(null, ipn),
})
-})
+}
+
+main()