notif_wasm.mx raw
1 //:build wasm
2
3 package notif
4
5 import (
6 "git.smesh.lol/musiquay/web/common/jsbridge/callback"
7 "unsafe"
8 )
9
10 //:wasmimport bridge notif_send
11 func wasmSend(ptr *byte, length int32, capacity int32)
12
13 //:wasmimport bridge notif_on_message
14 func wasmOnMessage(cbID int32)
15
16 //:wasmimport bridge notif_worker_on_message
17 func wasmWorkerOnMessage(cbID int32)
18
19 //:wasmimport bridge notif_worker_post
20 func wasmWorkerPost(ptr *byte, length int32, capacity int32)
21
22 //:wasmimport bridge notif_worker_set_timeout
23 func wasmWorkerSetTimeout(ms int32, cbID int32) (n int32)
24
25 //:wasmimport bridge notif_worker_clear_timeout
26 func wasmWorkerClearTimeout(handle int32)
27
28 //:wasmimport bridge notif_worker_now_seconds
29 func wasmWorkerNowSeconds() (n int64)
30
31 func Send(msg string) {
32 wasmSend(unsafe.StringData(msg), int32(len(msg)), int32(len(msg)))
33 }
34 func OnMessage(fn func(msg string)) { wasmOnMessage(callback.RegisterS(fn)) }
35 func WorkerOnMessage(fn func(msg string)) { wasmWorkerOnMessage(callback.RegisterS(fn)) }
36 func WorkerPost(msg string) {
37 wasmWorkerPost(unsafe.StringData(msg), int32(len(msg)), int32(len(msg)))
38 }
39 func WorkerSetTimeout(ms int32, fn func()) (n int32) {
40 return wasmWorkerSetTimeout(ms, callback.Register0Once(fn))
41 }
42 func WorkerClearTimeout(handle int32) { wasmWorkerClearTimeout(handle) }
43 func WorkerNowSeconds() (n int64) { return wasmWorkerNowSeconds() }
44