iosignal 1.6.0 → 1.7.0

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.
Files changed (45) hide show
  1. package/dist/iosignal.cjs +2 -2
  2. package/dist/iosignal.esm.js +1 -1
  3. package/dist/iosignal.esm.js.map +1 -1
  4. package/dist/iosignal.min.js +1 -1
  5. package/dist/iosignal.min.js.map +1 -1
  6. package/indexWebBrowser.js +1 -1
  7. package/package.json +2 -2
  8. package/src/api/RedisAPI.js +23 -26
  9. package/src/api/api_reply.js +12 -15
  10. package/src/api/api_sudo.js +67 -72
  11. package/src/auth/Auth_Env.js +7 -9
  12. package/src/auth/Auth_File.js +31 -35
  13. package/src/auth/Auth_Redis.js +15 -21
  14. package/src/auth/BohoAuth.js +68 -72
  15. package/src/client/CongPacket.js +15 -24
  16. package/src/client/IOCongSocket.js +26 -33
  17. package/src/client/IOCore.js +6 -35
  18. package/src/client/IOWS.js +22 -23
  19. package/src/client/IOWebSocket.js +11 -7
  20. package/src/common/constants.js +21 -32
  21. package/src/common/payload.js +47 -48
  22. package/src/common/quotaTable.js +10 -10
  23. package/src/common/util.js +38 -38
  24. package/src/server/FileLogger.js +9 -9
  25. package/src/server/Manager.js +39 -55
  26. package/src/server/Metric.js +54 -53
  27. package/src/server/Remote.js +207 -0
  28. package/src/server/{ServerRemoteCore.js → RemoteCore.js} +53 -81
  29. package/src/server/Server.js +22 -25
  30. package/src/server/serverOption.js +10 -10
  31. package/test-browser/index.html +30 -26
  32. package/test-browser/server.js +1 -1
  33. package/test-client-nodejs/client.cjs +6 -6
  34. package/test-client-nodejs/client.mjs +6 -6
  35. package/test-client-nodejs/client_api_reply.mjs +8 -8
  36. package/test-client-nodejs/stateChange.mjs +7 -7
  37. package/test-server/server-Auth_Env.js +2 -2
  38. package/test-server/server-Auth_File.js +1 -1
  39. package/test-server/server-api_reply.js +2 -2
  40. package/test-server/server-api_sudo.js +3 -3
  41. package/test-server/server-esm.mjs +9 -8
  42. package/test-server/simple-server.mjs +6 -6
  43. package/test-signal-payloadType/signalPack.js +1 -1
  44. package/test-signal-payloadType/signaling.js +4 -4
  45. package/src/server/ServerRemote.js +0 -227
@@ -11,7 +11,7 @@ const NB = MBP.NB
11
11
  const MB = MBP.MB
12
12
 
13
13
 
