mm_os 4.3.7 → 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.
- package/README.md +101 -504
- package/index.js +26 -19
- package/lib/loader.js +787 -0
- package/lib/os.js +369 -0
- package/package.json +55 -84
- package/LICENSE +0 -21
- package/README_EN.md +0 -505
- package/adapter/adapter.js +0 -484
- package/adapter/custom_persistence.js +0 -661
- package/adapter/mqtt.js +0 -254
- package/adapter/socket.js +0 -244
- package/adapter/web.js +0 -92
- package/adapter/websocket.js +0 -43
- package/ai.js +0 -130
- package/com/api/README.md +0 -3
- package/com/api/com.json +0 -5
- package/com/api/config.tpl.json +0 -41
- package/com/api/drive.js +0 -732
- package/com/api/index.js +0 -201
- package/com/api/oauth.js +0 -200
- package/com/api/script.tpl.js +0 -32
- package/com/cmd/README.md +0 -11
- package/com/cmd/com.json +0 -5
- package/com/cmd/config.tpl.json +0 -48
- package/com/cmd/drive.js +0 -176
- package/com/cmd/index.js +0 -287
- package/com/cmd/job/config.json +0 -66
- package/com/cmd/job/index.js +0 -241
- package/com/cmd/job/test.js +0 -188
- package/com/cmd/msg.json +0 -48
- package/com/cmd/script.tpl.js +0 -12
- package/com/db/README.md +0 -3
- package/com/db/com.json +0 -5
- package/com/db/drive.js +0 -2206
- package/com/db/index.js +0 -241
- package/com/event/README.md +0 -4
- package/com/event/com.json +0 -5
- package/com/event/config.tpl.json +0 -20
- package/com/event/drive.js +0 -61
- package/com/event/index.js +0 -438
- package/com/event/script.tpl.js +0 -23
- package/com/mqtt/README.md +0 -47
- package/com/mqtt/com.json +0 -5
- package/com/mqtt/config.tpl.json +0 -42
- package/com/mqtt/drive.js +0 -704
- package/com/mqtt/index.js +0 -1052
- package/com/mqtt/index.test.js +0 -503
- package/com/mqtt/script.tpl.js +0 -719
- package/com/nav/README.md +0 -2
- package/com/nav/com.json +0 -5
- package/com/nav/config.tpl.json +0 -84
- package/com/nav/drive.js +0 -702
- package/com/nav/index.js +0 -228
- package/com/nav/tpl/admin_pc/page_channel.vue +0 -305
- package/com/nav/tpl/admin_pc/page_config.vue +0 -280
- package/com/nav/tpl/admin_pc/page_config_form.vue +0 -194
- package/com/nav/tpl/admin_pc/page_default.vue +0 -247
- package/com/nav/tpl/admin_pc/page_form.vue +0 -180
- package/com/nav/tpl/admin_pc/page_lang.vue +0 -264
- package/com/nav/tpl/admin_pc/page_nav.vue +0 -321
- package/com/nav/tpl/admin_pc/page_table.vue +0 -296
- package/com/nav/tpl/admin_pc/page_type.vue +0 -321
- package/com/nav/tpl/admin_pc/page_view.vue +0 -124
- package/com/nav/tpl/dev_pc/page_channel.vue +0 -253
- package/com/nav/tpl/dev_pc/page_config.vue +0 -253
- package/com/nav/tpl/dev_pc/page_default.vue +0 -247
- package/com/nav/tpl/dev_pc/page_form.vue +0 -162
- package/com/nav/tpl/dev_pc/page_nav.vue +0 -253
- package/com/nav/tpl/dev_pc/page_table.vue +0 -247
- package/com/nav/tpl/dev_pc/page_type.vue +0 -313
- package/com/nav/tpl/home_pc/page_channel.vue +0 -234
- package/com/nav/tpl/home_pc/page_default.vue +0 -234
- package/com/nav/tpl/home_pc/page_form.vue +0 -137
- package/com/nav/tpl/home_pc/page_list.vue +0 -234
- package/com/nav/tpl/home_pc/page_nav.vue +0 -221
- package/com/nav/tpl/home_pc/page_type.vue +0 -234
- package/com/nav/tpl/home_pc/page_view.vue +0 -125
- package/com/nav/tpl/home_phone/page_channel.vue +0 -234
- package/com/nav/tpl/home_phone/page_default.vue +0 -234
- package/com/nav/tpl/home_phone/page_form.vue +0 -137
- package/com/nav/tpl/home_phone/page_list.vue +0 -234
- package/com/nav/tpl/home_phone/page_nav.vue +0 -237
- package/com/nav/tpl/home_phone/page_type.vue +0 -234
- package/com/nav/tpl/home_phone/page_view.vue +0 -125
- package/com/nav/viewmodel.js +0 -446
- package/com/param/README.md +0 -2
- package/com/param/com.json +0 -5
- package/com/param/config.tpl.json +0 -136
- package/com/param/drive.js +0 -502
- package/com/param/index.js +0 -158
- package/com/param/script.tpl.js +0 -12
- package/com/pendant/README.md +0 -3
- package/com/pendant/com.json +0 -5
- package/com/pendant/config.tpl.json +0 -32
- package/com/pendant/drive.js +0 -204
- package/com/pendant/index.js +0 -467
- package/com/pendant/pendant.html +0 -16
- package/com/pendant/script.tpl.js +0 -18
- package/com/socket/README.md +0 -47
- package/com/socket/com.json +0 -5
- package/com/socket/config.tpl.json +0 -12
- package/com/socket/drive.js +0 -679
- package/com/socket/index.js +0 -402
- package/com/socket/script.tpl.js +0 -41
- package/com/sql/README.md +0 -3
- package/com/sql/com.json +0 -5
- package/com/sql/config.tpl.json +0 -74
- package/com/sql/drive.js +0 -1328
- package/com/sql/index.js +0 -152
- package/com/sql/script.tpl.js +0 -47
- package/com/static/README.md +0 -2
- package/com/static/com.json +0 -5
- package/com/static/config.tpl.json +0 -24
- package/com/static/drive.js +0 -194
- package/com/static/index.js +0 -237
- package/com/static/script.tpl.js +0 -28
- package/com/task/README.md +0 -3
- package/com/task/com.json +0 -5
- package/com/task/config.tpl.json +0 -24
- package/com/task/drive.js +0 -428
- package/com/task/index.js +0 -159
- package/com/task/script.tpl.js +0 -40
- package/com/template/com.json +0 -5
- package/com/template/config.tpl.json +0 -16
- package/com/template/drive.js +0 -81
- package/com/template/index.js +0 -141
- package/com.js +0 -237
- package/common/README.md +0 -2
- package/common/middleware/web_after/index.js +0 -26
- package/common/middleware/web_after/middleware.json +0 -9
- package/common/middleware/web_base/index.js +0 -113
- package/common/middleware/web_base/middleware.json +0 -19
- package/common/middleware/web_before/index.js +0 -33
- package/common/middleware/web_before/middleware.json +0 -9
- package/common/middleware/web_cors/index.js +0 -87
- package/common/middleware/web_cors/middleware.json +0 -24
- package/common/middleware/web_error/index.js +0 -131
- package/common/middleware/web_error/middleware.json +0 -19
- package/common/middleware/web_ip/index.js +0 -15
- package/common/middleware/web_ip/middleware.json +0 -14
- package/common/middleware/web_logger/index.js +0 -156
- package/common/middleware/web_logger/middleware.json +0 -14
- package/common/middleware/web_main/index.js +0 -26
- package/common/middleware/web_main/middleware.json +0 -9
- package/common/middleware/web_static/index.js +0 -73
- package/common/middleware/web_static/middleware.json +0 -54
- package/common/middleware/web_waf/index.js +0 -395
- package/common/middleware/web_waf/middleware.json +0 -13
- package/core/app/config.tpl.json +0 -67
- package/core/app/index.js +0 -711
- package/core/app/script.tpl.js +0 -52
- package/core/channel/index.js +0 -899
- package/core/channel/matcher.js +0 -585
- package/core/com/config.tpl.json +0 -16
- package/core/com/index.js +0 -77
- package/core/com/script.tpl.js +0 -5
- package/core/component/component.js +0 -42
- package/core/component/config.tpl.json +0 -63
- package/core/component/index.js +0 -273
- package/core/component/script.tpl.js +0 -19
- package/core/controller/config.tpl.json +0 -14
- package/core/controller/index.js +0 -371
- package/core/controller/script.tpl.js +0 -27
- package/core/factory/config.tpl.json +0 -14
- package/core/factory/entity.js +0 -275
- package/core/factory/index.js +0 -241
- package/core/factory/script.tpl.js +0 -16
- package/core/game/bat/index.js +0 -137
- package/core/game/bat/world.js +0 -622
- package/core/game/config.tpl.json +0 -16
- package/core/game/entity_admin.js +0 -230
- package/core/game/index.js +0 -186
- package/core/handler/config.tpl.json +0 -22
- package/core/handler/index.js +0 -181
- package/core/handler/script.tpl.js +0 -23
- package/core/logic/config.tpl.json +0 -14
- package/core/logic/index.js +0 -59
- package/core/logic/script.tpl.js +0 -19
- package/core/middleware/config.tpl.json +0 -16
- package/core/middleware/index.js +0 -117
- package/core/middleware/script.tpl.js +0 -37
- package/core/mod/config.tpl.json +0 -22
- package/core/mod/index.js +0 -136
- package/core/mod/script.tpl.js +0 -34
- package/core/model/config.tpl.json +0 -219
- package/core/model/index.js +0 -272
- package/core/model/model.js +0 -27
- package/core/model/script.tpl.js +0 -20
- package/core/notifier/config.tpl.json +0 -14
- package/core/notifier/index.js +0 -77
- package/core/notifier/script.tpl.js +0 -20
- package/core/plugin/config.tpl.json +0 -36
- package/core/plugin/index.js +0 -267
- package/core/plugin/script.tpl.js +0 -51
- package/core/pusher/config.tpl.json +0 -14
- package/core/pusher/index.js +0 -158
- package/core/pusher/script.tpl.js +0 -20
- package/core/room/bat/index.js +0 -170
- package/core/room/bat/room.js +0 -524
- package/core/room/config.tpl.json +0 -20
- package/core/room/index.js +0 -249
- package/core/room/room.js +0 -61
- package/core/scene/config.tpl.json +0 -14
- package/core/scene/index.js +0 -467
- package/core/scene/loop.js +0 -1306
- package/core/scene/map.js +0 -28
- package/core/scene/script.tpl.js +0 -22
- package/core/sender/config.tpl.json +0 -14
- package/core/sender/index.js +0 -79
- package/core/sender/script.tpl.js +0 -20
- package/core/service/config.tpl.json +0 -14
- package/core/service/index.js +0 -100
- package/core/service/script.tpl.js +0 -25
- package/core/store/config.tpl.json +0 -26
- package/core/store/index.js +0 -1794
- package/core/store/script.tpl.js +0 -22
- package/core/system/config.tpl.json +0 -18
- package/core/system/index.js +0 -312
- package/core/system/script.tpl.js +0 -77
- package/core/view/config.tpl.json +0 -14
- package/core/view/index.js +0 -91
- package/core/view/script.tpl.js +0 -20
- package/core/zone/bat/index.js +0 -744
- package/core/zone/config.tpl.json +0 -54
- package/core/zone/index.js +0 -655
- package/core/zone/script.tpl.js +0 -10
- package/core/zone/zone_bat.js +0 -136
- package/core//345/237/272/347/261/273/346/250/241/345/235/227/346/270/205/345/215/225.md +0 -24
- package/os.js +0 -53
- package/server.js +0 -602
- package/ulits/id_gen.js +0 -134
- package/ulits/word.js +0 -206
package/lib/os.js
ADDED
|
@@ -0,0 +1,369 @@
|
|
|
1
|
+
const { Mod, Store } = require('mm_corejs');
|
|
2
|
+
const { getLogger } = require('mm_logger');
|
|
3
|
+
const Loader = require('./loader');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* OS类
|
|
7
|
+
*/
|
|
8
|
+
class OS extends Mod {
|
|
9
|
+
static config = {
|
|
10
|
+
name: 'os',
|
|
11
|
+
in_adapters: ['web', 'mqtt', 'socket', 'websocket'],
|
|
12
|
+
out_adapters: ['redis', 'mongodb', 'mysql', 'sqlite', 'jsondb', 'file'],
|
|
13
|
+
tools: ['lang', 'tpl', 'ret'],
|
|
14
|
+
admins: ['handle', 'event', 'api', 'param', 'service', 'template', 'pendant', 'timer', 'statics'],
|
|
15
|
+
cache: {
|
|
16
|
+
type: 'redis'
|
|
17
|
+
},
|
|
18
|
+
db: {
|
|
19
|
+
type: 'mysql'
|
|
20
|
+
},
|
|
21
|
+
web: {
|
|
22
|
+
port: 8080
|
|
23
|
+
},
|
|
24
|
+
mqtt: {
|
|
25
|
+
port: 1883
|
|
26
|
+
},
|
|
27
|
+
socket: {
|
|
28
|
+
port: 9000
|
|
29
|
+
},
|
|
30
|
+
websocket: {
|
|
31
|
+
port: 9001
|
|
32
|
+
},
|
|
33
|
+
jsondb: {
|
|
34
|
+
dir: './data'
|
|
35
|
+
},
|
|
36
|
+
mysql: {
|
|
37
|
+
host: '127.0.0.1',
|
|
38
|
+
port: 3306,
|
|
39
|
+
user: 'root',
|
|
40
|
+
password: 'Asd159357',
|
|
41
|
+
database: 'mm'
|
|
42
|
+
},
|
|
43
|
+
redis: {
|
|
44
|
+
host: '127.0.0.1',
|
|
45
|
+
password: 'asd159357',
|
|
46
|
+
port: 6379,
|
|
47
|
+
db: 0
|
|
48
|
+
},
|
|
49
|
+
mongodb: {
|
|
50
|
+
host: '127.0.0.1',
|
|
51
|
+
port: 27017,
|
|
52
|
+
user: 'root',
|
|
53
|
+
password: 'asd123',
|
|
54
|
+
database: 'mm'
|
|
55
|
+
},
|
|
56
|
+
sqlite: {
|
|
57
|
+
dir: './db',
|
|
58
|
+
database: 'mm',
|
|
59
|
+
user: 'root',
|
|
60
|
+
password: 'asd123'
|
|
61
|
+
},
|
|
62
|
+
ret: {
|
|
63
|
+
type: 'json-rpc'
|
|
64
|
+
},
|
|
65
|
+
lang: {
|
|
66
|
+
type: 'zh_cn'
|
|
67
|
+
},
|
|
68
|
+
tpl: {
|
|
69
|
+
dir: './static/template',
|
|
70
|
+
ext: '.html'
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* OS类构造函数
|
|
76
|
+
* @param {object} config 配置对象
|
|
77
|
+
*/
|
|
78
|
+
constructor(config) {
|
|
79
|
+
super(config);
|
|
80
|
+
/**
|
|
81
|
+
* 管理列表
|
|
82
|
+
* @type {Store}
|
|
83
|
+
*/
|
|
84
|
+
this.admins = new Store();
|
|
85
|
+
/**
|
|
86
|
+
* 输入适配器列表
|
|
87
|
+
* @type {Store}
|
|
88
|
+
*/
|
|
89
|
+
this.in_adapters = new Store();
|
|
90
|
+
/**
|
|
91
|
+
* 输出适配器列表
|
|
92
|
+
* @type {Store}
|
|
93
|
+
*/
|
|
94
|
+
this.out_adapters = new Store();
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* 生命周期初始化钩子
|
|
99
|
+
* @returns {void} 无返回值
|
|
100
|
+
*/
|
|
101
|
+
async onInit() {
|
|
102
|
+
this.initLogger();
|
|
103
|
+
// 初始化事件总线
|
|
104
|
+
this.initEventBus();
|
|
105
|
+
await this.initAdmins();
|
|
106
|
+
await this.initAdapter();
|
|
107
|
+
await this.initpStorage();
|
|
108
|
+
await this.initLoader();
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* 初始化日志记录器
|
|
114
|
+
*/
|
|
115
|
+
OS.prototype.initLogger = function () {
|
|
116
|
+
this.logger = getLogger(this.config.log || { level: 'info' });
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* 记录日志
|
|
121
|
+
* @param {string} type 日志类型
|
|
122
|
+
* @param {string} msg 日志消息
|
|
123
|
+
* @param {...*} args 日志参数
|
|
124
|
+
*/
|
|
125
|
+
OS.prototype.log = function (type, msg, ...args) {
|
|
126
|
+
this.logger[type](msg, ...args);
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* 注册管理
|
|
131
|
+
* @param {string} name 管理名称
|
|
132
|
+
* @param {object} admin 管理对象
|
|
133
|
+
*/
|
|
134
|
+
OS.prototype.reg = function (name, admin) {
|
|
135
|
+
this.admins.add({ id: name, name: name, admin });
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* 加载模块
|
|
140
|
+
* @param {string} mod_name 模块名称
|
|
141
|
+
* @returns {object} 模块对象
|
|
142
|
+
*/
|
|
143
|
+
OS.prototype.require = function (mod_name) {
|
|
144
|
+
return require(mod_name);
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* 初始化适配器
|
|
149
|
+
* @returns {void} 无返回值
|
|
150
|
+
*/
|
|
151
|
+
OS.prototype.initAdapter = async function () {
|
|
152
|
+
// 入站适配器
|
|
153
|
+
let adapters = this.config.in_adapters || [];
|
|
154
|
+
for (let name of adapters) {
|
|
155
|
+
try {
|
|
156
|
+
let admin = this.require(`mm_${name}_server`).admin;
|
|
157
|
+
admin.setServer(this);
|
|
158
|
+
let manager = admin.get('os', this.config[name]);
|
|
159
|
+
this._useMiddleware(name, manager);
|
|
160
|
+
if (typeof manager.init === 'function') {
|
|
161
|
+
await manager.init();
|
|
162
|
+
}
|
|
163
|
+
this.in_adapters.add({ id: name, name: name, admin: manager });
|
|
164
|
+
} catch (error) {
|
|
165
|
+
this.log('error', `初始化适配器 ${name} 失败: ${error}`);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// 出站适配器
|
|
170
|
+
let out_adapters = this.config.out_adapters || [];
|
|
171
|
+
for (let name of out_adapters) {
|
|
172
|
+
try {
|
|
173
|
+
let admin = this.require(`mm_${name}`).admin;
|
|
174
|
+
admin.setServer(this);
|
|
175
|
+
let manager = admin.get('os', this.config[name]);
|
|
176
|
+
if (typeof manager.init === 'function') {
|
|
177
|
+
await manager.init();
|
|
178
|
+
}
|
|
179
|
+
this.out_adapters.add({ id: name, name: name, admin: manager });
|
|
180
|
+
} catch (error) {
|
|
181
|
+
this.log('error', `初始化适配器 ${name} 失败: ${error}`);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* 装配中间件:web 适配器挂载页面渲染中间件与静态资源插件,
|
|
188
|
+
* 使 HTML 页面以正确内容类型输出,并让注册到 mm_statics 的静态文件可被直接访问
|
|
189
|
+
* @param {string} name 适配器名称(web / socket / mqtt / websocket)
|
|
190
|
+
* @param {object} manager 适配器管理器实例
|
|
191
|
+
* @returns {void} 无返回值
|
|
192
|
+
* @private
|
|
193
|
+
*/
|
|
194
|
+
OS.prototype._useMiddleware = function (name, manager) {
|
|
195
|
+
if (name !== 'web' || !manager || typeof manager.use !== 'function') return;
|
|
196
|
+
try {
|
|
197
|
+
const { Render } = this.require('mm_render');
|
|
198
|
+
manager.use(new Render());
|
|
199
|
+
const statics_mod = this.require('mm_statics');
|
|
200
|
+
manager.use(new statics_mod.StaticsPlugin({ admin: statics_mod.admin }));
|
|
201
|
+
} catch (error) {
|
|
202
|
+
this.log('error', `装配渲染中间件失败: ${error.message}`);
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* 初始化工具
|
|
208
|
+
* @returns {void} 无返回值
|
|
209
|
+
*/
|
|
210
|
+
OS.prototype.initTools = async function () {
|
|
211
|
+
let tools = this.config.tools || [];
|
|
212
|
+
for (let name of tools) {
|
|
213
|
+
try {
|
|
214
|
+
let admin = this.require(`mm_${name}`).admin;
|
|
215
|
+
admin.setServer(this);
|
|
216
|
+
let manager = admin.get('os', this.config[name]);
|
|
217
|
+
if (typeof manager.init === 'function') {
|
|
218
|
+
await manager.init();
|
|
219
|
+
}
|
|
220
|
+
this.reg(name, manager);
|
|
221
|
+
} catch (error) {
|
|
222
|
+
this.log('error', `初始化工具 ${name} 失败: ${error}`);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* 初始化管理
|
|
229
|
+
* @returns {void} 无返回值
|
|
230
|
+
*/
|
|
231
|
+
OS.prototype.initAdmins = async function () {
|
|
232
|
+
let admins = this.config.admins || [];
|
|
233
|
+
for (let name of admins) {
|
|
234
|
+
try {
|
|
235
|
+
let admin = this.require(`mm_${name}`).admin;
|
|
236
|
+
admin.setServer(this);
|
|
237
|
+
let manager = admin.get('os', this.config[name]);
|
|
238
|
+
if (typeof manager.init === 'function') {
|
|
239
|
+
await manager.init();
|
|
240
|
+
}
|
|
241
|
+
this.reg(name, manager);
|
|
242
|
+
} catch (error) {
|
|
243
|
+
this.log('error', `初始化管理 ${name} 失败: ${error}`);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* 初始化存储
|
|
250
|
+
* @returns {void} 无返回值
|
|
251
|
+
*/
|
|
252
|
+
OS.prototype.initpStorage = async function () {
|
|
253
|
+
// 初始化缓存存储
|
|
254
|
+
let cacheAdmin = this.require('mm_cache').admin;
|
|
255
|
+
this._setAdminServer(cacheAdmin);
|
|
256
|
+
let cache = cacheAdmin.get('os', Object.assign({}, this.config.cache, { redis: this.config.redis, mongodb: this.config.mongodb, cachebase: this.config.cachebase }));
|
|
257
|
+
if (typeof cache.init === 'function') {
|
|
258
|
+
await cache.init();
|
|
259
|
+
}
|
|
260
|
+
this.cache = cache;
|
|
261
|
+
|
|
262
|
+
// 初始化数据库
|
|
263
|
+
let sqlAdmin = this.require('mm_sql').admin;
|
|
264
|
+
this._setAdminServer(sqlAdmin);
|
|
265
|
+
let sql = sqlAdmin.get('os', Object.assign({}, this.config.sql, { mysql: this.config.mysql, sqlite: this.config.sqlite, jsondb: this.config.jsondb }));
|
|
266
|
+
if (typeof sql.init === 'function') {
|
|
267
|
+
await sql.init();
|
|
268
|
+
}
|
|
269
|
+
this.sql = sql;
|
|
270
|
+
};
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* 设置管理器服务器:已设置时跳过,避免同一 Admin 实例重复绑定
|
|
274
|
+
* @param {object} admin 管理器工厂实例
|
|
275
|
+
*/
|
|
276
|
+
OS.prototype._setAdminServer = function (admin) {
|
|
277
|
+
if (!admin.getServer()) {
|
|
278
|
+
admin.setServer(this);
|
|
279
|
+
}
|
|
280
|
+
};
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* 初始化应用加载器
|
|
284
|
+
* @returns {void} 无返回值
|
|
285
|
+
*/
|
|
286
|
+
OS.prototype.initLoader = async function () {
|
|
287
|
+
let loader = new Loader(this.config.loader || {}, this);
|
|
288
|
+
loader.setLogger(this.logger);
|
|
289
|
+
await loader.init();
|
|
290
|
+
this.loader = loader;
|
|
291
|
+
};
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* 初始化事件总线
|
|
295
|
+
* @returns {void} 无返回值
|
|
296
|
+
*/
|
|
297
|
+
OS.prototype.initEventBus = function () {
|
|
298
|
+
let admin = this.require('mm_eventer').admin;
|
|
299
|
+
admin.setServer(this);
|
|
300
|
+
this.eventer = admin.get('os');
|
|
301
|
+
};
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* 启动入站适配器
|
|
305
|
+
* @returns {void} 无返回值
|
|
306
|
+
*/
|
|
307
|
+
OS.prototype._startInAdapters = async function () {
|
|
308
|
+
let in_adapters = this.in_adapters.list();
|
|
309
|
+
for (let item of in_adapters) {
|
|
310
|
+
try {
|
|
311
|
+
await item.admin.start();
|
|
312
|
+
this._printAddress(item);
|
|
313
|
+
} catch (error) {
|
|
314
|
+
this.log('error', `启动适配器 ${item.name} 失败: ${error}`);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
};
|
|
318
|
+
|
|
319
|
+
/**
|
|
320
|
+
* 启动出站适配器
|
|
321
|
+
* @returns {void} 无返回值
|
|
322
|
+
*/
|
|
323
|
+
OS.prototype._startOutAdapters = async function () {
|
|
324
|
+
let out_adapters = this.out_adapters.list();
|
|
325
|
+
for (let item of out_adapters) {
|
|
326
|
+
try {
|
|
327
|
+
await item.admin.start();
|
|
328
|
+
this._printAddress(item);
|
|
329
|
+
} catch (error) {
|
|
330
|
+
this.log('error', `启动适配器 ${item.name} 失败: ${error}`);
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
};
|
|
334
|
+
|
|
335
|
+
/**
|
|
336
|
+
* 启动适配器
|
|
337
|
+
* @returns {void} 无返回值
|
|
338
|
+
*/
|
|
339
|
+
OS.prototype.start = async function () {
|
|
340
|
+
// 启动入站适配器
|
|
341
|
+
await this._startInAdapters();
|
|
342
|
+
// 启动出站适配器
|
|
343
|
+
await this._startOutAdapters();
|
|
344
|
+
|
|
345
|
+
// 启动缓存存储
|
|
346
|
+
await this.cache.start();
|
|
347
|
+
// 启动数据库
|
|
348
|
+
await this.sql.start();
|
|
349
|
+
|
|
350
|
+
// 启动应用
|
|
351
|
+
if (this.loader) {
|
|
352
|
+
await this.loader.start();
|
|
353
|
+
}
|
|
354
|
+
};
|
|
355
|
+
|
|
356
|
+
/**
|
|
357
|
+
* 打印适配器监听地址
|
|
358
|
+
* @param {object} item 适配器存储项,含 name 与 admin
|
|
359
|
+
*/
|
|
360
|
+
OS.prototype._printAddress = function (item) {
|
|
361
|
+
let { host, port } = item.admin.config || {};
|
|
362
|
+
if (!host || host === '0.0.0.0' || host === '::') {
|
|
363
|
+
host = 'localhost';
|
|
364
|
+
}
|
|
365
|
+
let protocol = { web: 'http', websocket: 'ws', socket: 'tcp', mqtt: 'mqtt' }[item.name] || item.name;
|
|
366
|
+
this.log('info', `适配器 ${item.name} 已启动: ${protocol}://${host}:${port}`);
|
|
367
|
+
};
|
|
368
|
+
|
|
369
|
+
module.exports = OS;
|
package/package.json
CHANGED
|
@@ -1,84 +1,55 @@
|
|
|
1
|
-
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
"devDependencies": {
|
|
57
|
-
"@types/jest": "^30.0.0",
|
|
58
|
-
"eslint-formatter-table": "^7.32.1",
|
|
59
|
-
"eslint-plugin-jsdoc": "^64.4.0",
|
|
60
|
-
"jest": "^30.5.1",
|
|
61
|
-
"mm_eslint": "^1.7.7"
|
|
62
|
-
},
|
|
63
|
-
"repository": {
|
|
64
|
-
"type": "git",
|
|
65
|
-
"url": "git+https://gitee.com/qiuwenwu91/mm_os.git"
|
|
66
|
-
},
|
|
67
|
-
"files": [
|
|
68
|
-
"index.js",
|
|
69
|
-
"os.js",
|
|
70
|
-
"server.js",
|
|
71
|
-
"com.js",
|
|
72
|
-
"README.md",
|
|
73
|
-
"README_EN.md",
|
|
74
|
-
"LICENSE",
|
|
75
|
-
"adapter/",
|
|
76
|
-
"com/",
|
|
77
|
-
"common/",
|
|
78
|
-
"core/",
|
|
79
|
-
"ulits/",
|
|
80
|
-
"tcp.js",
|
|
81
|
-
"software.js",
|
|
82
|
-
"ai.js"
|
|
83
|
-
]
|
|
84
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "mm_os",
|
|
3
|
+
"version": "5.0.0",
|
|
4
|
+
"description": "这是OS系统",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://gitee.com/qiuwenwu91/mm_os.git"
|
|
8
|
+
},
|
|
9
|
+
"license": "ISC",
|
|
10
|
+
"author": "qww",
|
|
11
|
+
"type": "commonjs",
|
|
12
|
+
"main": "index.js",
|
|
13
|
+
"files": [
|
|
14
|
+
"index.js",
|
|
15
|
+
"lib",
|
|
16
|
+
"README.md"
|
|
17
|
+
],
|
|
18
|
+
"directories": {
|
|
19
|
+
"example": "example",
|
|
20
|
+
"lib": "lib"
|
|
21
|
+
},
|
|
22
|
+
"scripts": {
|
|
23
|
+
"test": "node test.js",
|
|
24
|
+
"demo": "node --preserve-symlinks example/demo.js",
|
|
25
|
+
"api:test": "node api_test.js"
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"markdown": "^0.5.0",
|
|
29
|
+
"mm_app": "^1.0.0",
|
|
30
|
+
"mm_cache": "^1.5.4",
|
|
31
|
+
"mm_corejs": "^1.1.4",
|
|
32
|
+
"mm_es6_to_amd": "^1.5.9",
|
|
33
|
+
"mm_event": "^2.2.0",
|
|
34
|
+
"mm_file": "^1.0.0",
|
|
35
|
+
"mm_handle": "^1.0.0",
|
|
36
|
+
"mm_jsondb": "^1.0.0",
|
|
37
|
+
"mm_logger": "^1.0.0",
|
|
38
|
+
"mm_mongodb": "^2.0.3",
|
|
39
|
+
"mm_mqtt_server": "^1.0.2",
|
|
40
|
+
"mm_mysql": "^2.5.6",
|
|
41
|
+
"mm_param": "^1.1.0",
|
|
42
|
+
"mm_pendant": "^1.1.0",
|
|
43
|
+
"mm_plugin": "^1.0.0",
|
|
44
|
+
"mm_redis": "^2.1.7",
|
|
45
|
+
"mm_render": "^1.0.0",
|
|
46
|
+
"mm_socket_server": "^1.0.2",
|
|
47
|
+
"mm_sql": "^1.8.0",
|
|
48
|
+
"mm_sqlite": "^1.5.5",
|
|
49
|
+
"mm_statics": "^1.9.0",
|
|
50
|
+
"mm_timer": "^1.1.0",
|
|
51
|
+
"mm_tpl": "^2.7.2",
|
|
52
|
+
"mm_web_server": "^1.0.2",
|
|
53
|
+
"mm_websocket_server": "^1.0.2"
|
|
54
|
+
}
|
|
55
|
+
}
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2025 Admin
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|