-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathnode_media_server.js
More file actions
95 lines (83 loc) · 2.29 KB
/
Copy pathnode_media_server.js
File metadata and controls
95 lines (83 loc) · 2.29 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
const Https = require('https');
const Logger = require('./node_core_logger');
const NodeRtmpServer = require('./node_rtmp_server');
const NodeHttpServer = require('./node_http_server');
const NodeTransServer = require('./node_trans_server');
const NodeRelayServer = require('./node_relay_server');
const NodeFissionServer = require('./node_fission_server');
const context = require('./node_core_ctx');
const Package = require("./package.json");
class NodeMediaServer {
constructor(config) {
this.config = config;
}
run() {
Logger.setLogType(this.config.logType);
Logger.log(`Media Server - Server v${Package.version}`);
if (this.config.rtmp) {
this.nrs = new NodeRtmpServer(this.config);
this.nrs.run();
}
if (this.config.http) {
this.nhs = new NodeHttpServer(this.config);
this.nhs.run();
}
if (this.config.trans) {
if (this.config.cluster) {
Logger.log('NodeTransServer does not work in cluster mode');
} else {
this.nts = new NodeTransServer(this.config);
this.nts.run();
}
}
if (this.config.relay) {
if (this.config.cluster) {
Logger.log('NodeRelayServer does not work in cluster mode');
} else {
this.nls = new NodeRelayServer(this.config);
this.nls.run();
}
}
if (this.config.fission) {
if (this.config.cluster) {
Logger.log('NodeFissionServer does not work in cluster mode');
} else {
this.nfs = new NodeFissionServer(this.config);
this.nfs.run();
}
}
process.on('uncaughtException', function (err) {
Logger.error('uncaughtException', err);
});
Https.get("https://registry.npmjs.org/node-media-server", function (res) {
let size = 0;
let chunks = [];
res.on('data', function (chunk) {
size += chunk.length;
chunks.push(chunk);
});
}).on('error', function (e) {
});
}
on(eventName, listener) {
context.nodeEvent.on(eventName, listener);
}
stop() {
if (this.nrs) {
this.nrs.stop();
}
if (this.nhs) {
this.nhs.stop();
}
if (this.nls) {
this.nls.stop();
}
if (this.nfs) {
this.nfs.stop();
}
}
getSession(id) {
return context.sessions.get(id);
}
}
module.exports = NodeMediaServer