iosignal 4.8.0 → 5.0.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.
@@ -27,7 +27,7 @@ export class RemoteCore {
27
27
  this.ssid = RemoteCore.ssid++; // ordered index number
28
28
  this.manager = manager;
29
29
 
30
- this.cid = ''; // Communication Id
30
+ this.cid = ''; // Client Id
31
31
  this.did = ''; // Device Id
32
32
  this.uid = ''; // User Id
33
33
  this.nick = ''
@@ -50,7 +50,7 @@ export class RemoteCore {
50
50
  this.state = state
51
51
  if (serverOption.debug.showAuthInfo) {
52
52
  this.stateLog.push( state + ":" + STATE[ state] )
53
- if( state == STATE.AUTH_ACK){
53
+ if( state == STATE.AUTH_RES){
54
54
  console.log('[auth success]', this.cid, this.stateLog.join('>'))
55
55
  }else if( state == STATE.AUTH_FAIL){
56
56
  console.log('[auth_fail]',this.stateLog.join('>'))
@@ -291,29 +291,16 @@ export class RemoteCore {
291
291
  break;
292
292
 
293
293
 
294
- // Auth
294
+ // client's auth requst
295
295
  case Boho.BohoMsg.AUTH_REQ:
296
296
  if (!this.manager.authManager) return
297
297
  if (this.state < STATE.SERVER_READY) {
298
- console.log('protocol error. auth_req before server_ready')
298
+ console.log('protocol error. must called auth_req after server_ready')
299
299
  this.close();
300
300
  }
301
301
  this.setState(STATE.AUTH_REQ)
302
- let auth_nonce_pack = this.boho.auth_nonce()
303
- // console.log('## auth_nonce_pack', auth_nonce_pack )
304
- this.send(auth_nonce_pack)
305
- this.setState(STATE.AUTH_NONCE)
306
- break;
307
-
308
- case Boho.BohoMsg.AUTH_HMAC:
309
- if (!this.manager.authManager) return
310
- if (this.state < STATE.AUTH_NONCE) {
311
- console.log('protocol error. auth_hmac before server_nonce')
312
- this.close();
313
- }
314
- this.setState(STATE.AUTH_HMAC)
315
302
  //async
316
- this.manager.authManager.verify_auth_hmac(message, this)
303
+ this.manager.authManager.verify_auth_req(message, this)
317
304
  .then(authInfo => {
318
305
  if (authInfo?.name) {
319
306
  this.manager.deligateSignal(this, '@$name', authInfo.name)
@@ -321,7 +308,7 @@ export class RemoteCore {
321
308
  // this.manager.sender('@$name', authInfo.name )
322
309
  }
323
310
 
324
- // console.log('[VERIFY AUTH_HMAC] SubClass of BohoAuth return authInfo:', authInfo )
311
+ // console.log('[VERIFY AUTH_REQ] SubClass of BohoAuth return authInfo:', authInfo )
325
312
  })
326
313
  .catch(e => {
327
314
  console.log('authInfo return fail.', e )
@@ -131,25 +131,25 @@ export class Server extends EventEmitter {
131
131
 
132
132
  /**
133
133
  * RPC service register.
134
- * target: service_name <string>
135
- * service: service_module <function module|class instance>
134
+ * service: service_name <string>
135
+ * service_module <function module|class instance>
136
136
  * return this
137
137
  */
138
- attach(target, service_module) {
138
+ attach(service, service_module) {
139
139
 
140
- if( typeof target !== 'string'){
141
- throw new Error(`service( target ,service ) target name is not a string.`)
140
+ if( typeof service !== 'string'){
141
+ throw new Error(`attach service name is not a string.`)
142
142
  }
143
143
  if (!service_module.checkPermission || typeof service_module.checkPermission != 'function') {
144
- throw new Error(`Service ${target} : no checkPermission or not a function.`)
144
+ throw new Error(`Service ${service} : no checkPermission or not a function.`)
145
145
  }
146
146
  if(!service_module.commands || !Array.isArray(service_module.commands) ){
147
- throw new Error(`Service ${target} : no commands or !Array.`)
147
+ throw new Error(`Service ${service} : no commands or !Array.`)
148
148
  }
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(service, (remote, req) => {
153
153
  try {
154
154
  if (!service_module.checkPermission(remote, req)) {
155
155
  remote.response(req.mid, STATUS.ERROR, "NO_PERMISSION.")
@@ -157,36 +157,36 @@ 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
  }
164
164
  } catch (error) {
165
- console.error(`Unhandled Service Error in target [${target}]:`, error);
165
+ console.error(`Unhandled Service Error in service [${service}]:`, error);
166
166
  remote.response(req.mid, STATUS.ERROR, "INTERNAL_SERVER_ERROR");
167
167
  }
168
168
  })
169
169
  } else {
170
170
  // Service TYPE 2. multiple functions.
171
- this.on(target, async (remote, req) => {
171
+ this.on(service, (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
  }
182
182
  } catch (error) {
183
- console.error(`Unhandled Service Error in target [${target}]:`, error);
183
+ console.error(`Unhandled Service Error in service [${service}]:`, error);
184
184
  remote.response(req.mid, STATUS.ERROR, "INTERNAL_SERVER_ERROR");
185
185
  }
186
186
  })
187
187
  }
188
- this.serviceNames.add(target)
189
- // console.log(`[Service attached: ${target} ] accept commands: ${service_module.commands}`)
188
+ this.serviceNames.add(service)
189
+ // console.log(`[Service attached: ${service} ] accept commands: ${service_module.commands}`)
190
190
  return this
191
191
  }
192
192
 
@@ -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
  }
@@ -21,18 +21,18 @@ export async function call(remote, req) {
21
21
  let cmd = req.topic;
22
22
  cmd = cmd.toLowerCase()
23
23
  if (cmd == 'cid') {
24
- result = remote.manager.metric.getCIdList()
24
+ result = remote.manager.metrics.getCIdList()
25
25
  } else if (cmd == 'remotes' || cmd == 'clients') {
26
- result = remote.manager.metric.getRemotes()
26
+ result = remote.manager.metrics.getRemotes()
27
27
  } else if (cmd == 'channels') {
28
- result = remote.manager.metric.getChannelList()
28
+ result = remote.manager.metrics.getChannelList()
29
29
  } else if (cmd == 'subscribers') {
30
30
  let ch = req.$[0]
31
- if (ch) result = remote.manager.metric.getSubscribers(ch)
31
+ if (ch) result = remote.manager.metrics.getSubscribers(ch)
32
32
  } else if (cmd == 'remote' || cmd == 'client') {
33
33
  let cid = req.$[0]
34
34
  let mode = req.$[1]
35
- if (cid) result = remote.manager.metric.getRemoteByCId(cid, mode)
35
+ if (cid) result = remote.manager.metrics.getRemoteByCId(cid, mode)
36
36
 
37
37
  } else if (cmd == 'close') {
38
38
  if (req.$[0]) result = remote.manager.closeRemoteByCId(req.$[0])