iosignal 4.7.0 → 4.10.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.
@@ -246,6 +246,7 @@ export class IOCore extends EventEmitter {
246
246
  stop() {
247
247
  this.autoReconnect = false;
248
248
  this.close();
249
+ this.cid = ''
249
250
  this.stateChange('stop','stop');
250
251
  }
251
252
 
@@ -460,7 +461,7 @@ export class IOCore extends EventEmitter {
460
461
 
461
462
  // **IMPORTANT** change state before subscribe.
462
463
  this.stateChange('ready', 'cid_ready')
463
- this.subscribe_memory_channels() // tags registered by listen() or link().
464
+ this.subscribe_channels()
464
465
  break;
465
466
 
466
467
  case IOMsg.QUOTA_LEVEL:
@@ -567,7 +568,7 @@ export class IOCore extends EventEmitter {
567
568
  }
568
569
  let oneString = decoder.decode(payloadStringWithoutNull)
569
570
  if (tag.indexOf('@') === 0) this.emit('@', tag, oneString)
570
- if (tag !== '@') {
571
+ else {
571
572
  this.emit(tag, tag, oneString)
572
573
  this.emit('message', tag, oneString)
573
574
  }
@@ -575,7 +576,7 @@ export class IOCore extends EventEmitter {
575
576
 
576
577
  case PAYLOAD_TYPE.BINARY:
577
578
  if (tag.indexOf('@') === 0) this.emit('@', tag, payloadBuffer)
578
- if (tag !== '@') {
579
+ else {
579
580
  this.emit(tag, tag, payloadBuffer)
580
581
  this.emit('message', tag, payloadBuffer)
581
582
  }
@@ -585,7 +586,7 @@ export class IOCore extends EventEmitter {
585
586
  let oneObjectBuffer = decoder.decode(payloadBuffer)
586
587
  let oneJSONObject = JSON.parse(oneObjectBuffer)
587
588
  if (tag.indexOf('@') === 0) this.emit('@', tag, oneJSONObject)
588
- if (tag !== '@') {
589
+ else {
589
590
  this.emit(tag, tag, oneJSONObject)
590
591
  this.emit('message', tag, oneJSONObject)
591
592
  }
@@ -595,7 +596,7 @@ export class IOCore extends EventEmitter {
595
596
  let mjsonBuffer = decoder.decode(payloadBuffer)
596
597
  let mjson = JSON.parse(mjsonBuffer)
597
598
  if (tag.indexOf('@') === 0) this.emit('@', tag, ...mjson)
598
- if (tag !== '@') {
599
+ else {
599
600
  this.emit(tag, tag, ...mjson)
600
601
  this.emit('message', tag, ...mjson)
601
602
  }
@@ -604,7 +605,7 @@ export class IOCore extends EventEmitter {
604
605
  case PAYLOAD_TYPE.MBA:
605
606
  let mbaObject = MBP.unpack(payloadBuffer)
606
607
  if (tag.indexOf('@') === 0) this.emit('@', tag, ...mbaObject.args)
607
- if (tag !== '@') {
608
+ else {
608
609
  this.emit(tag, tag, ...mbaObject.args)
609
610
  this.emit('message', tag, ...mbaObject.args)
610
611
  }
@@ -732,6 +733,7 @@ export class IOCore extends EventEmitter {
732
733
  console.log('## your maximum signalSize(bytes) is:', this.quota.signalSize)
733
734
  return
734
735
  }
736
+ // console.log(`C->[${IOMsg[ data[0]]}]`)
735
737
  this.socket_send(data);
736
738
  }
737
739
 
@@ -958,14 +960,6 @@ export class IOCore extends EventEmitter {
958
960
  subscribe(tag) {
959
961
  if (typeof tag !== 'string') throw TypeError('tag should be string.')
960
962
  if (tag.length > SIZE_LIMIT.TAG_LEN1) throw TypeError('please check tag string length limit:' + SIZE_LIMIT.TAG_LEN1)
961
- if (this.state !== STATE.READY) return
962
-
963
- // subscribe 사용시, 사용 'ready' 이벤트시 메뉴얼 등록되므로 여기에 등록하면 2중 호출된다.
964
- // 즉, channels 등록은 listen 같은 자동화 구독시만 사용.
965
- // let tagList = tag.split(',')
966
- // tagList.forEach(tag => {
967
- // this.channels.add(tag)
968
- // })
969
963
 
970
964
  try {
971
965
  let tagEncoded = encoder.encode(tag)
@@ -975,47 +969,27 @@ export class IOCore extends EventEmitter {
975
969
  MBP.NB('8', tagEncoded.byteLength),
976
970
  tagEncoded]))
977
971
  } catch (error) { }
972
+
978
973
  }
979
974
 
975
+
980
976
  /**
981
- * Subscribes to a channel or channels with a promise.
982
- * @param {string} tag - The tag(s) of the channel(s) to subscribe to (comma-separated).
983
- * @returns {Promise<any>}
984
- * @throws {TypeError} If tag is not a string or exceeds length limit.
977
+ * Subscribes stored channels.
978
+ * called client state become 'ready'
985
979
  */
986
- subscribe_promise(tag) {
987
- if (typeof tag !== 'string') throw TypeError('tag should be string.')
988
- if (tag.length > SIZE_LIMIT.TAG_LEN2) throw TypeError('please check tag string length limit:' + SIZE_LIMIT.TAG_LEN2)
989
-
990
- if (this.state !== STATE.READY) {
991
- return Promise.reject('subscribe_promise:: connection is not ready')
992
- }
980
+ subscribe_channels() {
981
+ if (this.state !== STATE.READY) return
982
+ if (this.channels.size == 0) return
983
+ let tag = Array.from(this.channels).join(',')
993
984
 
994
985
  try {
995
986
  let tagEncoded = encoder.encode(tag)
996
987
  this.send_enc_mode(
997
988
  Buffer.concat([
998
- MBP.NB('8', IOMsg.SUBSCRIBE_REQ),
999
- MBP.NB('16', ++this.mid),
1000
- MBP.NB('16', tagEncoded.byteLength),
989
+ MBP.NB('8', IOMsg.SUBSCRIBE),
990
+ MBP.NB('8', tagEncoded.byteLength),
1001
991
  tagEncoded]))
1002
- return this.setMsgPromise(this.mid)
1003
992
  } catch (error) { }
1004
- }
1005
-
1006
- /**
1007
- * Subscribes to channels stored in memory (local cache).
1008
- */
1009
- subscribe_memory_channels() { //local cache . auto_resubscribe
1010
- if (this.channels.size == 0) return
1011
- let chList = Array.from(this.channels).join(',')
1012
-
1013
- this.subscribe_promise(chList)
1014
- .then((res) => {
1015
- // console.log('>> SUBSCRIBE_REQ result', res ) // return code == map.size
1016
- }).catch((e) => {
1017
- console.log('>> SUBSCRIBE FAIL:', e)
1018
- })
1019
993
 
1020
994
  }
1021
995
 
@@ -187,6 +187,7 @@ export class Remote extends RemoteCore {
187
187
 
188
188
  // node.js server side remote.
189
189
  send(message, isBinary) {
190
+ // console.log(`<-S [${IOMsg[ message[0]]}]`)
190
191
  this.manager.txBytes += message.byteLength;
191
192
  this.socket.txCounter++;
192
193
  if (this.socketType === 'websocket') {
@@ -149,7 +149,7 @@ export class Server extends EventEmitter {
149
149
 
150
150
  // Service TYPE 1. single call() function.
151
151
  if ( service_module.call && typeof service_module.call == 'function' ) {
152
- this.on(target, async (remote, req) => {
152
+ this.on(target, (remote, req) => {
153
153
  try {
154
154
  if (!service_module.checkPermission(remote, req)) {
155
155
  remote.response(req.mid, STATUS.ERROR, "NO_PERMISSION.")
@@ -157,7 +157,7 @@ export class Server extends EventEmitter {
157
157
  }
158
158
  if( service_module.commands.includes( req.topic )){
159
159
  // console.log('server service_module req', req )
160
- await service_module.call(remote, req)
160
+ service_module.call(remote, req)
161
161
  }else{
162
162
  remote.response(req.mid, STATUS.ERROR, "UNKNOWN_COMMAND");
163
163
  }
@@ -168,14 +168,14 @@ export class Server extends EventEmitter {
168
168
  })
169
169
  } else {
170
170
  // Service TYPE 2. multiple functions.
171
- this.on(target, async (remote, req) => {
171
+ this.on(target, (remote, req) => {
172
172
  try {
173
173
  if (!service_module.checkPermission(remote, req)) {
174
174
  remote.response(req.mid, STATUS.ERROR, "NO_PERMISSION.")
175
175
  return
176
176
  }
177
177
  if( service_module.commands.includes( req.topic )){
178
- await service_module[req.topic](remote, req)
178
+ service_module[req.topic](remote, req)
179
179
  }else{
180
180
  remote.response(req.mid, STATUS.ERROR, "UNKNOWN_COMMAND");
181
181
  }
@@ -47,9 +47,8 @@ export let serverOption = {
47
47
  },
48
48
 
49
49
  auth: {
50
- delay_auth_fail: 600,
50
+ delay_auth_fail: 600
51
51
  },
52
-
53
52
  membersOnly: false
54
53
 
55
54
  }