@bigtyphoon/melo 1.7.6
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/LICENSE +22 -0
- package/README.md +55 -0
- package/bin/commadtest.ts +10 -0
- package/bin/commands/add.ts +43 -0
- package/bin/commands/init.ts +292 -0
- package/bin/commands/kill.ts +21 -0
- package/bin/commands/list.ts +60 -0
- package/bin/commands/masterha.ts +40 -0
- package/bin/commands/restart.ts +48 -0
- package/bin/commands/start.ts +65 -0
- package/bin/commands/stop.ts +26 -0
- package/bin/melo.ts +30 -0
- package/bin/utils/constants.ts +27 -0
- package/bin/utils/utils.ts +130 -0
- package/dist/bin/commadtest.js +9 -0
- package/dist/bin/commands/add.js +40 -0
- package/dist/bin/commands/init.js +279 -0
- package/dist/bin/commands/kill.js +21 -0
- package/dist/bin/commands/list.js +65 -0
- package/dist/bin/commands/masterha.js +36 -0
- package/dist/bin/commands/restart.js +45 -0
- package/dist/bin/commands/start.js +58 -0
- package/dist/bin/commands/stop.js +20 -0
- package/dist/bin/melo.js +26 -0
- package/dist/bin/utils/constants.js +28 -0
- package/dist/bin/utils/utils.js +134 -0
- package/dist/lib/application.js +888 -0
- package/dist/lib/common/manager/appManager.js +112 -0
- package/dist/lib/common/manager/taskManager.js +39 -0
- package/dist/lib/common/remote/backend/msgRemote.js +63 -0
- package/dist/lib/common/remote/frontend/channelRemote.js +78 -0
- package/dist/lib/common/remote/frontend/sessionRemote.js +76 -0
- package/dist/lib/common/service/backendSessionService.js +337 -0
- package/dist/lib/common/service/channelService.js +514 -0
- package/dist/lib/common/service/connectionService.js +95 -0
- package/dist/lib/common/service/filterService.js +112 -0
- package/dist/lib/common/service/handlerService.js +187 -0
- package/dist/lib/common/service/sessionService.js +610 -0
- package/dist/lib/components/backendSession.js +14 -0
- package/dist/lib/components/channel.js +13 -0
- package/dist/lib/components/connection.js +12 -0
- package/dist/lib/components/connector.js +437 -0
- package/dist/lib/components/dictionary.js +93 -0
- package/dist/lib/components/master.js +39 -0
- package/dist/lib/components/monitor.js +25 -0
- package/dist/lib/components/protobuf.js +156 -0
- package/dist/lib/components/proxy.js +236 -0
- package/dist/lib/components/pushScheduler.js +62 -0
- package/dist/lib/components/remote.js +127 -0
- package/dist/lib/components/server.js +63 -0
- package/dist/lib/components/session.js +20 -0
- package/dist/lib/connectors/commands/handshake.js +119 -0
- package/dist/lib/connectors/commands/heartbeat.js +67 -0
- package/dist/lib/connectors/commands/kick.js +15 -0
- package/dist/lib/connectors/common/coder.js +90 -0
- package/dist/lib/connectors/common/handler.js +57 -0
- package/dist/lib/connectors/hybrid/IHybridSocket.js +3 -0
- package/dist/lib/connectors/hybrid/switcher.js +100 -0
- package/dist/lib/connectors/hybrid/tcpprocessor.js +40 -0
- package/dist/lib/connectors/hybrid/tcpsocket.js +171 -0
- package/dist/lib/connectors/hybrid/wsprocessor.js +49 -0
- package/dist/lib/connectors/hybridconnector.js +89 -0
- package/dist/lib/connectors/hybridsocket.js +139 -0
- package/dist/lib/connectors/mqtt/generate.js +113 -0
- package/dist/lib/connectors/mqtt/mqttadaptor.js +81 -0
- package/dist/lib/connectors/mqtt/protocol.js +48 -0
- package/dist/lib/connectors/mqttconnector.js +107 -0
- package/dist/lib/connectors/mqttsocket.js +59 -0
- package/dist/lib/connectors/sioconnector.js +135 -0
- package/dist/lib/connectors/siosocket.js +69 -0
- package/dist/lib/connectors/udpconnector.js +76 -0
- package/dist/lib/connectors/udpsocket.js +93 -0
- package/dist/lib/filters/handler/serial.js +44 -0
- package/dist/lib/filters/handler/time.js +32 -0
- package/dist/lib/filters/handler/timeout.js +45 -0
- package/dist/lib/filters/handler/toobusy.js +36 -0
- package/dist/lib/filters/rpc/rpcLog.js +43 -0
- package/dist/lib/filters/rpc/toobusy.js +41 -0
- package/dist/lib/index.js +81 -0
- package/dist/lib/interfaces/IComponent.js +3 -0
- package/dist/lib/interfaces/IConnector.js +3 -0
- package/dist/lib/interfaces/IHandlerFilter.js +3 -0
- package/dist/lib/interfaces/ILifeCycle.js +3 -0
- package/dist/lib/interfaces/IPlugin.js +3 -0
- package/dist/lib/interfaces/IPushScheduler.js +3 -0
- package/dist/lib/interfaces/ISocket.js +3 -0
- package/dist/lib/interfaces/IStore.js +3 -0
- package/dist/lib/interfaces/define.js +3 -0
- package/dist/lib/master/master.js +129 -0
- package/dist/lib/master/starter.js +236 -0
- package/dist/lib/master/watchdog.js +120 -0
- package/dist/lib/melo.js +125 -0
- package/dist/lib/modules/console.js +436 -0
- package/dist/lib/modules/masterwatcher.js +98 -0
- package/dist/lib/modules/monitorwatcher.js +124 -0
- package/dist/lib/modules/onlineUser.js +69 -0
- package/dist/lib/modules/restartNotifyModule.js +107 -0
- package/dist/lib/modules/watchServer.js +737 -0
- package/dist/lib/monitor/monitor.js +80 -0
- package/dist/lib/pushSchedulers/buffer.js +96 -0
- package/dist/lib/pushSchedulers/direct.js +58 -0
- package/dist/lib/pushSchedulers/multi.js +80 -0
- package/dist/lib/server/server.js +500 -0
- package/dist/lib/util/appUtil.js +306 -0
- package/dist/lib/util/constants.js +117 -0
- package/dist/lib/util/countDownLatch.js +51 -0
- package/dist/lib/util/events.js +20 -0
- package/dist/lib/util/handlerHelper.js +8 -0
- package/dist/lib/util/log.js +14 -0
- package/dist/lib/util/moduleUtil.js +101 -0
- package/dist/lib/util/pathUtil.js +134 -0
- package/dist/lib/util/remoterHelper.js +8 -0
- package/dist/lib/util/utils.js +358 -0
- package/dist/test/application.js +522 -0
- package/dist/test/config/log4js.json +28 -0
- package/dist/test/config/master.json +9 -0
- package/dist/test/config/servers.json +6 -0
- package/dist/test/filters/handler/serial.js +41 -0
- package/dist/test/filters/handler/time.js +41 -0
- package/dist/test/filters/handler/timeout.js +41 -0
- package/dist/test/filters/handler/toobusy.js +57 -0
- package/dist/test/filters/rpc/rpcLog.js +22 -0
- package/dist/test/filters/rpc/toobusy.js +39 -0
- package/dist/test/manager/mockChannelManager.js +77 -0
- package/dist/test/manager/taskManager.js +68 -0
- package/dist/test/mock-base/app/servers/other-file +0 -0
- package/dist/test/mock-plugin/components/mockPlugin.js +10 -0
- package/dist/test/mock-plugin/events/mockEvent.js +12 -0
- package/dist/test/modules/console.js +242 -0
- package/dist/test/pomelo.js +19 -0
- package/dist/test/remote/channelRemote.js +159 -0
- package/dist/test/service/channel.js +134 -0
- package/dist/test/service/channelService.js +216 -0
- package/dist/test/service/connectionService.js +114 -0
- package/dist/test/service/filterService.js +144 -0
- package/dist/test/service/handlerService.js +65 -0
- package/dist/test/service/sessionService.js +387 -0
- package/dist/test/util/countDownLatch.js +70 -0
- package/dist/test/util/pathUtil.js +108 -0
- package/dist/test/util/utils.js +140 -0
- package/lib/application.ts +1240 -0
- package/lib/common/manager/appManager.ts +118 -0
- package/lib/common/manager/taskManager.ts +50 -0
- package/lib/common/remote/backend/msgRemote.ts +134 -0
- package/lib/common/remote/frontend/channelRemote.ts +91 -0
- package/lib/common/remote/frontend/sessionRemote.ts +91 -0
- package/lib/common/service/backendSessionService.ts +388 -0
- package/lib/common/service/channelService.ts +609 -0
- package/lib/common/service/connectionService.ts +112 -0
- package/lib/common/service/filterService.ts +118 -0
- package/lib/common/service/handlerService.ts +224 -0
- package/lib/common/service/sessionService.ts +731 -0
- package/lib/components/backendSession.ts +14 -0
- package/lib/components/channel.ts +11 -0
- package/lib/components/connection.ts +13 -0
- package/lib/components/connector.ts +533 -0
- package/lib/components/dictionary.ts +121 -0
- package/lib/components/master.ts +41 -0
- package/lib/components/monitor.ts +30 -0
- package/lib/components/protobuf.ts +208 -0
- package/lib/components/proxy.ts +282 -0
- package/lib/components/pushScheduler.ts +70 -0
- package/lib/components/remote.ts +166 -0
- package/lib/components/server.ts +71 -0
- package/lib/components/session.ts +22 -0
- package/lib/connectors/commands/handshake.ts +155 -0
- package/lib/connectors/commands/heartbeat.ts +83 -0
- package/lib/connectors/commands/kick.ts +11 -0
- package/lib/connectors/common/coder.ts +93 -0
- package/lib/connectors/common/handler.ts +62 -0
- package/lib/connectors/hybrid/IHybridSocket.ts +9 -0
- package/lib/connectors/hybrid/switcher.ts +142 -0
- package/lib/connectors/hybrid/tcpprocessor.ts +43 -0
- package/lib/connectors/hybrid/tcpsocket.ts +223 -0
- package/lib/connectors/hybrid/wsprocessor.ts +57 -0
- package/lib/connectors/hybridconnector.ts +134 -0
- package/lib/connectors/hybridsocket.ts +168 -0
- package/lib/connectors/mqtt/generate.ts +103 -0
- package/lib/connectors/mqtt/mqttadaptor.ts +114 -0
- package/lib/connectors/mqtt/protocol.ts +49 -0
- package/lib/connectors/mqttconnector.ts +134 -0
- package/lib/connectors/mqttsocket.ts +79 -0
- package/lib/connectors/sioconnector.ts +161 -0
- package/lib/connectors/siosocket.ts +85 -0
- package/lib/connectors/udpconnector.ts +113 -0
- package/lib/connectors/udpsocket.ts +110 -0
- package/lib/filters/handler/serial.ts +46 -0
- package/lib/filters/handler/time.ts +35 -0
- package/lib/filters/handler/timeout.ts +50 -0
- package/lib/filters/handler/toobusy.ts +37 -0
- package/lib/filters/rpc/rpcLog.ts +42 -0
- package/lib/filters/rpc/toobusy.ts +41 -0
- package/lib/index.ts +74 -0
- package/lib/interfaces/IComponent.ts +47 -0
- package/lib/interfaces/IConnector.ts +20 -0
- package/lib/interfaces/IHandlerFilter.ts +15 -0
- package/lib/interfaces/ILifeCycle.ts +16 -0
- package/lib/interfaces/IPlugin.ts +65 -0
- package/lib/interfaces/IPushScheduler.ts +52 -0
- package/lib/interfaces/ISocket.ts +26 -0
- package/lib/interfaces/IStore.ts +10 -0
- package/lib/interfaces/define.ts +15 -0
- package/lib/master/master.ts +148 -0
- package/lib/master/starter.ts +234 -0
- package/lib/master/watchdog.ts +135 -0
- package/lib/melo.ts +152 -0
- package/lib/modules/console.ts +465 -0
- package/lib/modules/masterwatcher.ts +120 -0
- package/lib/modules/monitorwatcher.ts +151 -0
- package/lib/modules/onlineUser.ts +78 -0
- package/lib/modules/restartNotifyModule.ts +128 -0
- package/lib/modules/watchServer.ts +766 -0
- package/lib/monitor/monitor.ts +99 -0
- package/lib/pushSchedulers/buffer.ts +117 -0
- package/lib/pushSchedulers/direct.ts +65 -0
- package/lib/pushSchedulers/multi.ts +94 -0
- package/lib/server/server.ts +554 -0
- package/lib/util/appUtil.ts +313 -0
- package/lib/util/constants.ts +154 -0
- package/lib/util/countDownLatch.ts +72 -0
- package/lib/util/events.ts +15 -0
- package/lib/util/handlerHelper.ts +5 -0
- package/lib/util/log.ts +11 -0
- package/lib/util/moduleUtil.ts +110 -0
- package/lib/util/pathUtil.ts +132 -0
- package/lib/util/remoterHelper.ts +68 -0
- package/lib/util/utils.ts +365 -0
- package/package.json +93 -0
- package/template/game-server/.vscode/launch.json +27 -0
- package/template/game-server/app/servers/connector/handler/entryHandler.ts +50 -0
- package/template/game-server/app/servers/connector/remote/authRemoter.ts +36 -0
- package/template/game-server/app.ts +30 -0
- package/template/game-server/app.ts.mqtt +32 -0
- package/template/game-server/app.ts.sio +36 -0
- package/template/game-server/app.ts.sio.wss +34 -0
- package/template/game-server/app.ts.udp +31 -0
- package/template/game-server/app.ts.wss +40 -0
- package/template/game-server/config/adminServer.json +5 -0
- package/template/game-server/config/adminUser.json +22 -0
- package/template/game-server/config/clientProtos.json +1 -0
- package/template/game-server/config/dictionary.json +1 -0
- package/template/game-server/config/log4js.json +150 -0
- package/template/game-server/config/master.json +8 -0
- package/template/game-server/config/serverProtos.json +1 -0
- package/template/game-server/config/servers.json +12 -0
- package/template/game-server/copy.js +5 -0
- package/template/game-server/package.json +28 -0
- package/template/game-server/preload.ts +40 -0
- package/template/game-server/tsconfig.json +36 -0
- package/template/npm-install.bat +4 -0
- package/template/npm-install.sh +5 -0
- package/template/readme.md +31 -0
- package/template/shared/server.crt +15 -0
- package/template/shared/server.key +15 -0
- package/template/web-server/app.js +25 -0
- package/template/web-server/app.js.https +36 -0
- package/template/web-server/bin/component.bat +1 -0
- package/template/web-server/bin/component.sh +1 -0
- package/template/web-server/package.json +10 -0
- package/template/web-server/public/css/base.css +76 -0
- package/template/web-server/public/image/logo.png +0 -0
- package/template/web-server/public/image/sp.png +0 -0
- package/template/web-server/public/index.html +57 -0
- package/template/web-server/public/index.html.sio +58 -0
- package/template/web-server/public/js/lib/build/build.js +1730 -0
- package/template/web-server/public/js/lib/build/build.js.wss +1721 -0
- package/template/web-server/public/js/lib/component.json +6 -0
- package/template/web-server/public/js/lib/local/boot/component.json +11 -0
- package/template/web-server/public/js/lib/local/boot/index.js +11 -0
- package/template/web-server/public/js/lib/meloclient.js +456 -0
- package/template/web-server/public/js/lib/meloclient.js.wss +456 -0
- package/template/web-server/public/js/lib/socket.io.js +3 -0
- package/test/application.ts +607 -0
- package/test/filters/handler/serial.ts +47 -0
- package/test/filters/handler/time.ts +47 -0
- package/test/filters/handler/timeout.ts +46 -0
- package/test/filters/handler/toobusy.ts +59 -0
- package/test/filters/rpc/rpcLog.ts +20 -0
- package/test/filters/rpc/toobusy.ts +40 -0
- package/test/manager/mockChannelManager.ts +92 -0
- package/test/manager/taskManager.ts +78 -0
- package/test/mock-base/app/servers/other-file +0 -0
- package/test/mock-plugin/components/mockPlugin.ts +8 -0
- package/test/mock-plugin/events/mockEvent.ts +12 -0
- package/test/modules/console.ts +264 -0
- package/test/pomelo.ts +18 -0
- package/test/remote/channelRemote.ts +176 -0
- package/test/service/channel.ts +161 -0
- package/test/service/channelService.ts +243 -0
- package/test/service/connectionService.ts +142 -0
- package/test/service/filterService.ts +165 -0
- package/test/service/handlerService.ts +77 -0
- package/test/service/sessionService.ts +464 -0
- package/test/util/countDownLatch.ts +81 -0
- package/test/util/pathUtil.ts +122 -0
- package/test/util/utils.ts +165 -0
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import * as fs from 'fs';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
import * as Constants from './constants';
|
|
4
|
+
import { RemoteServerCode } from '../index';
|
|
5
|
+
import { DIR } from './constants';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Get relative path
|
|
9
|
+
*
|
|
10
|
+
* @param {String} path full path
|
|
11
|
+
* @return {String} relative path
|
|
12
|
+
*/
|
|
13
|
+
export function getRelativePath(path: string) {
|
|
14
|
+
return path.replace(process.cwd(), '')
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Get system remote service path
|
|
19
|
+
*
|
|
20
|
+
* @param {String} role server role: frontend, backend
|
|
21
|
+
* @return {String} path string if the path exist else null
|
|
22
|
+
*/
|
|
23
|
+
export function getSysRemotePath(role: string) {
|
|
24
|
+
let p = path.join(__dirname, '/../common/remote/', role);
|
|
25
|
+
return fs.existsSync(p) ? p : null;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Get user remote service path
|
|
30
|
+
*
|
|
31
|
+
* @param {String} appBase application base path
|
|
32
|
+
* @param {String} serverType server type
|
|
33
|
+
* @return {String} path string if the path exist else null
|
|
34
|
+
*/
|
|
35
|
+
export function getUserRemotePath(appBase: string, serverType: string) {
|
|
36
|
+
let p = path.join(appBase, '/app/servers/', serverType, Constants.DIR.REMOTE);
|
|
37
|
+
return fs.existsSync(p) ? p : null;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Get user remote cron path
|
|
42
|
+
*
|
|
43
|
+
* @param {String} appBase application base path
|
|
44
|
+
* @param {String} serverType server type
|
|
45
|
+
* @return {String} path string if the path exist else null
|
|
46
|
+
*/
|
|
47
|
+
export function getCronPath(appBase: string, serverType: string) {
|
|
48
|
+
let p = path.join(appBase, '/app/servers/', serverType, Constants.DIR.CRON);
|
|
49
|
+
return fs.existsSync(p) ? p : null;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* List all the subdirectory names of user remote directory
|
|
54
|
+
* which hold the codes for all the server types.
|
|
55
|
+
*
|
|
56
|
+
* @param {String} appBase application base path
|
|
57
|
+
* @return {Array} all the subdiretory name under servers/
|
|
58
|
+
*/
|
|
59
|
+
export function listUserRemoteDir(appBase: string) {
|
|
60
|
+
let base = path.join(appBase, '/app/servers/');
|
|
61
|
+
let files = fs.readdirSync(base);
|
|
62
|
+
return files.filter(function (fn) {
|
|
63
|
+
if (fn.charAt(0) === '.') {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return fs.statSync(path.join(base, fn)).isDirectory();
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Compose remote path record
|
|
73
|
+
*
|
|
74
|
+
* @param {String} namespace remote path namespace, such as: 'sys', 'user'
|
|
75
|
+
* @param {String} serverType
|
|
76
|
+
* @param {String} path remote service source path
|
|
77
|
+
* @param {Boolean} relativePath convert path to relative path
|
|
78
|
+
* @return {Object} remote path record
|
|
79
|
+
*/
|
|
80
|
+
export function remotePathRecord(namespace: string, serverType: string, path: string, relativePath?: boolean): RemoteServerCode {
|
|
81
|
+
if (relativePath) {
|
|
82
|
+
path = getRelativePath(path);
|
|
83
|
+
}
|
|
84
|
+
return { namespace: namespace, serverType: serverType, path: path };
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Get handler path
|
|
89
|
+
*
|
|
90
|
+
* @param {String} appBase application base path
|
|
91
|
+
* @param {String} serverType server type
|
|
92
|
+
* @return {String} path string if the path exist else null
|
|
93
|
+
*/
|
|
94
|
+
export function getHandlerPath(appBase: string, serverType: string) {
|
|
95
|
+
let p = path.join(appBase, '/app/servers/', serverType, Constants.DIR.HANDLER);
|
|
96
|
+
return fs.existsSync(p) ? p : null;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Get admin script root path.
|
|
101
|
+
*
|
|
102
|
+
* @param {String} appBase application base path
|
|
103
|
+
* @return {String} script path string
|
|
104
|
+
*/
|
|
105
|
+
export function getScriptPath(appBase: string) {
|
|
106
|
+
return path.join(appBase, Constants.DIR.SCRIPT);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Get logs path.
|
|
111
|
+
*
|
|
112
|
+
* @param {String} appBase application base path
|
|
113
|
+
* @return {String} logs path string
|
|
114
|
+
*/
|
|
115
|
+
export function getLogPath(appBase: string) {
|
|
116
|
+
return path.join(appBase, Constants.DIR.LOG);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export function getPluginRemotePath(basePath: string) {
|
|
120
|
+
let p = path.join(basePath, DIR.REMOTE);
|
|
121
|
+
return fs.existsSync(p) ? p : null;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export function getPluginHandlerPath(basePath: string) {
|
|
125
|
+
let p = path.join(basePath, DIR.HANDLER);
|
|
126
|
+
return fs.existsSync(p) ? p : null;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export function getPluginCronPath(basePath: string) {
|
|
130
|
+
let p = path.join(basePath, DIR.CRON);
|
|
131
|
+
return fs.existsSync(p) ? p : null;
|
|
132
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 不带路由参数的远程调用代理
|
|
3
|
+
*/
|
|
4
|
+
export interface RemoterProxy<F> {
|
|
5
|
+
/**
|
|
6
|
+
* 使用默认路由参数null调用rpc
|
|
7
|
+
*/
|
|
8
|
+
defaultRoute: F;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* 路由到serverId服务器,并返回rpc函数
|
|
12
|
+
* notify: 只发送消息,不接收返回,节省一次通信。
|
|
13
|
+
* (notify只有tcp的rpc协议支持.其它协议不要使用 notify)
|
|
14
|
+
*/
|
|
15
|
+
to(serverId: string, notify?: boolean): F;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* 广播到所有定义了这个remoter的服务器
|
|
19
|
+
*/
|
|
20
|
+
broadcast: F;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* 带路由参数的远程调用代理
|
|
25
|
+
*/
|
|
26
|
+
export interface RemoterProxyWithRoute<ROUTE, F> extends RemoterProxy<F> {
|
|
27
|
+
/**
|
|
28
|
+
* 路由到routeParam,并返回rpc调用函数
|
|
29
|
+
* notify: 只发送消息,不接收返回,节省一次通信。
|
|
30
|
+
* (notify只有tcp的rpc协议支持.其它rpc协议不要使用 notify)
|
|
31
|
+
*/
|
|
32
|
+
route(routeParam: ROUTE, notify?: boolean): F;
|
|
33
|
+
|
|
34
|
+
// 兼容老的写法
|
|
35
|
+
(routeParam: ROUTE, ...args: any[]): Promise<any>;
|
|
36
|
+
|
|
37
|
+
toServer(serverId: string, ...args: any[]): Promise<any>;
|
|
38
|
+
|
|
39
|
+
toServer(serverId: '*', ...args: any[]): Promise<any[]>;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function bindRemoterMethod<ROUTE, T, R, F>(method: F & (() => Promise<R>), thisArg: T, routeParamType: new (...args: any[]) => ROUTE): RemoterProxyWithRoute<ROUTE, F> & ((routeParam: ROUTE) => Promise<R>) & { toServer(serverId: string): Promise<R> };
|
|
43
|
+
export function bindRemoterMethod<ROUTE, T, T1, R, F>(method: F & ((arg1: T1) => Promise<R>), thisArg: T, routeParamType: new (...args: any[]) => ROUTE): RemoterProxyWithRoute<ROUTE, F> & ((routeParam: ROUTE, arg1: T1) => Promise<R>) & { toServer(serverId: string, arg1: T1): Promise<R> };
|
|
44
|
+
export function bindRemoterMethod<ROUTE, T, T1, T2, R, F>(method: F & ((arg1: T1, arg2: T2) => Promise<R>), thisArg: T, routeParamType: new (...args: any[]) => ROUTE): RemoterProxyWithRoute<ROUTE, F> & ((routeParam: ROUTE, arg1: T1, arg2: T2) => Promise<R>) & { toServer(serverId: string, arg1: T1, arg2: T2): Promise<R> };
|
|
45
|
+
export function bindRemoterMethod<ROUTE, T, T1, T2, T3, R, F>(method: F & ((arg1: T1, arg2: T2, arg3: T3) => Promise<R>), thisArg: T, routeParamType: new (...args: any[]) => ROUTE): RemoterProxyWithRoute<ROUTE, F> & ((routeParam: ROUTE, arg1: T1, arg2: T2, arg3: T3) => Promise<R>) & { toServer(serverId: string, arg1: T1, arg2: T2, arg3: T3): Promise<R> };
|
|
46
|
+
export function bindRemoterMethod<ROUTE, T, T1, T2, T3, T4, R, F>(method: F & ((arg1: T1, arg2: T2, arg3: T3, arg4: T4) => Promise<R>), thisArg: T, routeParamType: new (...args: any[]) => ROUTE): RemoterProxyWithRoute<ROUTE, F> & ((routeParam: ROUTE, arg1: T1, arg2: T2, arg3: T3, arg4: T4) => Promise<R>) & { toServer(serverId: string, arg1: T1, arg2: T2, arg3: T3, arg4: T4): Promise<R> };
|
|
47
|
+
export function bindRemoterMethod<ROUTE, T, T1, T2, T3, T4, T5, R, F>(method: F & ((arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5) => Promise<R>), thisArg: T, routeParamType: new (...args: any[]) => ROUTE): RemoterProxyWithRoute<ROUTE, F> & ((routeParam: ROUTE, arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5) => Promise<R>) & { toServer(serverId: string, arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5): Promise<R> };
|
|
48
|
+
export function bindRemoterMethod<ROUTE, T, T1, T2, T3, T4, T5, T6, R, F>(method: F & ((arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, arg6: T6) => Promise<R>), thisArg: T, routeParamType: new (...args: any[]) => ROUTE): RemoterProxyWithRoute<ROUTE, F> & ((routeParam: ROUTE, arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, arg6: T6) => Promise<R>) & { toServer(serverId: string, arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, arg6: T6): Promise<R> };
|
|
49
|
+
export function bindRemoterMethod<ROUTE, T, T1, T2, T3, T4, T5, T6, T7, R, F>(method: F & ((arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, arg6: T6, arg7: T7) => Promise<R>), thisArg: T, routeParamType: new (...args: any[]) => ROUTE): RemoterProxyWithRoute<ROUTE, F> & ((routeParam: ROUTE, arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, arg6: T6, arg7: T7) => Promise<R>) & { toServer(serverId: string, arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, arg6: T6, arg7: T): Promise<R> };
|
|
50
|
+
export function bindRemoterMethod<ROUTE, T, T1, T2, T3, T4, T5, T6, T7, T8, R, F>(method: F & ((arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, arg6: T6, arg7: T7, arg8: T8) => Promise<R>), thisArg: T, routeParamType: new (...args: any[]) => ROUTE): RemoterProxyWithRoute<ROUTE, F> & ((routeParam: ROUTE, arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, arg6: T6, arg7: T7, arg8: T8) => Promise<R>) & { toServer(serverId: string, arg1: T1, arg2: T2, arg3: T3, arg4: T4, arg5: T5, arg6: T6, arg7: T7, arg8: T8): Promise<R> };
|
|
51
|
+
export function bindRemoterMethod<T extends object, F extends Function, ROUTE>(method: F, thisArg: T): RemoterProxy<F>;
|
|
52
|
+
export function bindRemoterMethod<T extends object, F extends Function, ROUTE>(method: F, thisArg: T, routeParamType?: new (...args: any[]) => ROUTE): RemoterProxyWithRoute<ROUTE, F> {
|
|
53
|
+
return method.bind(thisArg) as any;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export type RemoterClass<ROUTE, T> = {
|
|
57
|
+
[P in keyof T]?: RemoterProxyWithRoute<ROUTE, T[P]>;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
type TestRoutify<ROUTE, T, K extends keyof T> = { [P in K]: RemoterProxyWithRoute<ROUTE, T[K]> };
|
|
61
|
+
|
|
62
|
+
type FunctionKeys<T> =
|
|
63
|
+
{ [K in keyof T]: T[K] extends Function ? K : never }[keyof T];
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
export type DefineRoutifyMethods<ROUTE, T> = RemoterClass<ROUTE, T>;
|
|
67
|
+
|
|
68
|
+
|
|
@@ -0,0 +1,365 @@
|
|
|
1
|
+
import * as os from 'os';
|
|
2
|
+
import * as util from 'util';
|
|
3
|
+
import {exec} from 'child_process';
|
|
4
|
+
import {getLogger} from '@bigtyphoon/melo-logger';
|
|
5
|
+
import * as Constants from './constants';
|
|
6
|
+
import {ServerInfo} from './constants';
|
|
7
|
+
import {Application} from '../application';
|
|
8
|
+
import * as path from 'path';
|
|
9
|
+
import { melo } from '../melo';
|
|
10
|
+
|
|
11
|
+
let logger = getLogger('melo', path.basename(__filename));
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Invoke callback with check
|
|
16
|
+
*/
|
|
17
|
+
export function invokeCallback(cb: Function, ...args: any[]) {
|
|
18
|
+
if (typeof cb === 'function') {
|
|
19
|
+
let len = args.length + 1;
|
|
20
|
+
if (len === 1) {
|
|
21
|
+
return cb();
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (len === 2) {
|
|
25
|
+
return cb(args[0]);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (len === 3) {
|
|
29
|
+
return cb(args[0], args[1]);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (len === 4) {
|
|
33
|
+
return cb(args[0], args[1], args[2]);
|
|
34
|
+
}
|
|
35
|
+
cb.apply(null, args);
|
|
36
|
+
// cb.apply(null, Array.prototype.slice.call(arguments, 1));
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Get the count of elements of object
|
|
42
|
+
*/
|
|
43
|
+
export function size(obj: any) {
|
|
44
|
+
let count = 0;
|
|
45
|
+
for (let i in obj) {
|
|
46
|
+
if (obj.hasOwnProperty(i) && typeof obj[i] !== 'function') {
|
|
47
|
+
count++;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return count;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Check a string whether ends with another string
|
|
55
|
+
*/
|
|
56
|
+
export function endsWith(str: string, suffix: string) {
|
|
57
|
+
if (typeof str !== 'string' || typeof suffix !== 'string' ||
|
|
58
|
+
suffix.length > str.length) {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
return str.indexOf(suffix, str.length - suffix.length) !== -1;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Check a string whether starts with another string
|
|
66
|
+
*/
|
|
67
|
+
export function startsWith(str: string, prefix: string) {
|
|
68
|
+
if (typeof str !== 'string' || typeof prefix !== 'string' ||
|
|
69
|
+
prefix.length > str.length) {
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return str.indexOf(prefix) === 0;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Compare the two arrays and return the difference.
|
|
78
|
+
*/
|
|
79
|
+
export function arrayDiff<T extends string>(array1: Array<T>, array2: Array<T>) {
|
|
80
|
+
let o: { [key: string]: boolean } = {};
|
|
81
|
+
for (let i = 0, len = array2.length; i < len; i++) {
|
|
82
|
+
o[array2[i]] = true;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
let result = [];
|
|
86
|
+
for (let i = 0, len = array1.length; i < len; i++) {
|
|
87
|
+
let v = array1[i];
|
|
88
|
+
if (o[v]) continue;
|
|
89
|
+
result.push(v);
|
|
90
|
+
}
|
|
91
|
+
return result;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/*
|
|
95
|
+
* Date format
|
|
96
|
+
*/
|
|
97
|
+
export function format(date: Date, format ?: string) {
|
|
98
|
+
format = format || 'MMddhhmm';
|
|
99
|
+
let o = {
|
|
100
|
+
'M+': date.getMonth() + 1, // month
|
|
101
|
+
'd+': date.getDate(), // day
|
|
102
|
+
'h+': date.getHours(), // hour
|
|
103
|
+
'm+': date.getMinutes(), // minute
|
|
104
|
+
's+': date.getSeconds(), // second
|
|
105
|
+
'q+': Math.floor((date.getMonth() + 3) / 3), // quarter
|
|
106
|
+
'S': date.getMilliseconds() // millisecond
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
if (/(y+)/.test(format)) {
|
|
110
|
+
format = format.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length));
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
for (let k in o) {
|
|
114
|
+
if (new RegExp('(' + k + ')').test(format)) {
|
|
115
|
+
format = format.replace(RegExp.$1, RegExp.$1.length === 1 ? (o as any)[k] :
|
|
116
|
+
('00' + (o as any)[k]).substr(('' + (o as any)[k]).length));
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return format;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* check if has Chinese characters.
|
|
124
|
+
*/
|
|
125
|
+
export function hasChineseChar(str: string) {
|
|
126
|
+
if (/.*[\u4e00-\u9fa5]+.*$/.test(str)) {
|
|
127
|
+
return true;
|
|
128
|
+
} else {
|
|
129
|
+
return false;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* transform unicode to utf8
|
|
135
|
+
*/
|
|
136
|
+
export function unicodeToUtf8(str: string) {
|
|
137
|
+
let i, len, ch;
|
|
138
|
+
let utf8Str = '';
|
|
139
|
+
len = str.length;
|
|
140
|
+
for (i = 0; i < len; i++) {
|
|
141
|
+
ch = str.charCodeAt(i);
|
|
142
|
+
|
|
143
|
+
if ((ch >= 0x0) && (ch <= 0x7F)) {
|
|
144
|
+
utf8Str += str.charAt(i);
|
|
145
|
+
|
|
146
|
+
} else if ((ch >= 0x80) && (ch <= 0x7FF)) {
|
|
147
|
+
utf8Str += String.fromCharCode(0xc0 | ((ch >> 6) & 0x1F));
|
|
148
|
+
utf8Str += String.fromCharCode(0x80 | (ch & 0x3F));
|
|
149
|
+
|
|
150
|
+
} else if ((ch >= 0x800) && (ch <= 0xFFFF)) {
|
|
151
|
+
utf8Str += String.fromCharCode(0xe0 | ((ch >> 12) & 0xF));
|
|
152
|
+
utf8Str += String.fromCharCode(0x80 | ((ch >> 6) & 0x3F));
|
|
153
|
+
utf8Str += String.fromCharCode(0x80 | (ch & 0x3F));
|
|
154
|
+
|
|
155
|
+
} else if ((ch >= 0x10000) && (ch <= 0x1FFFFF)) {
|
|
156
|
+
utf8Str += String.fromCharCode(0xF0 | ((ch >> 18) & 0x7));
|
|
157
|
+
utf8Str += String.fromCharCode(0x80 | ((ch >> 12) & 0x3F));
|
|
158
|
+
utf8Str += String.fromCharCode(0x80 | ((ch >> 6) & 0x3F));
|
|
159
|
+
utf8Str += String.fromCharCode(0x80 | (ch & 0x3F));
|
|
160
|
+
|
|
161
|
+
} else if ((ch >= 0x200000) && (ch <= 0x3FFFFFF)) {
|
|
162
|
+
utf8Str += String.fromCharCode(0xF8 | ((ch >> 24) & 0x3));
|
|
163
|
+
utf8Str += String.fromCharCode(0x80 | ((ch >> 18) & 0x3F));
|
|
164
|
+
utf8Str += String.fromCharCode(0x80 | ((ch >> 12) & 0x3F));
|
|
165
|
+
utf8Str += String.fromCharCode(0x80 | ((ch >> 6) & 0x3F));
|
|
166
|
+
utf8Str += String.fromCharCode(0x80 | (ch & 0x3F));
|
|
167
|
+
|
|
168
|
+
} else if ((ch >= 0x4000000) && (ch <= 0x7FFFFFFF)) {
|
|
169
|
+
utf8Str += String.fromCharCode(0xFC | ((ch >> 30) & 0x1));
|
|
170
|
+
utf8Str += String.fromCharCode(0x80 | ((ch >> 24) & 0x3F));
|
|
171
|
+
utf8Str += String.fromCharCode(0x80 | ((ch >> 18) & 0x3F));
|
|
172
|
+
utf8Str += String.fromCharCode(0x80 | ((ch >> 12) & 0x3F));
|
|
173
|
+
utf8Str += String.fromCharCode(0x80 | ((ch >> 6) & 0x3F));
|
|
174
|
+
utf8Str += String.fromCharCode(0x80 | (ch & 0x3F));
|
|
175
|
+
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
}
|
|
179
|
+
return utf8Str;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Ping server to check if network is available
|
|
184
|
+
*
|
|
185
|
+
*/
|
|
186
|
+
export function ping(host: string, cb: (ret: boolean) => void) {
|
|
187
|
+
if (!isLocal(host)) {
|
|
188
|
+
let cmd = 'ping -w 15 ' + host;
|
|
189
|
+
exec(cmd, function (err, stdout, stderr) {
|
|
190
|
+
if (!!err) {
|
|
191
|
+
cb(false);
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
cb(true);
|
|
195
|
+
});
|
|
196
|
+
} else {
|
|
197
|
+
cb(true);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Check if server is exsit.
|
|
203
|
+
*
|
|
204
|
+
*/
|
|
205
|
+
export function checkPort(app: Application, server: ServerInfo, cb: (result: string) => void) {
|
|
206
|
+
if (!server.port && !server.clientPort) {
|
|
207
|
+
invokeCallback(cb, 'leisure');
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
let port = server.port || server.clientPort;
|
|
211
|
+
const host = server.host;
|
|
212
|
+
const generateCommand = function (host: string, port: number) {
|
|
213
|
+
let cmd;
|
|
214
|
+
let ssh_params = app.get(Constants.RESERVED.SSH_CONFIG_PARAMS);
|
|
215
|
+
if (!!ssh_params && Array.isArray(ssh_params)) {
|
|
216
|
+
ssh_params = ssh_params.join(' ');
|
|
217
|
+
}
|
|
218
|
+
else {
|
|
219
|
+
ssh_params = '';
|
|
220
|
+
}
|
|
221
|
+
if (!isLocal(host)) {
|
|
222
|
+
cmd = util.format('ssh %s %s "netstat -an|awk \'{print $4}\'|grep %s|wc -l"', host, ssh_params, port);
|
|
223
|
+
} else {
|
|
224
|
+
cmd = util.format('netstat -an|awk \'{print $4}\'|grep %s|wc -l', port);
|
|
225
|
+
}
|
|
226
|
+
return cmd;
|
|
227
|
+
};
|
|
228
|
+
const cmd1 = generateCommand(host, port);
|
|
229
|
+
exec(cmd1, function (err, stdout, stderr) {
|
|
230
|
+
if (err) {
|
|
231
|
+
logger.error('command %s execute with error: %j', cmd1, err.stack);
|
|
232
|
+
invokeCallback(cb, 'error');
|
|
233
|
+
} else if (stdout.trim() !== '0') {
|
|
234
|
+
invokeCallback(cb, 'busy');
|
|
235
|
+
} else {
|
|
236
|
+
port = server.clientPort;
|
|
237
|
+
const cmd2 = generateCommand(host, port);
|
|
238
|
+
exec(cmd2, function (err, stdout, stderr) {
|
|
239
|
+
if (err) {
|
|
240
|
+
logger.error('command %s execute with error: %j', cmd2, err.stack);
|
|
241
|
+
invokeCallback(cb, 'error');
|
|
242
|
+
} else if (stdout.trim() !== '0') {
|
|
243
|
+
invokeCallback(cb, 'busy');
|
|
244
|
+
} else {
|
|
245
|
+
invokeCallback(cb, 'leisure');
|
|
246
|
+
}
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
export function isLocal(host: string) {
|
|
253
|
+
const app = melo.app;
|
|
254
|
+
if (!app) {
|
|
255
|
+
return host === '127.0.0.1' || host === 'localhost' || host === '0.0.0.0' || inLocal(host);
|
|
256
|
+
} else {
|
|
257
|
+
return host === '127.0.0.1' || host === 'localhost' || host === '0.0.0.0' || inLocal(host) || host === app.master.host;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* Load cluster server.
|
|
263
|
+
*
|
|
264
|
+
*/
|
|
265
|
+
export function loadCluster(app: Application, server: ServerInfo, serverMap: { [serverId: string]: ServerInfo }) {
|
|
266
|
+
let increaseFields: { [key: string]: string } = {};
|
|
267
|
+
let host = server.host;
|
|
268
|
+
let count = Number(server[Constants.RESERVED.CLUSTER_COUNT]);
|
|
269
|
+
let seq = app.clusterSeq[server.serverType];
|
|
270
|
+
if (!seq) {
|
|
271
|
+
seq = 0;
|
|
272
|
+
app.clusterSeq[server.serverType] = count;
|
|
273
|
+
} else {
|
|
274
|
+
app.clusterSeq[server.serverType] = seq + count;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
for (let key in server) {
|
|
278
|
+
let value = (server as any)[key].toString();
|
|
279
|
+
if (value.indexOf(Constants.RESERVED.CLUSTER_SIGNAL) > 0) {
|
|
280
|
+
let base = (server as any)[key].slice(0, -2);
|
|
281
|
+
increaseFields[key] = base;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
let clone = function (src: any) {
|
|
286
|
+
let rs: any = {};
|
|
287
|
+
for (let key in src) {
|
|
288
|
+
rs[key] = src[key];
|
|
289
|
+
}
|
|
290
|
+
return rs;
|
|
291
|
+
};
|
|
292
|
+
for (let i = 0, l = seq; i < count; i++ , l++) {
|
|
293
|
+
let cserver = clone(server);
|
|
294
|
+
cserver.id = Constants.RESERVED.CLUSTER_PREFIX + server.serverType + '-' + l;
|
|
295
|
+
for (let k in increaseFields) {
|
|
296
|
+
let v = parseInt(increaseFields[k]);
|
|
297
|
+
cserver[k] = v + i;
|
|
298
|
+
}
|
|
299
|
+
serverMap[cserver.id] = cserver;
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
// export function extends(origin, add)
|
|
304
|
+
// {
|
|
305
|
+
// if (!add || !this.isObject(add)) return origin;
|
|
306
|
+
|
|
307
|
+
// let keys = Object.keys(add);
|
|
308
|
+
// let i = keys.length;
|
|
309
|
+
// while (i--)
|
|
310
|
+
// {
|
|
311
|
+
// origin[keys[i]] = add[keys[i]];
|
|
312
|
+
// }
|
|
313
|
+
// return origin;
|
|
314
|
+
// };
|
|
315
|
+
|
|
316
|
+
export function headHandler(headBuffer: Buffer) {
|
|
317
|
+
let len = 0;
|
|
318
|
+
for (let i = 1; i < 4; i++) {
|
|
319
|
+
if (i > 1) {
|
|
320
|
+
len <<= 8;
|
|
321
|
+
}
|
|
322
|
+
len += headBuffer.readUInt8(i);
|
|
323
|
+
}
|
|
324
|
+
return len;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
let inLocal = function (host: string) {
|
|
328
|
+
for (let index in localIps) {
|
|
329
|
+
if (host === localIps[index]) {
|
|
330
|
+
return true;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
return false;
|
|
334
|
+
};
|
|
335
|
+
|
|
336
|
+
let localIps = function () {
|
|
337
|
+
let ifaces = os.networkInterfaces();
|
|
338
|
+
let ips: string[] = [];
|
|
339
|
+
let func = function (details: os.NetworkInterfaceInfo) {
|
|
340
|
+
if (details.family === 'IPv4') {
|
|
341
|
+
ips.push(details.address);
|
|
342
|
+
}
|
|
343
|
+
};
|
|
344
|
+
for (let dev in ifaces) {
|
|
345
|
+
ifaces[dev].forEach(func);
|
|
346
|
+
}
|
|
347
|
+
return ips;
|
|
348
|
+
}();
|
|
349
|
+
|
|
350
|
+
export function isObject(arg: any) {
|
|
351
|
+
return typeof arg === 'object' && arg !== null;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
export function extendsObject(origin: any, add: any) {
|
|
355
|
+
if (!add || !isObject(add)) return origin;
|
|
356
|
+
|
|
357
|
+
let keys = Object.keys(add);
|
|
358
|
+
let i = keys.length;
|
|
359
|
+
while (i--) {
|
|
360
|
+
origin[keys[i]] = add[keys[i]];
|
|
361
|
+
}
|
|
362
|
+
return origin;
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
export let promisify = util.promisify;
|
package/package.json
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@bigtyphoon/melo",
|
|
3
|
+
"version": "1.7.6",
|
|
4
|
+
"private": false,
|
|
5
|
+
"homepage": "https://github.com/node-melo/melo",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git@github.com:node-melo/melo.git"
|
|
9
|
+
},
|
|
10
|
+
"scripts": {
|
|
11
|
+
"build": "tsc",
|
|
12
|
+
"start": "yarn run build && node dist/index",
|
|
13
|
+
"lint": "node_modules/.bin/tslint --format prose -c ../../tslint.json lib/**/*.ts test/**/*.ts",
|
|
14
|
+
"fix-lint": "node_modules/.bin/tslint --format prose -c ../../tslint.json lib/**/*.ts test/**/*.ts --fix",
|
|
15
|
+
"test": "yarn run build",
|
|
16
|
+
"cov": "nyc mocha",
|
|
17
|
+
"ci": "yarn run test",
|
|
18
|
+
"mochatest": "cd dist && mocha --require source-map-support/register --recursive",
|
|
19
|
+
"gen-api-ref": "node ../../node_modules/typedoc/bin/typedoc --mode file --hideGenerator --excludeExternals --ignoreCompilerErrors --out ../../run/site/public/api-reference/melo lib/"
|
|
20
|
+
},
|
|
21
|
+
"engines": {
|
|
22
|
+
"node": ">=12.9.0"
|
|
23
|
+
},
|
|
24
|
+
"bugs": {
|
|
25
|
+
"url": "https://github.com/node-melo/melo/issues"
|
|
26
|
+
},
|
|
27
|
+
"author": "mybios",
|
|
28
|
+
"licenses": [
|
|
29
|
+
{
|
|
30
|
+
"type": "MIT",
|
|
31
|
+
"url": "https://github.com/node-melo/melo#license"
|
|
32
|
+
}
|
|
33
|
+
],
|
|
34
|
+
"keywords": [
|
|
35
|
+
"melo",
|
|
36
|
+
"framework",
|
|
37
|
+
"game",
|
|
38
|
+
"web",
|
|
39
|
+
"realtime",
|
|
40
|
+
"server"
|
|
41
|
+
],
|
|
42
|
+
"files": [
|
|
43
|
+
"bin",
|
|
44
|
+
"dist",
|
|
45
|
+
"lib",
|
|
46
|
+
"template",
|
|
47
|
+
"test"
|
|
48
|
+
],
|
|
49
|
+
"main": "./dist/lib/index",
|
|
50
|
+
"types": "./lib/index",
|
|
51
|
+
"dependencies": {
|
|
52
|
+
"@bigtyphoon/melo-admin": "^1.7.6",
|
|
53
|
+
"@bigtyphoon/melo-loader": "^1.7.6",
|
|
54
|
+
"@bigtyphoon/melo-logger": "^1.7.6",
|
|
55
|
+
"@bigtyphoon/melo-protobuf": "^1.7.6",
|
|
56
|
+
"@bigtyphoon/melo-protocol": "^1.7.6",
|
|
57
|
+
"@bigtyphoon/melo-rpc": "^1.7.6",
|
|
58
|
+
"@bigtyphoon/melo-scheduler": "^1.7.6",
|
|
59
|
+
"async": "^3.0.0",
|
|
60
|
+
"colors": "^1.4.0",
|
|
61
|
+
"commander": "3.0.2",
|
|
62
|
+
"crc": "^4.3.2",
|
|
63
|
+
"eyes": "^0.1.8",
|
|
64
|
+
"mkdirp": "^3.0.1",
|
|
65
|
+
"mqtt-connection": "^4.1.0",
|
|
66
|
+
"node-bignumber": "^1.2.1",
|
|
67
|
+
"pretty-columns": "^1.2.1",
|
|
68
|
+
"seq-queue": "^0.0.5",
|
|
69
|
+
"socket.io": "^4.1.3",
|
|
70
|
+
"ws": "^8.12.0"
|
|
71
|
+
},
|
|
72
|
+
"bin": {
|
|
73
|
+
"melo": "./dist/bin/melo.js"
|
|
74
|
+
},
|
|
75
|
+
"devDependencies": {
|
|
76
|
+
"@types/async": "3.2.24",
|
|
77
|
+
"@types/crc": "3.8.3",
|
|
78
|
+
"@types/eyes": "0.1.35",
|
|
79
|
+
"@types/mkdirp": "2.0.0",
|
|
80
|
+
"@types/mocha": "^5.0.0",
|
|
81
|
+
"@types/node": "^12.20.41",
|
|
82
|
+
"@types/ws": "8.5.4",
|
|
83
|
+
"mocha": "10.3.0",
|
|
84
|
+
"nyc": "15.1.0",
|
|
85
|
+
"should": "13.2.3",
|
|
86
|
+
"tslint": "6.1.3",
|
|
87
|
+
"typescript": "^4.3.5"
|
|
88
|
+
},
|
|
89
|
+
"publishConfig": {
|
|
90
|
+
"access": "public"
|
|
91
|
+
},
|
|
92
|
+
"gitHead": "87c4ea8724fa27baf22c0a669a7d89ef6f426af4"
|
|
93
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
// 使用 IntelliSense 了解相关属性。
|
|
3
|
+
// 悬停以查看现有属性的描述。
|
|
4
|
+
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
|
|
5
|
+
"version": "0.2.0",
|
|
6
|
+
"configurations": [
|
|
7
|
+
{
|
|
8
|
+
"type": "node",
|
|
9
|
+
"request": "launch",
|
|
10
|
+
"name": "LaunchMaster",
|
|
11
|
+
"program": "${workspaceFolder}\\dist\\app.js",
|
|
12
|
+
"outFiles": [
|
|
13
|
+
"${workspaceFolder}/**/*.js"
|
|
14
|
+
]
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
"type": "node",
|
|
18
|
+
"request": "attach",
|
|
19
|
+
"name": "Attach to Connector",
|
|
20
|
+
"address": "127.0.0.1",
|
|
21
|
+
"port": 10001,
|
|
22
|
+
"localRoot": "${workspaceFolder}",
|
|
23
|
+
"remoteRoot": "${workspaceFolder}"
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
]
|
|
27
|
+
}
|