iosignal 4.6.1 → 4.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.
- package/.vscode/settings.json +1 -1
- package/README.md +33 -7
- package/dist/io.d.ts +4 -4
- package/dist/io.js +3 -3
- package/dist/io.js.map +1 -1
- package/dist/io.min.js +3 -3
- package/dist/io.min.js.map +1 -1
- package/dist/iosignal.js +61 -71
- package/dist/types/client/IOCore.d.ts +4 -4
- package/dist/types/common/constants.d.ts +2 -12
- package/index.js +4 -4
- package/package.json +1 -1
- package/src/auth/key_providers/RedisKeyProvider.js +2 -2
- package/src/client/IOCore.js +8 -8
- package/src/common/constants.js +5 -15
- package/src/server/Manager.js +1 -1
- package/src/server/RemoteCore.js +3 -3
- package/src/server/Server.js +27 -27
- package/src/{api/RedisAPI.js → services/RedisService.js} +6 -6
- package/src/{api/api_reply.js → services/replyService.js} +5 -5
- package/src/{api/api_sudo.js → services/sudoService.js} +3 -3
- package/tsconfig.json +1 -1
- /package/src/{api/api_constant.js → services/constant.js} +0 -0
package/dist/iosignal.js
CHANGED
|
@@ -13,7 +13,7 @@ import require$$2, { networkInterfaces } from 'os';
|
|
|
13
13
|
import require$$0$1 from 'buffer';
|
|
14
14
|
import { memoryUsage } from 'process';
|
|
15
15
|
|
|
16
|
-
var version$1 = "4.
|
|
16
|
+
var version$1 = "4.7.0";
|
|
17
17
|
var pkg = {
|
|
18
18
|
version: version$1};
|
|
19
19
|
|
|
@@ -497,7 +497,7 @@ for (let c in PAYLOAD_TYPE) { PAYLOAD_TYPE[PAYLOAD_TYPE[c]] = c; }
|
|
|
497
497
|
* @property {number} SET
|
|
498
498
|
* @property {number} RESPONSE_CODE
|
|
499
499
|
* @property {number} RESPONSE_MBP
|
|
500
|
-
* @property {number}
|
|
500
|
+
* @property {number} CALL
|
|
501
501
|
* @property {number} RESPONSE
|
|
502
502
|
* @property {number} FLOW_MODE
|
|
503
503
|
* @property {number} WAIT
|
|
@@ -562,11 +562,10 @@ let IOMsg = {
|
|
|
562
562
|
|
|
563
563
|
//..
|
|
564
564
|
SET: 0xDB, //
|
|
565
|
-
RESPONSE_CODE: 0xDC,
|
|
565
|
+
// RESPONSE_CODE: 0xDC,
|
|
566
566
|
RESPONSE_MBP: 0xDD,
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
RESPONSE: 0xDF,
|
|
567
|
+
CALL: 0xDE, // rpc call
|
|
568
|
+
// RESPONSE: 0xDF,
|
|
570
569
|
// ~DF
|
|
571
570
|
|
|
572
571
|
|
|
@@ -584,22 +583,13 @@ let IOMsg = {
|
|
|
584
583
|
for (let c in IOMsg) { IOMsg[IOMsg[c]] = c; }
|
|
585
584
|
// console.log( IOMsg );
|
|
586
585
|
|
|
587
|
-
/**
|
|
588
|
-
* @typedef {object} API_TYPE
|
|
589
|
-
* @property {string} REQUEST_RESPONSE
|
|
590
|
-
* @property {string} ONE_WAY
|
|
591
|
-
*/
|
|
592
|
-
const API_TYPE = {
|
|
593
|
-
'REQUEST_RESPONSE': 'requet_response',
|
|
594
|
-
'ONE_WAY': 'one_way'
|
|
595
|
-
};
|
|
596
586
|
|
|
597
587
|
/**
|
|
598
588
|
* @typedef {object} STATUS
|
|
599
589
|
* @property {number} OK
|
|
600
590
|
* @property {number} ERROR
|
|
601
591
|
*/
|
|
602
|
-
//
|
|
592
|
+
// service response status code
|
|
603
593
|
const STATUS$1 = {
|
|
604
594
|
OK: 0,
|
|
605
595
|
//0~127: success
|
|
@@ -1662,7 +1652,7 @@ class IOCore extends EventEmitter {
|
|
|
1662
1652
|
if (!storeName || args.length == 0) {
|
|
1663
1653
|
return Promise.reject(new Error('set need storeName and value)'))
|
|
1664
1654
|
}
|
|
1665
|
-
return this.
|
|
1655
|
+
return this.call('store', 'set', storeName, ...args)
|
|
1666
1656
|
}
|
|
1667
1657
|
|
|
1668
1658
|
/**
|
|
@@ -1674,26 +1664,26 @@ class IOCore extends EventEmitter {
|
|
|
1674
1664
|
if (!storeName) {
|
|
1675
1665
|
return Promise.reject(new Error('store get need storeName)'))
|
|
1676
1666
|
}
|
|
1677
|
-
let pack = await this.
|
|
1667
|
+
let pack = await this.call('store', 'get', storeName);
|
|
1678
1668
|
let { $ } = M$1.unpack(pack.body);
|
|
1679
1669
|
return $
|
|
1680
1670
|
}
|
|
1681
1671
|
|
|
1682
1672
|
|
|
1683
1673
|
/**
|
|
1684
|
-
* Sends a request to a target and topic.(remote
|
|
1685
|
-
* @param {string} target - The target(
|
|
1686
|
-
* @param {string} topic - The topic(
|
|
1674
|
+
* Sends a request to a target and topic.(remote service call)
|
|
1675
|
+
* @param {string} target - The target(service name) of the request.
|
|
1676
|
+
* @param {string} topic - The topic(service function name) of the request.
|
|
1687
1677
|
* @param {...any} args - Optional arguments for the request.
|
|
1688
1678
|
* @returns {Promise<any>}
|
|
1689
1679
|
*/
|
|
1690
|
-
|
|
1680
|
+
call(target, topic, ...args) {
|
|
1691
1681
|
if (!target || !topic)
|
|
1692
1682
|
return Promise.reject(new Error('request need target and topic)'))
|
|
1693
1683
|
let sigPack;
|
|
1694
1684
|
if (args.length > 0) {
|
|
1695
1685
|
sigPack = M$1.pack(
|
|
1696
|
-
M$1.MB('#MsgType', '8', IOMsg.
|
|
1686
|
+
M$1.MB('#MsgType', '8', IOMsg.CALL),
|
|
1697
1687
|
M$1.MB('mid', '16', ++this.mid),
|
|
1698
1688
|
M$1.MB('target', target),
|
|
1699
1689
|
M$1.MB('topic', topic),
|
|
@@ -1701,7 +1691,7 @@ class IOCore extends EventEmitter {
|
|
|
1701
1691
|
);
|
|
1702
1692
|
} else {
|
|
1703
1693
|
sigPack = M$1.pack(
|
|
1704
|
-
M$1.MB('#MsgType', '8', IOMsg.
|
|
1694
|
+
M$1.MB('#MsgType', '8', IOMsg.CALL),
|
|
1705
1695
|
M$1.MB('mid', '16', ++this.mid),
|
|
1706
1696
|
M$1.MB('target', target),
|
|
1707
1697
|
M$1.MB('topic', topic)
|
|
@@ -7938,15 +7928,15 @@ class RemoteCore {
|
|
|
7938
7928
|
break;
|
|
7939
7929
|
|
|
7940
7930
|
|
|
7941
|
-
case IOMsg.
|
|
7931
|
+
case IOMsg.CALL: //service request
|
|
7942
7932
|
try {
|
|
7943
7933
|
let req = M$1.unpack(message);
|
|
7944
7934
|
if (req) {
|
|
7945
7935
|
if (!req.target || !req.topic) return
|
|
7946
|
-
if (this.manager.server.
|
|
7936
|
+
if (this.manager.server.serviceNames.has(req.target)) {
|
|
7947
7937
|
this.manager.server.emit(req.target, this, req);
|
|
7948
7938
|
} else {
|
|
7949
|
-
// console.log('UnKnown
|
|
7939
|
+
// console.log('UnKnown Service call: ', req.target)
|
|
7950
7940
|
}
|
|
7951
7941
|
}
|
|
7952
7942
|
} catch (e) {
|
|
@@ -8657,7 +8647,7 @@ class Manager {
|
|
|
8657
8647
|
}
|
|
8658
8648
|
|
|
8659
8649
|
|
|
8660
|
-
if (remote.uid && this.server.
|
|
8650
|
+
if (remote.uid && this.server.serviceNames.has('account')) {
|
|
8661
8651
|
let req = { topic: 'detachUserRemote' };
|
|
8662
8652
|
req.args = ['caller:manager.removeRemote'];
|
|
8663
8653
|
this.server.emit('account', remote, req);
|
|
@@ -8989,7 +8979,7 @@ class Server extends require$$0$3 {
|
|
|
8989
8979
|
|
|
8990
8980
|
constructor(options, authManager) {
|
|
8991
8981
|
super();
|
|
8992
|
-
this.
|
|
8982
|
+
this.serviceNames = new Set();
|
|
8993
8983
|
this.wss = {};
|
|
8994
8984
|
this.port = null;
|
|
8995
8985
|
this.congPort = null;
|
|
@@ -9110,63 +9100,63 @@ class Server extends require$$0$3 {
|
|
|
9110
9100
|
}
|
|
9111
9101
|
|
|
9112
9102
|
/**
|
|
9113
|
-
*
|
|
9114
|
-
* target:
|
|
9115
|
-
*
|
|
9103
|
+
* RPC service register.
|
|
9104
|
+
* target: service_name <string>
|
|
9105
|
+
* service: service_module <function module|class instance>
|
|
9116
9106
|
* return this
|
|
9117
9107
|
*/
|
|
9118
|
-
|
|
9108
|
+
attach(target, service_module) {
|
|
9119
9109
|
|
|
9120
9110
|
if( typeof target !== 'string'){
|
|
9121
|
-
throw new Error(`
|
|
9111
|
+
throw new Error(`service( target ,service ) target name is not a string.`)
|
|
9122
9112
|
}
|
|
9123
|
-
if (!
|
|
9124
|
-
throw new Error(`
|
|
9113
|
+
if (!service_module.checkPermission || typeof service_module.checkPermission != 'function') {
|
|
9114
|
+
throw new Error(`Service ${target} : no checkPermission or not a function.`)
|
|
9125
9115
|
}
|
|
9126
|
-
if(!
|
|
9127
|
-
throw new Error(`
|
|
9116
|
+
if(!service_module.commands || !Array.isArray(service_module.commands) ){
|
|
9117
|
+
throw new Error(`Service ${target} : no commands or !Array.`)
|
|
9128
9118
|
}
|
|
9129
9119
|
|
|
9130
|
-
//
|
|
9131
|
-
if (
|
|
9120
|
+
// Service TYPE 1. single call() function.
|
|
9121
|
+
if ( service_module.call && typeof service_module.call == 'function' ) {
|
|
9132
9122
|
this.on(target, async (remote, req) => {
|
|
9133
9123
|
try {
|
|
9134
|
-
if (!
|
|
9124
|
+
if (!service_module.checkPermission(remote, req)) {
|
|
9135
9125
|
remote.response(req.mid, STATUS.ERROR, "NO_PERMISSION.");
|
|
9136
9126
|
return
|
|
9137
9127
|
}
|
|
9138
|
-
if(
|
|
9139
|
-
// console.log('server
|
|
9140
|
-
await
|
|
9128
|
+
if( service_module.commands.includes( req.topic )){
|
|
9129
|
+
// console.log('server service_module req', req )
|
|
9130
|
+
await service_module.call(remote, req);
|
|
9141
9131
|
}else {
|
|
9142
9132
|
remote.response(req.mid, STATUS.ERROR, "UNKNOWN_COMMAND");
|
|
9143
9133
|
}
|
|
9144
9134
|
} catch (error) {
|
|
9145
|
-
console.error(`Unhandled
|
|
9135
|
+
console.error(`Unhandled Service Error in target [${target}]:`, error);
|
|
9146
9136
|
remote.response(req.mid, STATUS.ERROR, "INTERNAL_SERVER_ERROR");
|
|
9147
9137
|
}
|
|
9148
9138
|
});
|
|
9149
9139
|
} else {
|
|
9150
|
-
//
|
|
9140
|
+
// Service TYPE 2. multiple functions.
|
|
9151
9141
|
this.on(target, async (remote, req) => {
|
|
9152
9142
|
try {
|
|
9153
|
-
if (!
|
|
9143
|
+
if (!service_module.checkPermission(remote, req)) {
|
|
9154
9144
|
remote.response(req.mid, STATUS.ERROR, "NO_PERMISSION.");
|
|
9155
9145
|
return
|
|
9156
9146
|
}
|
|
9157
|
-
if(
|
|
9158
|
-
await
|
|
9147
|
+
if( service_module.commands.includes( req.topic )){
|
|
9148
|
+
await service_module[req.topic](remote, req);
|
|
9159
9149
|
}else {
|
|
9160
9150
|
remote.response(req.mid, STATUS.ERROR, "UNKNOWN_COMMAND");
|
|
9161
9151
|
}
|
|
9162
9152
|
} catch (error) {
|
|
9163
|
-
console.error(`Unhandled
|
|
9153
|
+
console.error(`Unhandled Service Error in target [${target}]:`, error);
|
|
9164
9154
|
remote.response(req.mid, STATUS.ERROR, "INTERNAL_SERVER_ERROR");
|
|
9165
9155
|
}
|
|
9166
9156
|
});
|
|
9167
9157
|
}
|
|
9168
|
-
this.
|
|
9169
|
-
// console.log(`[
|
|
9158
|
+
this.serviceNames.add(target);
|
|
9159
|
+
// console.log(`[Service attached: ${target} ] accept commands: ${service_module.commands}`)
|
|
9170
9160
|
return this
|
|
9171
9161
|
}
|
|
9172
9162
|
|
|
@@ -9176,8 +9166,8 @@ class Server extends require$$0$3 {
|
|
|
9176
9166
|
this.manager.close();
|
|
9177
9167
|
}
|
|
9178
9168
|
|
|
9179
|
-
this.
|
|
9180
|
-
this.
|
|
9169
|
+
this.serviceNames.forEach(v => this.removeAllListeners(v));
|
|
9170
|
+
this.serviceNames.clear();
|
|
9181
9171
|
|
|
9182
9172
|
let serverCount = 0;
|
|
9183
9173
|
if (this.wss) serverCount++;
|
|
@@ -9486,7 +9476,7 @@ class RedisKeyProvider {
|
|
|
9486
9476
|
}
|
|
9487
9477
|
}
|
|
9488
9478
|
|
|
9489
|
-
//
|
|
9479
|
+
//sudoService call
|
|
9490
9480
|
async getAuthIdList() {
|
|
9491
9481
|
let result = await this.redis.keys(DEVICE_PREFIX + '*');
|
|
9492
9482
|
result = result.map(v => {
|
|
@@ -9501,7 +9491,7 @@ class RedisKeyProvider {
|
|
|
9501
9491
|
return this.redis.hSet(DEVICE_PREFIX + id, { 'key': Base64hashKey, 'cid': cid, 'level': level })
|
|
9502
9492
|
}
|
|
9503
9493
|
|
|
9504
|
-
//
|
|
9494
|
+
//sudoService call
|
|
9505
9495
|
async delAuth(id) {
|
|
9506
9496
|
return this.redis.del(DEVICE_PREFIX + id)
|
|
9507
9497
|
}
|
|
@@ -9573,7 +9563,7 @@ function checkPermission$1(remote) {
|
|
|
9573
9563
|
}
|
|
9574
9564
|
|
|
9575
9565
|
/**
|
|
9576
|
-
* client api call example: await io.
|
|
9566
|
+
* client api call example: await io.call('reply','echo','hello')
|
|
9577
9567
|
*/
|
|
9578
9568
|
async function echo(remote, req) {
|
|
9579
9569
|
if (!req.args)
|
|
@@ -9583,7 +9573,7 @@ async function echo(remote, req) {
|
|
|
9583
9573
|
}
|
|
9584
9574
|
|
|
9585
9575
|
/**
|
|
9586
|
-
* client api call example: await io.
|
|
9576
|
+
* client api call example: await io.call('reply','date')
|
|
9587
9577
|
*/
|
|
9588
9578
|
async function date(remote, req) {
|
|
9589
9579
|
let r = new Date().toUTCString();
|
|
@@ -9591,14 +9581,14 @@ async function date(remote, req) {
|
|
|
9591
9581
|
}
|
|
9592
9582
|
|
|
9593
9583
|
/**
|
|
9594
|
-
* client api call example: await io.
|
|
9584
|
+
* client api call example: await io.call('reply','unixtime')
|
|
9595
9585
|
*/
|
|
9596
9586
|
async function unixtime(remote, req) {
|
|
9597
9587
|
let r = Math.floor(Date.now() / 1000);
|
|
9598
9588
|
remote.response(req.mid, STATUS.OK, r);
|
|
9599
9589
|
}
|
|
9600
9590
|
|
|
9601
|
-
var
|
|
9591
|
+
var replyService = /*#__PURE__*/Object.freeze({
|
|
9602
9592
|
__proto__: null,
|
|
9603
9593
|
checkPermission: checkPermission$1,
|
|
9604
9594
|
commands: commands$1,
|
|
@@ -9621,7 +9611,7 @@ function checkPermission(remote) {
|
|
|
9621
9611
|
return (remote.level >= MIN_LEVEL$1) ? true : false;
|
|
9622
9612
|
}
|
|
9623
9613
|
|
|
9624
|
-
async function
|
|
9614
|
+
async function call(remote, req) {
|
|
9625
9615
|
let result;
|
|
9626
9616
|
let status = 0;
|
|
9627
9617
|
try {
|
|
@@ -9677,7 +9667,7 @@ async function request(remote, req) {
|
|
|
9677
9667
|
}
|
|
9678
9668
|
} else {
|
|
9679
9669
|
status = STATUS.ERROR;
|
|
9680
|
-
result = "
|
|
9670
|
+
result = "service sudo: no such a cmd: " + cmd;
|
|
9681
9671
|
}
|
|
9682
9672
|
|
|
9683
9673
|
remote.response(req.mid, status, result);
|
|
@@ -9688,21 +9678,21 @@ async function request(remote, req) {
|
|
|
9688
9678
|
|
|
9689
9679
|
}
|
|
9690
9680
|
|
|
9691
|
-
var
|
|
9681
|
+
var sudoService = /*#__PURE__*/Object.freeze({
|
|
9692
9682
|
__proto__: null,
|
|
9683
|
+
call: call,
|
|
9693
9684
|
checkPermission: checkPermission,
|
|
9694
|
-
commands: commands
|
|
9695
|
-
request: request
|
|
9685
|
+
commands: commands
|
|
9696
9686
|
});
|
|
9697
9687
|
|
|
9698
9688
|
/**
|
|
9699
|
-
*
|
|
9689
|
+
* RedisService <IOSignal RPC Service>
|
|
9700
9690
|
*
|
|
9701
9691
|
* iosignal 클라이언트의 redis 질의 요청을 받으면,
|
|
9702
9692
|
* redisClient 로 연결된 redis-server 에게 질의 후 결과를 되돌려 준다.
|
|
9703
9693
|
*
|
|
9704
9694
|
* client ex:
|
|
9705
|
-
* await io.
|
|
9695
|
+
* await io.call('redis','hget','user:id' )
|
|
9706
9696
|
*
|
|
9707
9697
|
*/
|
|
9708
9698
|
|
|
@@ -9714,10 +9704,10 @@ const COMMANDS = [
|
|
|
9714
9704
|
'sMembers', 'exists', 'sRem', 'del', 'keys', 'save'
|
|
9715
9705
|
];
|
|
9716
9706
|
|
|
9717
|
-
class
|
|
9707
|
+
class RedisService {
|
|
9718
9708
|
constructor(redisClient, _minLevel) {
|
|
9719
9709
|
if (!redisClient) {
|
|
9720
|
-
throw new Error("
|
|
9710
|
+
throw new Error("RedisService constructor: no redisClient")
|
|
9721
9711
|
}
|
|
9722
9712
|
this.redisClient = redisClient;
|
|
9723
9713
|
this.minLevel = _minLevel ? _minLevel : MIN_LEVEL;
|
|
@@ -9728,7 +9718,7 @@ class RedisAPI {
|
|
|
9728
9718
|
return (remote.level >= this.minLevel) ? true : false;
|
|
9729
9719
|
}
|
|
9730
9720
|
|
|
9731
|
-
async
|
|
9721
|
+
async call(remote, req) {
|
|
9732
9722
|
let result;
|
|
9733
9723
|
try {
|
|
9734
9724
|
let cmd = req.topic;
|
|
@@ -9747,4 +9737,4 @@ class RedisAPI {
|
|
|
9747
9737
|
|
|
9748
9738
|
const version = pkg.version;
|
|
9749
9739
|
|
|
9750
|
-
export {
|
|
9740
|
+
export { tt as Boho, BohoAuth, CongRx, ENC_MODE, FileKeyProvider, FileLogger, IOWS as IO, IOCongSocket, IOMsg, M$1 as MBP, PAYLOAD_TYPE, RedisKeyProvider, RedisService, SIZE_LIMIT, STATE, STATUS$1 as STATUS, Server, StringKeyProvider, delay, getIPv4HexString, getLocalAddress, getPayloadFromSignalPack, getSignalPack, isPrivateIP, numberWithCommas, pack, parsePayload, replyService, serverOption, sudoService, version };
|
|
@@ -304,13 +304,13 @@ export class IOCore extends EventEmitter<string | symbol, any> {
|
|
|
304
304
|
*/
|
|
305
305
|
get(storeName: string): Promise<any>;
|
|
306
306
|
/**
|
|
307
|
-
* Sends a request to a target and topic.(remote
|
|
308
|
-
* @param {string} target - The target(
|
|
309
|
-
* @param {string} topic - The topic(
|
|
307
|
+
* Sends a request to a target and topic.(remote service call)
|
|
308
|
+
* @param {string} target - The target(service name) of the request.
|
|
309
|
+
* @param {string} topic - The topic(service function name) of the request.
|
|
310
310
|
* @param {...any} args - Optional arguments for the request.
|
|
311
311
|
* @returns {Promise<any>}
|
|
312
312
|
*/
|
|
313
|
-
|
|
313
|
+
call(target: string, topic: string, ...args: any[]): Promise<any>;
|
|
314
314
|
/**
|
|
315
315
|
* Subscribes to a channel or channels.
|
|
316
316
|
* @param {string} tag - The tag(s) of the channel(s) to subscribe to (comma-separated).
|
|
@@ -97,7 +97,7 @@ export type IOMsg = {
|
|
|
97
97
|
SET: number;
|
|
98
98
|
RESPONSE_CODE: number;
|
|
99
99
|
RESPONSE_MBP: number;
|
|
100
|
-
|
|
100
|
+
CALL: number;
|
|
101
101
|
RESPONSE: number;
|
|
102
102
|
FLOW_MODE: number;
|
|
103
103
|
WAIT: number;
|
|
@@ -132,10 +132,8 @@ export namespace IOMsg {
|
|
|
132
132
|
export let IAM: number;
|
|
133
133
|
export let IAM_RES: number;
|
|
134
134
|
export let SET: number;
|
|
135
|
-
export let RESPONSE_CODE: number;
|
|
136
135
|
export let RESPONSE_MBP: number;
|
|
137
|
-
export let
|
|
138
|
-
export let RESPONSE: number;
|
|
136
|
+
export let CALL: number;
|
|
139
137
|
export let FLOW_MODE: number;
|
|
140
138
|
export let WAIT: number;
|
|
141
139
|
export let RESUME: number;
|
|
@@ -143,14 +141,6 @@ export namespace IOMsg {
|
|
|
143
141
|
export let OVER_SIZE: number;
|
|
144
142
|
export let OVER_FLOW: number;
|
|
145
143
|
}
|
|
146
|
-
export type API_TYPE = {
|
|
147
|
-
REQUEST_RESPONSE: string;
|
|
148
|
-
ONE_WAY: string;
|
|
149
|
-
};
|
|
150
|
-
export namespace API_TYPE {
|
|
151
|
-
let REQUEST_RESPONSE: string;
|
|
152
|
-
let ONE_WAY: string;
|
|
153
|
-
}
|
|
154
144
|
export type STATUS = {
|
|
155
145
|
OK: number;
|
|
156
146
|
ERROR: number;
|
package/index.js
CHANGED
|
@@ -20,7 +20,7 @@ export { FileKeyProvider } from './src/auth/key_providers/FileKeyProvider.js'
|
|
|
20
20
|
export { RedisKeyProvider } from './src/auth/key_providers/RedisKeyProvider.js'
|
|
21
21
|
export { StringKeyProvider } from './src/auth/key_providers/StringKeyProvider.js'
|
|
22
22
|
|
|
23
|
-
//
|
|
24
|
-
export * as
|
|
25
|
-
export * as
|
|
26
|
-
export {
|
|
23
|
+
// services
|
|
24
|
+
export * as replyService from './src/services/replyService.js'
|
|
25
|
+
export * as sudoService from './src/services/sudoService.js'
|
|
26
|
+
export { RedisService } from './src/services/RedisService.js'
|
package/package.json
CHANGED
|
@@ -20,7 +20,7 @@ export class RedisKeyProvider {
|
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
//
|
|
23
|
+
//sudoService call
|
|
24
24
|
async getAuthIdList() {
|
|
25
25
|
let result = await this.redis.keys(DEVICE_PREFIX + '*')
|
|
26
26
|
result = result.map(v => {
|
|
@@ -35,7 +35,7 @@ export class RedisKeyProvider {
|
|
|
35
35
|
return this.redis.hSet(DEVICE_PREFIX + id, { 'key': Base64hashKey, 'cid': cid, 'level': level })
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
//
|
|
38
|
+
//sudoService call
|
|
39
39
|
async delAuth(id) {
|
|
40
40
|
return this.redis.del(DEVICE_PREFIX + id)
|
|
41
41
|
}
|
package/src/client/IOCore.js
CHANGED
|
@@ -900,7 +900,7 @@ export class IOCore extends EventEmitter {
|
|
|
900
900
|
if (!storeName || args.length == 0) {
|
|
901
901
|
return Promise.reject(new Error('set need storeName and value)'))
|
|
902
902
|
}
|
|
903
|
-
return this.
|
|
903
|
+
return this.call('store', 'set', storeName, ...args)
|
|
904
904
|
}
|
|
905
905
|
|
|
906
906
|
/**
|
|
@@ -912,26 +912,26 @@ export class IOCore extends EventEmitter {
|
|
|
912
912
|
if (!storeName) {
|
|
913
913
|
return Promise.reject(new Error('store get need storeName)'))
|
|
914
914
|
}
|
|
915
|
-
let pack = await this.
|
|
915
|
+
let pack = await this.call('store', 'get', storeName)
|
|
916
916
|
let { $ } = MBP.unpack(pack.body)
|
|
917
917
|
return $
|
|
918
918
|
}
|
|
919
919
|
|
|
920
920
|
|
|
921
921
|
/**
|
|
922
|
-
* Sends a request to a target and topic.(remote
|
|
923
|
-
* @param {string} target - The target(
|
|
924
|
-
* @param {string} topic - The topic(
|
|
922
|
+
* Sends a request to a target and topic.(remote service call)
|
|
923
|
+
* @param {string} target - The target(service name) of the request.
|
|
924
|
+
* @param {string} topic - The topic(service function name) of the request.
|
|
925
925
|
* @param {...any} args - Optional arguments for the request.
|
|
926
926
|
* @returns {Promise<any>}
|
|
927
927
|
*/
|
|
928
|
-
|
|
928
|
+
call(target, topic, ...args) {
|
|
929
929
|
if (!target || !topic)
|
|
930
930
|
return Promise.reject(new Error('request need target and topic)'))
|
|
931
931
|
let sigPack;
|
|
932
932
|
if (args.length > 0) {
|
|
933
933
|
sigPack = MBP.pack(
|
|
934
|
-
MBP.MB('#MsgType', '8', IOMsg.
|
|
934
|
+
MBP.MB('#MsgType', '8', IOMsg.CALL),
|
|
935
935
|
MBP.MB('mid', '16', ++this.mid),
|
|
936
936
|
MBP.MB('target', target),
|
|
937
937
|
MBP.MB('topic', topic),
|
|
@@ -939,7 +939,7 @@ export class IOCore extends EventEmitter {
|
|
|
939
939
|
)
|
|
940
940
|
} else {
|
|
941
941
|
sigPack = MBP.pack(
|
|
942
|
-
MBP.MB('#MsgType', '8', IOMsg.
|
|
942
|
+
MBP.MB('#MsgType', '8', IOMsg.CALL),
|
|
943
943
|
MBP.MB('mid', '16', ++this.mid),
|
|
944
944
|
MBP.MB('target', target),
|
|
945
945
|
MBP.MB('topic', topic)
|
package/src/common/constants.js
CHANGED
|
@@ -116,7 +116,7 @@ for (let c in PAYLOAD_TYPE) { PAYLOAD_TYPE[PAYLOAD_TYPE[c]] = c }
|
|
|
116
116
|
* @property {number} SET
|
|
117
117
|
* @property {number} RESPONSE_CODE
|
|
118
118
|
* @property {number} RESPONSE_MBP
|
|
119
|
-
* @property {number}
|
|
119
|
+
* @property {number} CALL
|
|
120
120
|
* @property {number} RESPONSE
|
|
121
121
|
* @property {number} FLOW_MODE
|
|
122
122
|
* @property {number} WAIT
|
|
@@ -181,11 +181,10 @@ export let IOMsg = {
|
|
|
181
181
|
|
|
182
182
|
//..
|
|
183
183
|
SET: 0xDB, //
|
|
184
|
-
RESPONSE_CODE: 0xDC,
|
|
184
|
+
// RESPONSE_CODE: 0xDC,
|
|
185
185
|
RESPONSE_MBP: 0xDD,
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
RESPONSE: 0xDF,
|
|
186
|
+
CALL: 0xDE, // rpc call
|
|
187
|
+
// RESPONSE: 0xDF,
|
|
189
188
|
// ~DF
|
|
190
189
|
|
|
191
190
|
|
|
@@ -203,22 +202,13 @@ export let IOMsg = {
|
|
|
203
202
|
for (let c in IOMsg) { IOMsg[IOMsg[c]] = c }
|
|
204
203
|
// console.log( IOMsg );
|
|
205
204
|
|
|
206
|
-
/**
|
|
207
|
-
* @typedef {object} API_TYPE
|
|
208
|
-
* @property {string} REQUEST_RESPONSE
|
|
209
|
-
* @property {string} ONE_WAY
|
|
210
|
-
*/
|
|
211
|
-
export const API_TYPE = {
|
|
212
|
-
'REQUEST_RESPONSE': 'requet_response',
|
|
213
|
-
'ONE_WAY': 'one_way'
|
|
214
|
-
}
|
|
215
205
|
|
|
216
206
|
/**
|
|
217
207
|
* @typedef {object} STATUS
|
|
218
208
|
* @property {number} OK
|
|
219
209
|
* @property {number} ERROR
|
|
220
210
|
*/
|
|
221
|
-
//
|
|
211
|
+
// service response status code
|
|
222
212
|
export const STATUS = {
|
|
223
213
|
OK: 0,
|
|
224
214
|
//0~127: success
|
package/src/server/Manager.js
CHANGED
|
@@ -119,7 +119,7 @@ export class Manager {
|
|
|
119
119
|
}
|
|
120
120
|
|
|
121
121
|
|
|
122
|
-
if (remote.uid && this.server.
|
|
122
|
+
if (remote.uid && this.server.serviceNames.has('account')) {
|
|
123
123
|
let req = { topic: 'detachUserRemote' }
|
|
124
124
|
req.args = ['caller:manager.removeRemote']
|
|
125
125
|
this.server.emit('account', remote, req)
|
package/src/server/RemoteCore.js
CHANGED
|
@@ -265,15 +265,15 @@ export class RemoteCore {
|
|
|
265
265
|
break;
|
|
266
266
|
|
|
267
267
|
|
|
268
|
-
case IOMsg.
|
|
268
|
+
case IOMsg.CALL: //service request
|
|
269
269
|
try {
|
|
270
270
|
let req = MBP.unpack(message)
|
|
271
271
|
if (req) {
|
|
272
272
|
if (!req.target || !req.topic) return
|
|
273
|
-
if (this.manager.server.
|
|
273
|
+
if (this.manager.server.serviceNames.has(req.target)) {
|
|
274
274
|
this.manager.server.emit(req.target, this, req)
|
|
275
275
|
} else {
|
|
276
|
-
// console.log('UnKnown
|
|
276
|
+
// console.log('UnKnown Service call: ', req.target)
|
|
277
277
|
}
|
|
278
278
|
}
|
|
279
279
|
} catch (e) {
|