14
- export class ServerRemoteCore {
14
+ export class RemoteCore {
15
15
  constructor(socket, manager) {
16
16
 
17
17
  this.socket = socket;
@@ -25,12 +25,12 @@ export class ServerRemoteCore {
25
25
  this.channels = new Set(); // subscribed tags
26
26
  this.retain_signal = new Map();
27
27
 
28
- this.ssid = ServerRemoteCore.ssid++; // ordered index number
28
+ this.ssid = RemoteCore.ssid++; // ordered index number
29
29
  this.manager = manager;
30
30
 
31
31
  this.cid; // Communication Id
32
32
  this.did; // Device Id
33
- this.uid;
33
+ this.uid; // User Id
34
34
  this.nick = ""
35
35
 
36
36
 
@@ -49,8 +49,6 @@ export class ServerRemoteCore {
49
49
 
50
50
  static ssid = 1;
51
51
 
52
-
53
-
54
52
  setState(state) {
55
53
  this.state = state
56
54
  if (serverOption.debug.showAuthInfo) {
@@ -59,16 +57,12 @@ export class ServerRemoteCore {
59
57
  }
60
58
  }
61
59
 
62
- getState(){
60
+ getState() { // <Number>
63
61
  return this.state
64
62
  }
65
63
 
66
- getStateName(){
67
- //state <number>
68
- //value of constant STATES.NAME < number >
69
- //type of constant STATES.NAME name < string uppercase >
70
- //stateName,eventName <string lowercase>
71
- return ( CLIENT_STATE[ this.state ]).toLowerCase()
64
+ getStateName() { // <String>
65
+ return (CLIENT_STATE[this.state]).toLowerCase()
72
66
  }
73
67
 
74
68
 
@@ -77,11 +71,11 @@ export class ServerRemoteCore {
77
71
  if (isBinary) {
78
72
  let msgTypeName = IOMsg[message[0]]
79
73
  if (!msgTypeName) msgTypeName = BohoMsg[message[0]]
80
- msgTypeName =' [' + msgTypeName + ']';
74
+ msgTypeName = ' [' + msgTypeName + ']';
81
75
  if (message.byteLength > 40) {
82
76
  console.log(from + msgTypeName + ' LEN:', message.length);
83
77
  } else {
84
- console.log(from + msgTypeName , message);
78
+ console.log(from + msgTypeName, message);
85
79
  }
86
80
 
87
81
  } else {
@@ -102,21 +96,20 @@ export class ServerRemoteCore {
102
96
 
103
97
  // todo:
104
98
  // traffic rate :
105
-
106
99
  return true;
107
100
  }
108
101
 
109
- //
110
102
  onTimeDelayMessage(message, isBinary = true) {
111
103
  setTimeout(() => {
112
104
  this.onSocketMessage(message, isBinary)
113
105
  }
114
106
  , serverOption.debug.delay)
115
107
  }
108
+
116
109
  // CongSocket or WebSocket
117
110
  onSocketMessage(message, isBinary = true) {
118
111
 
119
- this.receiveMonitor() // rx data and ping pong : timeout check
112
+ this.receiveMonitor() // rx-data, ping/pong and timeout check
120
113
  if (!this.rxQuotaChecker(message)) return
121
114
 
122
115
  if (serverOption.showMessage === 'message') this.showMessageLog(message, isBinary)
@@ -127,9 +120,7 @@ export class ServerRemoteCore {
127
120
  msgType = message[0]
128
121
 
129
122
  if (msgType === BohoMsg.ENC_488) {
130
- // let from = this.boho.isAuthorized ? this.cid : "anonymous"
131
- // console.log(`>> [E488] from: ${from} LEN ${message.byteLength}`)
132
- // console.log( "ENC buffer", message)
123
+
133
124
  try {
134
125
  decoded = this.boho.decrypt_488(message)
135
126
  } catch (err) {
@@ -139,17 +130,16 @@ export class ServerRemoteCore {
139
130
 
140
131
  if (decoded) {
141
132
  msgType = decoded[0]
142
- message = decoded // signal message
143
- // console.log('[D]', IOMsg[ msgType] )
133
+ message = decoded
144
134
  } else {
145
135
  return
146
136
  }
147
137
 
148
- } else if (msgType === BohoMsg.ENC_E2E) { // End to End Signal
138
+ } else if (msgType === BohoMsg.ENC_E2E) { // symetric E2EE Signal
149
139
  try {
150
140
  decoded = this.boho.decrypt_488(message)
151
141
  } catch (err) {
152
- console.log('-- E2E DEC_FAIL', err)
142
+ // console.log('-- E2E DEC_FAIL', err)
153
143
  return
154
144
  }
155
145
  // console.log('e2e unpack:', decoded )
@@ -157,7 +147,6 @@ export class ServerRemoteCore {
157
147
  msgType = decoded[0]
158
148
  message.set(decoded, MetaSize.ENC_488) // set decoded signal_e2e headaer.
159
149
  message = message.subarray(MetaSize.ENC_488) // reset offset.
160
- // console.log('[D]', IOMsg[ msgType] )
161
150
  } else {
162
151
  return
163
152
  }
@@ -168,19 +157,18 @@ export class ServerRemoteCore {
168
157
 
169
158
  switch (msgType) {
170
159
  case IOMsg.PING:
171
- // console.log('-- ping from:' , this.cid )
172
160
  this.pong();
173
161
  break;
174
162
 
175
163
  case IOMsg.PONG:
176
- // console.log('<-pong')
177
164
  break;
178
165
 
179
166
  case IOMsg.CID_REQ:
180
167
  if (this.state < CLIENT_STATE.SENT_SERVER_READY) {
181
- // console.log('protocol error. cid_req before server_ready')
168
+ // Protocol violation: CID_REQ was sent before receiving the SERVER_READY signal.
182
169
  this.close()
183
170
  }
171
+
184
172
  if (!this.cid) {
185
173
  this.cid = '?' + webcrypto.getRandomValues(Buffer.alloc(3)).toString('base64url')
186
174
  this.manager.cid2remote.set(this.cid, this)
@@ -206,10 +194,10 @@ export class ServerRemoteCore {
206
194
  this.send(message, isBinary)
207
195
  break;
208
196
 
209
- case IOMsg.IAM: // iam
210
- if(message.byteLength > 1){
197
+ case IOMsg.IAM:
198
+ if (message.byteLength > 1) {
211
199
  let iamInfo = message.subarray(1)
212
- this.nick = decoder.decode(iamInfo)
200
+ this.nick = decoder.decode(iamInfo)
213
201
  console.log('iam nick reset', this.nick)
214
202
  }
215
203
  this.iamResponse()
@@ -222,7 +210,7 @@ export class ServerRemoteCore {
222
210
  if (message.byteLength >= tagLen + 2) {
223
211
  let tag = message.subarray(2, 2 + tagLen)
224
212
  tag = decoder.decode(tag)
225
- this.manager.sender(tag, this, message )
213
+ this.manager.sender(tag, this, message)
226
214
  }
227
215
  }
228
216
  break;
@@ -238,7 +226,6 @@ export class ServerRemoteCore {
238
226
  if (message.byteLength == tagLen + 2) {
239
227
  let tag = message.subarray(2, 2 + tagLen)
240
228
  tag = decoder.decode(tag)
241
- // console.log('unsub: tag', tag)
242
229
  let tagList = tag.split(',')
243
230
  this.manager.unsubscribe(tagList, this)
244
231
  }
@@ -253,14 +240,12 @@ export class ServerRemoteCore {
253
240
  let tag = message.subarray(2, 2 + tagLen)
254
241
  tag = decoder.decode(tag)
255
242
  let tagList = tag.split(',')
256
- // console.log('-- SUBSCRIBE req splittagList', tagList)
257
243
  this.manager.subscribe(tagList, this)
258
244
  }
259
245
  }
260
246
  break;
261
247
 
262
248
  case IOMsg.SUBSCRIBE_REQ: // 2bytes tagLen
263
- // console.log('#####recv sub_req ', message, message.byteLength )
264
249
  if (message.byteLength >= 6) {
265
250
  let msgID = message.readUInt16BE(1)
266
251
  let tagLen = message.readUInt16BE(3)
@@ -269,12 +254,10 @@ export class ServerRemoteCore {
269
254
  tag = decoder.decode(tag)
270
255
  let tagList = tag.split(',')
271
256
  // console.log('>> SUBSCRIBE_REQ from:', this.cid, tagList)
272
- let size = this.manager.subscribe(tagList, this)
273
-
274
- // this.response(msgID, 0, { size: size })
257
+ this.manager.subscribe(tagList, this)
275
258
  this.response(msgID, 0)
276
259
  } else {
277
- this.response(msgID, 255 )
260
+ this.response(msgID, 255)
278
261
  }
279
262
  }
280
263
  break;
@@ -282,15 +265,13 @@ export class ServerRemoteCore {
282
265
 
283
266
  case IOMsg.REQUEST: //api request
284
267
  try {
285
- let req = MBP.unpack( message )
286
- // console.log('request unpack req', req)
287
- if(req){
288
- // console.log('request target:', req.target, 'topic:', req.topic)
289
- if( !req.target || !req.topic ) return
290
- if(this.manager.server.apiNames.has(req.target)){
291
- this.manager.server.emit( req.target, this , req )
292
- }else{
293
- console.log('UnKnown API req: ', req.target)
268
+ let req = MBP.unpack(message)
269
+ if (req) {
270
+ if (!req.target || !req.topic) return
271
+ if (this.manager.server.apiNames.has(req.target)) {
272
+ this.manager.server.emit(req.target, this, req)
273
+ } else {
274
+ // console.log('UnKnown API req: ', req.target)
294
275
  }
295
276
  }
296
277
  } catch (e) {
@@ -331,17 +312,17 @@ export class ServerRemoteCore {
331
312
  this.setState(CLIENT_STATE.RECV_AUTH_HMAC)
332
313
  //async
333
314
  this.manager.authManager.verify_auth_hmac(message, this)
334
- .then(authInfo=>{
335
- if(authInfo){
336
- this.manager.deligateSignal(remote, '@$name', authInfo.name)
337
- // console.log('device login success authInfo', authInfo)
338
- // this.manager.sender('@$name', authInfo.name )
339
- }
315
+ .then(authInfo => {
316
+ if (authInfo) {
317
+ this.manager.deligateSignal(remote, '@$name', authInfo.name)
318
+ // console.log('device login success authInfo', authInfo)
319
+ // this.manager.sender('@$name', authInfo.name )
320
+ }
340
321
 
341
- })
342
- .catch(e=>{
322
+ })
323
+ .catch(e => {
343
324
 
344
- })
325
+ })
345
326
 
346
327
  return;
347
328
 
@@ -366,25 +347,25 @@ export class ServerRemoteCore {
366
347
 
367
348
 
368
349
  response(msgId, statusCode, body) {
369
- // console.log('response body', body)
370
- if( body ){
350
+ // console.log('response body', body)
351
+ if (body) {
371
352
 
372
- this.send_enc_mode( MBP.pack(
353
+ this.send_enc_mode(MBP.pack(
373
354
  MB('#type', '8', IOMsg.RESPONSE_MBP),
374
- MB('status','8', statusCode),
375
- MB('mid','16', msgId),
376
- MB('body',body)
355
+ MB('status', '8', statusCode),
356
+ MB('mid', '16', msgId),
357
+ MB('body', body)
377
358
  ))
378
359
 
379
- }else{
380
- this.send_enc_mode( MBP.pack(
381
- MB('#type','8', IOMsg.RESPONSE_MBP),
382
- MB('status','8', statusCode),
383
- MB('mid','16', msgId)
360
+ } else {
361
+ this.send_enc_mode(MBP.pack(
362
+ MB('#type', '8', IOMsg.RESPONSE_MBP),
363
+ MB('status', '8', statusCode),
364
+ MB('mid', '16', msgId)
384
365
  ))
385
366
 
386
367
  }
387
-
368
+
388
369
  }
389
370
 
390
371
 
@@ -398,29 +379,24 @@ export class ServerRemoteCore {
398
379
  // console.log('svr useEnc', useEncryption, data )
399
380
 
400
381
  if (useEncryption && data[0] == IOMsg.SIGNAL_E2E) {
401
- // E2E는,
402
- // 서버는 수신자와 암호통신하는경우, 헤더부분만 암호화 하고, 데이타 부분은 그대로 전달해야한다.
382
+ // When the server delivers end-to-end encrypted messages,
383
+ // it should only encrypt the header part and pass the data part as is.
403
384
  let tagLen = data[1];
404
385
 
405
386
  // let tagInfo = decoder.decode( data.subarray( 2, 2 + tagLen) )
406
387
  // console.log('server bypass E2E signal taginfo:', tagInfo )
407
388
 
408
389
  let encHeader = this.boho.encrypt_488(data.subarray(0, 3 + tagLen))
409
- // console.log('size check:', encHeader.byteLength == (tagLen + 3 + 21 ) )
410
390
  encHeader[0] = BohoMsg.ENC_E2E
411
- // encHeader 크기가 21(enc_488)크기 만큼 커짐. tagLen+3 + 21
412
391
  let newEncBuffer = Buffer.concat([encHeader, data.subarray(3 + tagLen)])
413
-
414
- // console.log('ENC_E2E', newEncBuffer)
415
392
  this.send(newEncBuffer)
416
393
 
417
394
  } else if (useEncryption) {
418
395
  let encPack = this.boho.encrypt_488(data)
419
396
  if (encPack) {
420
- // console.log('send *S* LEN:', encPack.byteLength)
421
397
  this.send(encPack)
422
398
  } else {
423
- console.log('encryption FAIL: NO DATA TRANSIT')
399
+ // console.log('encryption FAIL: NO DATA TRANSIT')
424
400
  }
425
401
  } else {
426
402
  // console.log('send -N-')
@@ -435,7 +411,6 @@ export class ServerRemoteCore {
435
411
  iamResponse(info = "") {
436
412
 
437
413
  if (info == "") {
438
- //send general info
439
414
  let channels = []
440
415
  for (let tag of this.channels.keys()) {
441
416
  channels.push(tag)
@@ -459,9 +434,6 @@ export class ServerRemoteCore {
459
434
  this.send_enc_mode(pack)
460
435
  }
461
436
 
462
- // storeSet(topic, ...args){
463
- // this.manager.set( this, topic, ...args )
464
- // }
465
437
 
466
438
  }
467
439
 
@@ -7,7 +7,7 @@ import { STATUS } from '../api/api_constant.js'
7
7
 
8
8
  export class Server extends EventEmitter {
9
9
 
10
- constructor(options, authManager ) {
10
+ constructor(options, authManager) {
11
11
  super();
12
12
  this.apiNames = new Set()
13
13
  this.wss = {};
@@ -42,32 +42,31 @@ export class Server extends EventEmitter {
42
42
  if (options.httpServer) {
43
43
  serverOption.httpServer = options.httpServer
44
44
  }
45
-
45
+
46
46
  if (options.congPort) {
47
47
  serverOption.congPort = parseInt(options.congPort)
48
48
  }
49
-
49
+
50
50
  this.manager = new Manager(this, authManager)
51
51
 
52
- if (serverOption.port || serverOption.httpServer ) this.startWSServer(serverOption)
53
- if( serverOption.congPort) this.startCongServer(serverOption.congPort)
54
-
55
- // console.log('serverOption:', serverOption)
52
+ if (serverOption.port || serverOption.httpServer) this.startWSServer(serverOption)
53
+ if (serverOption.congPort) this.startCongServer(serverOption.congPort)
54
+
56
55
  }
57
56
 
58
57
 
59
58
  startWSServer(serverOption) {
60
59
 
61
- if(serverOption.port ){
60
+ if (serverOption.port) {
62
61
  console.log('opening WebSocket Server port:', serverOption.port)
63
62
  this.wss = new WebSocketServer({ port: serverOption.port })
64
- }else if( serverOption.httpServer ){
65
- console.log('opening WebSocket Server external httpServer:' )
63
+ } else if (serverOption.httpServer) {
64
+ console.log('opening WebSocket Server external httpServer:')
66
65
  this.wss = new WebSocketServer({ server: serverOption.httpServer })
67
- }else{
66
+ } else {
68
67
  throw new TypeError(
69
68
  'One and only one of the "port", "httpServer"' +
70
- 'must be specified'
69
+ 'must be specified'
71
70
  );
72
71
  }
73
72
 
@@ -76,7 +75,7 @@ export class Server extends EventEmitter {
76
75
 
77
76
  this.wss.on('error', (err) => {
78
77
  console.error('### ws server error:', err.message)
79
- if(err.code == 'EADDRINUSE'){
78
+ if (err.code == 'EADDRINUSE') {
80
79
  process.exit()
81
80
  }
82
81
  })
@@ -93,7 +92,7 @@ export class Server extends EventEmitter {
93
92
 
94
93
  }
95
94
 
96
- startCongServer( congPort ) {
95
+ startCongServer(congPort) {
97
96
  console.log('opening CongSocket Server:', congPort)
98
97
 
99
98
  this.congServer = net.createServer((socket) => {
@@ -101,10 +100,10 @@ export class Server extends EventEmitter {
101
100
  })
102
101
  .on('error', (err) => {
103
102
  console.log('### cong server error:', err.message)
104
- if(err.code == 'EADDRINUSE'){
103
+ if (err.code == 'EADDRINUSE') {
105
104
  process.exit()
106
105
  }
107
- }).listen( congPort, () => {
106
+ }).listen(congPort, () => {
108
107
  // console.log('congsocket server bound' );
109
108
  });
110
109
  }
@@ -112,17 +111,16 @@ export class Server extends EventEmitter {
112
111
 
113
112
 
114
113
  api(target, api) {
115
-
114
+
116
115
  this.apiNames.add(target)
117
116
 
118
- // common checkPermission
119
117
  if (!api.checkPermission || typeof api.checkPermission != 'function') {
120
118
  throw new Error('wrong api interface. no checkPermission function.')
121
119
  }
122
120
 
123
121
 
124
- if(typeof api.request == 'function' && Array.isArray( api.commands )){
125
- console.log(`API TYPE1. A Class with one request function. target: ${target} list: ${api.commands}` )
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}`)
126
124
 
127
125
  this.on(target, (remote, req) => {
128
126
  if (api.checkPermission(remote, req)) {
@@ -132,11 +130,11 @@ export class Server extends EventEmitter {
132
130
  }
133
131
  })
134
132
 
135
- }else{
133
+ } else {
136
134
  let apiList = []
137
135
  Object.keys(api).forEach(v => {
138
136
  if (typeof api[v] === 'function') apiList.push(v)
139
- console.log('api list',typeof api[v] ,v )
137
+ console.log('api list', typeof api[v], v)
140
138
  })
141
139
 
142
140
  console.log(`API TYPE2. Multiple function list. target: ${target} list:${apiList}`)
@@ -146,9 +144,8 @@ export class Server extends EventEmitter {
146
144
  if (!api.checkPermission(remote, req)) {
147
145
  r = "NO_PERMISSION."
148
146
  } else {
149
- // if (apiList.includes(req.topic)) {
150
- if ( api[req.topic] ) {
151
- console.log(`API TYPE2. request target: ${target} has topic:${req.topic}`)
147
+ if (api[req.topic]) {
148
+ console.log(`API TYPE2. request target: ${target} has topic:${req.topic}`)
152
149
  api[req.topic](remote, req)
153
150
  return
154
151
  } else {
@@ -10,21 +10,21 @@ export let serverOption = {
10
10
  showMetric: 0,
11
11
  showChannel: 0,
12
12
  monitorPeriod: 5000,
13
- fileLogger:{
14
- connection: {
15
- use: false,
13
+ fileLogger: {
14
+ connection: {
15
+ use: false,
16
16
  path: 'connection.log'
17
17
  },
18
18
  auth: {
19
- use: false,
19
+ use: false,
20
20
  path: 'auth.log'
21
21
  },
22
- attack:{
22
+ attack: {
23
23
  use: false,
24
- path:'attack.log'
24
+ path: 'attack.log'
25
25
  }
26
26
  },
27
- useQuota:{
27
+ useQuota: {
28
28
  signalSize: false,
29
29
  publishCounter: false,
30
30
  trafficRate: false,
@@ -33,19 +33,19 @@ export let serverOption = {
33
33
  defaultQuotaIndex: 3,
34
34
  adminLevel: 255,
35
35
 
36
- debug:{
36
+ debug: {
37
37
  slow: false,
38
38
  delay: 500,
39
39
  showAuthInfo: false
40
40
  },
41
41
 
42
- retain:{
42
+ retain: {
43
43
  isAvailable: true,
44
44
  limitSize: 100000,
45
45
  limitCounter: 1000
46
46
  },
47
47
 
48
- auth:{
48
+ auth: {
49
49
  delay_auth_fail: 1000,
50
50
  },
51
51
 
@@ -1,23 +1,25 @@
1
1
  <!DOCTYPE html>
2
2
  <html lang="en">
3
+
3
4
  <head>
4
5
  <meta charset="UTF-8">
5
6
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
6
7
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
7
8
  <title>Document</title>
8
9
  <style>
9
- #messageView{
10
+ #messageView {
10
11
  border: 1px solid red;
11
12
  padding: 2em;
12
13
  }
13
14
  </style>
14
15
  </head>
16
+
15
17
  <body>
16
18
  <h2>Simple pub sub example.</h2>
17
19
  <p>you should start server first.</p>
18
20
  <p>this index.html load two types of modules. </p>
19
21
  <h5>1. IIFE: iosignal.min.js</h5>
20
- <p>use global name: IO </p>
22
+ <p>use global name: IO </p>
21
23
  <p>IO has props: Boho, MBP, Buffer,, </p>
22
24
  <h5>2. ESM: iosignal.esm.js</h5>
23
25
  <p> check the console.</p>
@@ -27,59 +29,60 @@
27
29
  <script>
28
30
  console.log('IIFE:')
29
31
  console.log('IO', IO)
30
- console.log('MBP', IO.MBP )
32
+ console.log('MBP', IO.MBP)
31
33
  console.log('Buffer', IO.Buffer)
32
- console.log('Boho', IO.Boho )
33
- console.log('sha256.hash("hi")', IO.Boho.sha256.hash('hi'))
34
+ console.log('Boho', IO.Boho)
35
+ console.log('sha256.hash("hi")', IO.Boho.sha256.hash('hi'))
34
36
 
35
- var ESM_IO ;
37
+ var ESM_IO;
38
+ IO.binaryType = "blob"
36
39
  var io1 = new IO('ws://localhost:7777')
37
40
  var io2 = new IO('ws://localhost:7777')
38
41
  var io3 = new IO('ws://localhost:7777')
39
42
 
40
- io1.on('error', errorHandler )
41
- io2.on('error', errorHandler )
42
- io3.on('error', errorHandler )
43
+ io1.on('error', errorHandler)
44
+ io2.on('error', errorHandler)
45
+ io3.on('error', errorHandler)
43
46
 
44
47
  let channelName = 'io'
45
48
  // classic style subsribing
46
- io1.on('ready',e=>{
49
+ io1.on('ready', e => {
47
50
  io1.subscribe(channelName)
48
- io1.on(channelName, (...args)=>{
51
+ io1.on(channelName, (...args) => {
49
52
  // console.log('io1 received', args )
50
- let msg = '[io1] ' + JSON.stringify( args )
53
+ let msg = '[io1] ' + JSON.stringify(args)
51
54
  addMessage(msg)
52
55
  })
53
56
  })
54
57
 
55
58
  // modern style subscribing
56
- io2.listen(channelName, (...args)=>{
59
+ io2.listen(channelName, (...args) => {
57
60
  // console.log('io2 receive', args )
58
- let msg = '[io2] ' + JSON.stringify( args )
59
- addMessage(msg)
61
+ let msg = '[io2] ' + JSON.stringify(args)
62
+ addMessage(msg)
60
63
  })
61
64
 
62
- setInterval(e=>{
65
+ setInterval(e => {
63
66
  io3.signal(channelName, 'single string') // single string payload
64
- io3.signal(channelName, Date.now(), 'a', 2 , {key: 3} ) //multiple payload
65
- io3.signal(channelName ) // pure signal without payload.
66
- },3000)
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) {
67
72
 
68
- function addMessage(msg){
69
-
70
73
  let p = document.createElement('p')
71
74
  p.textContent = msg
72
75
  let v = document.querySelector('#messageView')
73
- if(v.childElementCount > 20) v.innerHTML = ""
74
- v.prepend( p )
76
+ if (v.childElementCount > 20) v.innerHTML = ""
77
+ v.prepend(p)
75
78
  }
76
79
 
77
- function errorHandler(e){
80
+ function errorHandler(e) {
78
81
  console.log(e.target)
79
82
  addMessage('ws.error')
80
83
  }
81
84
  </script>
82
- <script type="module">
85
+ <!-- <script type="module">
83
86
  import { IO, Boho, MBP, Buffer, sha256 } from "../dist/iosignal.esm.js"
84
87
  ESM_IO = IO
85
88
  console.log('ESM:')
@@ -88,6 +91,7 @@
88
91
  console.log('MBP', MBP )
89
92
  console.log('Buffer', Buffer)
90
93
  console.log('sha256.hash("hi")', sha256.hash('hi'))
91
- </script>
94
+ </script> -->
92
95
  </body>
96
+
93
97
  </html>
@@ -6,6 +6,6 @@ const options = {
6
6
  showMessage: 'message'
7
7
  }
8
8
 
9
- const server = new Server( options )
9
+ const server = new Server(options)
10
10
 
11
11
 
@@ -3,15 +3,15 @@ const { IO } = require('iosignal')
3
3
 
4
4
  const io = new IO('ws://localhost:7777')
5
5
 
6
- io.on('ready', ()=>{
6
+ io.on('ready', () => {
7
7
  console.log('ready cid:', io.cid)
8
- io.signal('#screen','playToggle')
8
+ io.signal('#screen', 'playToggle')
9
9
  });
10
10
 
11
- io.listen('#notify', (...args)=>{
12
- console.log( args )
11
+ io.listen('#notify', (...args) => {
12
+ console.log(args)
13
13
  })
14
14
 
15
- io.on('error',err=>{
16
- console.log('err', err)
15
+ io.on('error', err => {
16
+ console.log('err', err)
17
17
  })