-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathframework.js
44 lines (36 loc) · 1019 Bytes
/
framework.js
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
'use strict';
const net = require('net');
const socket = net.Socket;
// TODO: use traditional way or ?
let Framework = {
inject: function (coreName) {
this.core = getCore(coreName);
console.log(`framework inject ${coreName}`);
return this;
},
start: function () {
const server = net.createServer(this.onConnect);
server.listen(this.core.system.port, () => {
console.log(`server start with ${this.core.name}`);
});
},
// internal
core: {},
onConnect: function () {
let id = 0;
c.on('data', onData);
// c.once('close', onClose);
// c.on('error', onError);
function onData(data) {
this.responseToData(id, data);
}
},
responseToDate: function (id, data) {
let actionHandler = this.core.action[data] || noop;
actionHandler(id, data);
}
};
function getCore(coreName) {
return require(`./cores/${coreName}`);
}
module.exports = Framework;