forked from illuspas/Node-Media-Server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnode_media_server.js
59 lines (47 loc) · 1.3 KB
/
node_media_server.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
//
// Created by Mingliang Chen on 17/8/1.
// illuspas[a]gmail.com
// Copyright (c) 2017 Nodemedia. All rights reserved.
//
const NodeRtmpServer = require('./node_rtmp_server');
const NodeHttpServer = require('./node_http_server');
const NodeCoreUtils = require('./node_core_utils');
const channels = require('./api/routes/streams');
class NodeMediaServer {
constructor(config) {
this.config = config;
this.sessions = new Map();
this.publishers = new Map();
this.idlePlayers = new Set();
this.nodeEvent = NodeCoreUtils.nodeEvent;
}
run() {
if (this.config.rtmp) {
this.nrs = new NodeRtmpServer(this.config, this.sessions, this.publishers, this.idlePlayers);
this.nrs.run();
}
if (this.config.http || this.config.https) {
this.nhs = new NodeHttpServer(this.config, this.sessions, this.publishers, this.idlePlayers);
this.nhs.run();
if (this.config.socket) {
this.nhs.runSocket();
}
this.nhs.expressApp.use('/api/streams', channels(this));
}
}
on(eventName, listener) {
this.nodeEvent.on(eventName, listener);
}
stop() {
if (this.nrs) {
this.nrs.stop();
}
if (this.nhs) {
this.nhs.stop();
}
}
getSession(id) {
return this.sessions.get(id);
}
}
module.exports = NodeMediaServer