-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.html
58 lines (58 loc) · 1.97 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
</head>
<body>
<script src="./out/full.js"></script>
<script>
Object.assign(globalThis, AsyncCall)
class BroadcastMessageChannel extends BroadcastChannel {
on(eventListener) {
const f = (e) => eventListener(e.data)
this.addEventListener('message', f)
return () => this.removeEventListener('message', f)
}
send(data) {
super.postMessage(data)
}
}
const server = new BroadcastMessageChannel('rpc')
const client = new BroadcastMessageChannel('rpc')
let count = 0
function define(def, key = `server${count++}`) {
// define server
AsyncCall(def, {
channel: server,
key,
log: false && {
beCalled: true,
localError: true,
remoteError: true,
type: 'pretty',
requestReplay: true,
sendLocalStack: true,
},
})
// define client
globalThis[key] = AsyncCall({}, { channel: client, key })
console.log('Server is available as global variable', key, globalThis[key], def)
}
function sleep(ms) {
return new Promise((resolve) => setTimeout(resolve, ms))
}
define({
async add(a, b) {
return a + b
},
async error() {
debugger
throw new SyntaxError()
},
async log(...args) {
console.log(...args)
},
})
</script>
</body>
</html>