-
Notifications
You must be signed in to change notification settings - Fork 0
/
rpc.js
57 lines (47 loc) · 1.19 KB
/
rpc.js
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
const ParentStream = require('iframe-stream').ParentStream
const dnode = require('dnode')
module.exports = class RPC {
constructor (funcs) {
const d = dnode(funcs)
d.on('remote', r => {
this.remote = r
})
const parentStream = ParentStream()
d.pipe(parentStream).pipe(d)
}
createChannel () {
return new Promise((resolve, reject) => {
this.remote.createChannel(resolve)
})
}
createMessage (data, ports = []) {
return new Promise((resolve, reject) => {
this.remote.createMessage(data, ports, resolve)
})
}
createInstance (message) {
return new Promise((resolve, reject) => {
this.remote.createInstance(message, resolve)
})
}
bindPort (name, port) {
return new Promise((resolve, reject) => {
this.remote.bindPort(name, port, resolve)
})
}
getPort (name) {
return new Promise((resolve, reject) => {
this.remote.getPort(name, resolve)
})
}
deletePort (name) {
return new Promise((resolve, reject) => {
this.remote.deletePort(name, resolve)
})
}
send (port, message) {
return new Promise((resolve, reject) => {
this.remote.send(port, message, resolve)
})
}
}