-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtlsocket.js
61 lines (50 loc) · 1.65 KB
/
tlsocket.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
const { get_env_config, load_env_config } = require("./conf/env_config");
//加载环境变量
load_env_config();
//加载环境变量完毕后,加载配置
const conf = get_env_config()
//打印logo
const { tlConsole, tlConsoleSocketIcon, tlConsoleError } = require("./src/utils/utils");
tlConsoleSocketIcon()
const http = require('http'); // http
const https = require('https');
const socketIO = require('socket.io');
const fs = require('fs');
const { dbInit } = require("./src/tables/db"); //db
const { redisInit } = require("./src/utils/cache/redis"); //redis
const socket = require("./src/socket/index");
process.on('unhandledRejection', (reason, promise) => {
tlConsoleError('Unhandled Rejection reason:', reason);
})
async function start(){
// Socket连接监听
let io = null;
if(process.env.tl_rtc_app_env_mode == 'http'){
io = socketIO.listen(http.createServer().listen(conf.socket_port));
}else{
let options = {
key: fs.readFileSync('./conf/keys/server.key'),
cert: fs.readFileSync('./conf/keys/server.crt')
}
io = socketIO.listen(
https.createServer(options).listen(conf.socket_port)
);
}
tlConsole("db init start ...")
if (!conf.db_open) {// 没开db
tlConsole("db not open ...")
}else{
await dbInit();
}
tlConsole("redis init start ...")
await redisInit();
tlConsole("redis init done ...")
socket.execute(io)
tlConsole("socket init done ...")
tlConsole(process.env.tl_rtc_app_env_mode, "socket ", " server listen on", conf.socket_port, "successful");
}
try{
start();
}catch(e){
tlConsoleError(e)
}