iosignal 1.6.1 → 1.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +254 -247
- package/auth_file.json +13 -13
- package/auth_file.mjs +23 -23
- package/dist/iosignal.cjs +2 -2
- package/dist/iosignal.esm.js.map +1 -1
- package/dist/iosignal.min.js.map +1 -1
- package/index.js +19 -19
- package/indexWebBrowser.js +13 -13
- package/package.json +60 -59
- package/rollup.config.js +69 -69
- package/src/api/RedisAPI.js +65 -68
- package/src/api/api_constant.js +7 -7
- package/src/api/api_reply.js +31 -34
- package/src/api/api_sudo.js +91 -96
- package/src/auth/Auth_Env.js +76 -78
- package/src/auth/Auth_File.js +71 -75
- package/src/auth/Auth_Redis.js +44 -50
- package/src/auth/BohoAuth.js +164 -168
- package/src/client/CongPacket.js +141 -150
- package/src/client/IOCongSocket.js +81 -88
- package/src/client/IOCore.js +822 -851
- package/src/client/IOWS.js +80 -81
- package/src/client/IOWebSocket.js +111 -112
- package/src/common/constants.js +148 -159
- package/src/common/payload.js +81 -82
- package/src/common/quotaTable.js +68 -68
- package/src/common/util.js +61 -61
- package/src/server/FileLogger.js +30 -30
- package/src/server/Manager.js +433 -449
- package/src/server/Metric.js +155 -154
- package/src/server/Remote.js +207 -0
- package/src/server/{ServerRemoteCore.js → RemoteCore.js} +439 -467
- package/src/server/Server.js +163 -166
- package/src/server/serverOption.js +56 -56
- package/test-browser/favicon.ico +0 -0
- package/test-browser/index.html +96 -93
- package/test-browser/server.js +11 -11
- package/test-client-nodejs/client.cjs +17 -17
- package/test-client-nodejs/client.mjs +17 -17
- package/test-client-nodejs/client_api_reply.mjs +15 -15
- package/test-client-nodejs/stateChange.mjs +19 -19
- package/test-server/server-Auth_Env.js +19 -19
- package/test-server/server-Auth_File.js +12 -12
- package/test-server/server-api_reply.js +6 -6
- package/test-server/server-api_sudo.js +7 -7
- package/test-server/server-commonjs.cjs +8 -8
- package/test-server/server-esm.mjs +20 -19
- package/test-server/simple-server.mjs +11 -11
- package/test-signal-payloadType/signalPack.js +34 -34
- package/test-signal-payloadType/signaling.js +60 -60
- package/src/server/ServerRemote.js +0 -227
package/src/server/Server.js
CHANGED
|
@@ -1,166 +1,163 @@
|
|
|
1
|
-
import net from 'net'
|
|
2
|
-
import EventEmitter from 'events'
|
|
3
|
-
import { WebSocketServer } from 'ws'
|
|
4
|
-
import { Manager } from './Manager.js'
|
|
5
|
-
import { serverOption } from './serverOption.js'
|
|
6
|
-
import { STATUS } from '../api/api_constant.js'
|
|
7
|
-
|
|
8
|
-
export class Server extends EventEmitter {
|
|
9
|
-
|
|
10
|
-
constructor(options, authManager
|
|
11
|
-
super();
|
|
12
|
-
this.apiNames = new Set()
|
|
13
|
-
this.wss = {};
|
|
14
|
-
|
|
15
|
-
if (options.timeout) {
|
|
16
|
-
let pingT = parseInt(options.timeout)
|
|
17
|
-
if (pingT && pingT >= 1000) serverOption.timeout = pingT
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
if (options.monitorPeriod) {
|
|
21
|
-
let monitorT = parseInt(options.monitorPeriod)
|
|
22
|
-
if (monitorT && monitorT >= 1000) serverOption.monitorPeriod = monitorT
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
if (options.showMessage) {
|
|
27
|
-
serverOption.showMessage = options.showMessage
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
if (options.showMetric) {
|
|
31
|
-
serverOption.showMetric = options.showMetric
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
if (options.timeout) {
|
|
35
|
-
serverOption.timeout = options.timeout
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
if (options.port) {
|
|
39
|
-
serverOption.port = parseInt(options.port)
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
if (options.httpServer) {
|
|
43
|
-
serverOption.httpServer = options.httpServer
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
if (options.congPort) {
|
|
47
|
-
serverOption.congPort = parseInt(options.congPort)
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
this.manager = new Manager(this, authManager)
|
|
51
|
-
|
|
52
|
-
if (serverOption.port || serverOption.httpServer
|
|
53
|
-
if(
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
'
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
ws
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
})
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
}
|
|
1
|
+
import net from 'net'
|
|
2
|
+
import EventEmitter from 'events'
|
|
3
|
+
import { WebSocketServer } from 'ws'
|
|
4
|
+
import { Manager } from './Manager.js'
|
|
5
|
+
import { serverOption } from './serverOption.js'
|
|
6
|
+
import { STATUS } from '../api/api_constant.js'
|
|
7
|
+
|
|
8
|
+
export class Server extends EventEmitter {
|
|
9
|
+
|
|
10
|
+
constructor(options, authManager) {
|
|
11
|
+
super();
|
|
12
|
+
this.apiNames = new Set()
|
|
13
|
+
this.wss = {};
|
|
14
|
+
|
|
15
|
+
if (options.timeout) {
|
|
16
|
+
let pingT = parseInt(options.timeout)
|
|
17
|
+
if (pingT && pingT >= 1000) serverOption.timeout = pingT
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (options.monitorPeriod) {
|
|
21
|
+
let monitorT = parseInt(options.monitorPeriod)
|
|
22
|
+
if (monitorT && monitorT >= 1000) serverOption.monitorPeriod = monitorT
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
if (options.showMessage) {
|
|
27
|
+
serverOption.showMessage = options.showMessage
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (options.showMetric) {
|
|
31
|
+
serverOption.showMetric = options.showMetric
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (options.timeout) {
|
|
35
|
+
serverOption.timeout = options.timeout
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (options.port) {
|
|
39
|
+
serverOption.port = parseInt(options.port)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (options.httpServer) {
|
|
43
|
+
serverOption.httpServer = options.httpServer
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (options.congPort) {
|
|
47
|
+
serverOption.congPort = parseInt(options.congPort)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
this.manager = new Manager(this, authManager)
|
|
51
|
+
|
|
52
|
+
if (serverOption.port || serverOption.httpServer) this.startWSServer(serverOption)
|
|
53
|
+
if (serverOption.congPort) this.startCongServer(serverOption.congPort)
|
|
54
|
+
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
startWSServer(serverOption) {
|
|
59
|
+
|
|
60
|
+
if (serverOption.port) {
|
|
61
|
+
console.log('opening WebSocket Server port:', serverOption.port)
|
|
62
|
+
this.wss = new WebSocketServer({ port: serverOption.port })
|
|
63
|
+
} else if (serverOption.httpServer) {
|
|
64
|
+
console.log('opening WebSocket Server external httpServer:')
|
|
65
|
+
this.wss = new WebSocketServer({ server: serverOption.httpServer })
|
|
66
|
+
} else {
|
|
67
|
+
throw new TypeError(
|
|
68
|
+
'One and only one of the "port", "httpServer"' +
|
|
69
|
+
'must be specified'
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
// this.wss.setMaxListeners(0)
|
|
75
|
+
|
|
76
|
+
this.wss.on('error', (err) => {
|
|
77
|
+
console.error('### ws server error:', err.message)
|
|
78
|
+
if (err.code == 'EADDRINUSE') {
|
|
79
|
+
process.exit()
|
|
80
|
+
}
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
this.wss.on('close', (err) => {
|
|
84
|
+
console.log('### WS server closed.', err)
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
this.wss.on('connection', (ws, req) => {
|
|
88
|
+
ws.socketType = 'websocket'
|
|
89
|
+
this.manager.addRemote(ws, req)
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
startCongServer(congPort) {
|
|
96
|
+
console.log('opening CongSocket Server:', congPort)
|
|
97
|
+
|
|
98
|
+
this.congServer = net.createServer((socket) => {
|
|
99
|
+
this.manager.addRemote(socket)
|
|
100
|
+
})
|
|
101
|
+
.on('error', (err) => {
|
|
102
|
+
console.log('### cong server error:', err.message)
|
|
103
|
+
if (err.code == 'EADDRINUSE') {
|
|
104
|
+
process.exit()
|
|
105
|
+
}
|
|
106
|
+
}).listen(congPort, () => {
|
|
107
|
+
// console.log('congsocket server bound' );
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
api(target, api) {
|
|
114
|
+
|
|
115
|
+
this.apiNames.add(target)
|
|
116
|
+
|
|
117
|
+
if (!api.checkPermission || typeof api.checkPermission != 'function') {
|
|
118
|
+
throw new Error('wrong api interface. no checkPermission function.')
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
if (typeof api.request == 'function' && Array.isArray(api.commands)) {
|
|
123
|
+
console.log(`API TYPE1. A Class with one request function. target: ${target} list: ${api.commands}`)
|
|
124
|
+
|
|
125
|
+
this.on(target, (remote, req) => {
|
|
126
|
+
if (api.checkPermission(remote, req)) {
|
|
127
|
+
api.request(remote, req)
|
|
128
|
+
} else {
|
|
129
|
+
remote.response(req.mid, STATUS.ERROR, "NO_PERMISSION.")
|
|
130
|
+
}
|
|
131
|
+
})
|
|
132
|
+
|
|
133
|
+
} else {
|
|
134
|
+
let apiList = []
|
|
135
|
+
Object.keys(api).forEach(v => {
|
|
136
|
+
if (typeof api[v] === 'function') apiList.push(v)
|
|
137
|
+
console.log('api list', typeof api[v], v)
|
|
138
|
+
})
|
|
139
|
+
|
|
140
|
+
console.log(`API TYPE2. Multiple function list. target: ${target} list:${apiList}`)
|
|
141
|
+
|
|
142
|
+
this.on(target, (remote, req) => {
|
|
143
|
+
let r;
|
|
144
|
+
if (!api.checkPermission(remote, req)) {
|
|
145
|
+
r = "NO_PERMISSION."
|
|
146
|
+
} else {
|
|
147
|
+
if (api[req.topic]) {
|
|
148
|
+
console.log(`API TYPE2. request target: ${target} has topic:${req.topic}`)
|
|
149
|
+
api[req.topic](remote, req)
|
|
150
|
+
return
|
|
151
|
+
} else {
|
|
152
|
+
r = `target: ${req.target} has not topic name: ${req.topic}`
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
remote.response(req.mid, STATUS.ERROR, r)
|
|
157
|
+
})
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
return this
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
}
|
|
@@ -1,56 +1,56 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export let serverOption = {
|
|
4
|
-
clientTracking: false,
|
|
5
|
-
port: 0, //wsPort
|
|
6
|
-
httpServer: null,
|
|
7
|
-
congPort: 0,
|
|
8
|
-
timeout: 50000,
|
|
9
|
-
showMessage: 'none',
|
|
10
|
-
showMetric: 0,
|
|
11
|
-
showChannel: 0,
|
|
12
|
-
monitorPeriod: 5000,
|
|
13
|
-
fileLogger:{
|
|
14
|
-
connection: {
|
|
15
|
-
use: false,
|
|
16
|
-
path: 'connection.log'
|
|
17
|
-
},
|
|
18
|
-
auth: {
|
|
19
|
-
use: false,
|
|
20
|
-
path: 'auth.log'
|
|
21
|
-
},
|
|
22
|
-
attack:{
|
|
23
|
-
use: false,
|
|
24
|
-
path:'attack.log'
|
|
25
|
-
}
|
|
26
|
-
},
|
|
27
|
-
useQuota:{
|
|
28
|
-
signalSize: false,
|
|
29
|
-
publishCounter: false,
|
|
30
|
-
trafficRate: false,
|
|
31
|
-
disconnect: false
|
|
32
|
-
},
|
|
33
|
-
defaultQuotaIndex: 3,
|
|
34
|
-
adminLevel: 255,
|
|
35
|
-
|
|
36
|
-
debug:{
|
|
37
|
-
slow: false,
|
|
38
|
-
delay: 500,
|
|
39
|
-
showAuthInfo: false
|
|
40
|
-
},
|
|
41
|
-
|
|
42
|
-
retain:{
|
|
43
|
-
isAvailable: true,
|
|
44
|
-
limitSize: 100000,
|
|
45
|
-
limitCounter: 1000
|
|
46
|
-
},
|
|
47
|
-
|
|
48
|
-
auth:{
|
|
49
|
-
delay_auth_fail: 1000,
|
|
50
|
-
},
|
|
51
|
-
|
|
52
|
-
memberOnly: false
|
|
53
|
-
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
export let serverOption = {
|
|
4
|
+
clientTracking: false,
|
|
5
|
+
port: 0, //wsPort
|
|
6
|
+
httpServer: null,
|
|
7
|
+
congPort: 0,
|
|
8
|
+
timeout: 50000,
|
|
9
|
+
showMessage: 'none',
|
|
10
|
+
showMetric: 0,
|
|
11
|
+
showChannel: 0,
|
|
12
|
+
monitorPeriod: 5000,
|
|
13
|
+
fileLogger: {
|
|
14
|
+
connection: {
|
|
15
|
+
use: false,
|
|
16
|
+
path: 'connection.log'
|
|
17
|
+
},
|
|
18
|
+
auth: {
|
|
19
|
+
use: false,
|
|
20
|
+
path: 'auth.log'
|
|
21
|
+
},
|
|
22
|
+
attack: {
|
|
23
|
+
use: false,
|
|
24
|
+
path: 'attack.log'
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
useQuota: {
|
|
28
|
+
signalSize: false,
|
|
29
|
+
publishCounter: false,
|
|
30
|
+
trafficRate: false,
|
|
31
|
+
disconnect: false
|
|
32
|
+
},
|
|
33
|
+
defaultQuotaIndex: 3,
|
|
34
|
+
adminLevel: 255,
|
|
35
|
+
|
|
36
|
+
debug: {
|
|
37
|
+
slow: false,
|
|
38
|
+
delay: 500,
|
|
39
|
+
showAuthInfo: false
|
|
40
|
+
},
|
|
41
|
+
|
|
42
|
+
retain: {
|
|
43
|
+
isAvailable: true,
|
|
44
|
+
limitSize: 100000,
|
|
45
|
+
limitCounter: 1000
|
|
46
|
+
},
|
|
47
|
+
|
|
48
|
+
auth: {
|
|
49
|
+
delay_auth_fail: 1000,
|
|
50
|
+
},
|
|
51
|
+
|
|
52
|
+
memberOnly: false
|
|
53
|
+
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
|
package/test-browser/favicon.ico
CHANGED
|
File without changes
|
package/test-browser/index.html
CHANGED
|
@@ -1,94 +1,97 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html lang="en">
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
<meta
|
|
6
|
-
<meta
|
|
7
|
-
<
|
|
8
|
-
<
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
</
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
<
|
|
19
|
-
<
|
|
20
|
-
<p>
|
|
21
|
-
<
|
|
22
|
-
<
|
|
23
|
-
<p>
|
|
24
|
-
<
|
|
25
|
-
<
|
|
26
|
-
<
|
|
27
|
-
<
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
console.log('
|
|
31
|
-
console.log('
|
|
32
|
-
console.log('
|
|
33
|
-
console.log('
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
var
|
|
38
|
-
|
|
39
|
-
var
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
io3.signal(channelName )
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
let
|
|
74
|
-
|
|
75
|
-
v.
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
console.log('
|
|
89
|
-
console.log('
|
|
90
|
-
console.log('
|
|
91
|
-
console.log('
|
|
92
|
-
|
|
93
|
-
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
|
|
4
|
+
<head>
|
|
5
|
+
<meta charset="UTF-8">
|
|
6
|
+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
|
7
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
8
|
+
<title>Document</title>
|
|
9
|
+
<style>
|
|
10
|
+
#messageView {
|
|
11
|
+
border: 1px solid red;
|
|
12
|
+
padding: 2em;
|
|
13
|
+
}
|
|
14
|
+
</style>
|
|
15
|
+
</head>
|
|
16
|
+
|
|
17
|
+
<body>
|
|
18
|
+
<h2>Simple pub sub example.</h2>
|
|
19
|
+
<p>you should start server first.</p>
|
|
20
|
+
<p>this index.html load two types of modules. </p>
|
|
21
|
+
<h5>1. IIFE: iosignal.min.js</h5>
|
|
22
|
+
<p>use global name: IO </p>
|
|
23
|
+
<p>IO has props: Boho, MBP, Buffer,, </p>
|
|
24
|
+
<h5>2. ESM: iosignal.esm.js</h5>
|
|
25
|
+
<p> check the console.</p>
|
|
26
|
+
<h2>message log</h2>
|
|
27
|
+
<div id="messageView">...</div>
|
|
28
|
+
<script src="../dist/iosignal.min.js"></script>
|
|
29
|
+
<script>
|
|
30
|
+
console.log('IIFE:')
|
|
31
|
+
console.log('IO', IO)
|
|
32
|
+
console.log('MBP', IO.MBP)
|
|
33
|
+
console.log('Buffer', IO.Buffer)
|
|
34
|
+
console.log('Boho', IO.Boho)
|
|
35
|
+
console.log('sha256.hash("hi")', IO.Boho.sha256.hash('hi'))
|
|
36
|
+
|
|
37
|
+
var ESM_IO;
|
|
38
|
+
IO.binaryType = "blob"
|
|
39
|
+
var io1 = new IO('ws://localhost:7777')
|
|
40
|
+
var io2 = new IO('ws://localhost:7777')
|
|
41
|
+
var io3 = new IO('ws://localhost:7777')
|
|
42
|
+
|
|
43
|
+
io1.on('error', errorHandler)
|
|
44
|
+
io2.on('error', errorHandler)
|
|
45
|
+
io3.on('error', errorHandler)
|
|
46
|
+
|
|
47
|
+
let channelName = 'io'
|
|
48
|
+
// classic style subsribing
|
|
49
|
+
io1.on('ready', e => {
|
|
50
|
+
io1.subscribe(channelName)
|
|
51
|
+
io1.on(channelName, (...args) => {
|
|
52
|
+
// console.log('io1 received', args )
|
|
53
|
+
let msg = '[io1] ' + JSON.stringify(args)
|
|
54
|
+
addMessage(msg)
|
|
55
|
+
})
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
// modern style subscribing
|
|
59
|
+
io2.listen(channelName, (...args) => {
|
|
60
|
+
// console.log('io2 receive', args )
|
|
61
|
+
let msg = '[io2] ' + JSON.stringify(args)
|
|
62
|
+
addMessage(msg)
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
setInterval(e => {
|
|
66
|
+
io3.signal(channelName, 'single string') // single string payload
|
|
67
|
+
io3.signal(channelName, Date.now(), 'a', 2, { key: 3 }) //multiple payload
|
|
68
|
+
io3.signal(channelName) // pure signal without payload.
|
|
69
|
+
}, 3000)
|
|
70
|
+
|
|
71
|
+
function addMessage(msg) {
|
|
72
|
+
|
|
73
|
+
let p = document.createElement('p')
|
|
74
|
+
p.textContent = msg
|
|
75
|
+
let v = document.querySelector('#messageView')
|
|
76
|
+
if (v.childElementCount > 20) v.innerHTML = ""
|
|
77
|
+
v.prepend(p)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function errorHandler(e) {
|
|
81
|
+
console.log(e.target)
|
|
82
|
+
addMessage('ws.error')
|
|
83
|
+
}
|
|
84
|
+
</script>
|
|
85
|
+
<!-- <script type="module">
|
|
86
|
+
import { IO, Boho, MBP, Buffer, sha256 } from "../dist/iosignal.esm.js"
|
|
87
|
+
ESM_IO = IO
|
|
88
|
+
console.log('ESM:')
|
|
89
|
+
console.log('IO', IO)
|
|
90
|
+
console.log('Boho', Boho )
|
|
91
|
+
console.log('MBP', MBP )
|
|
92
|
+
console.log('Buffer', Buffer)
|
|
93
|
+
console.log('sha256.hash("hi")', sha256.hash('hi'))
|
|
94
|
+
</script> -->
|
|
95
|
+
</body>
|
|
96
|
+
|
|
94
97
|
</html>
|
package/test-browser/server.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { Server } from 'iosignal'
|
|
2
|
-
|
|
3
|
-
const options = {
|
|
4
|
-
port: 7777,
|
|
5
|
-
showMetric: 2,
|
|
6
|
-
showMessage: 'message'
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
const server = new Server(
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
import { Server } from 'iosignal'
|
|
2
|
+
|
|
3
|
+
const options = {
|
|
4
|
+
port: 7777,
|
|
5
|
+
showMetric: 2,
|
|
6
|
+
showMessage: 'message'
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const server = new Server(options)
|
|
10
|
+
|
|
11
|
+
|