forked from illuspas/Node-Media-Server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
node_ipc_session.js
61 lines (45 loc) · 1.54 KB
/
node_ipc_session.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
//
// Created by Mingliang Chen on 18/6/19.
// illuspas[a]gmail.com
// Copyright (c) 2018 Nodemedia. All rights reserved.
//
const Logger = require('./node_core_logger');
const NodeRtmpClient = require('./node_rtmp_client');
class NodeIpcSession {
constructor(streamPath, pullPort, pushPort) {
this.streamPath = streamPath;
this.app = streamPath.split('/')[1];
this.stream = streamPath.split('/')[2];
this.pullPort = pullPort;
this.pullRtmp = new NodeRtmpClient(`rtmp://127.0.0.1:${pullPort}${streamPath}`);
this.pushPort = pushPort;
this.pushRtmp = new NodeRtmpClient(`rtmp://127.0.0.1:${pushPort}${streamPath}`);
this.isStart = false;
Logger.debug(`[rtmp ipc] Create new ipc stream ${streamPath} from port=${pullPort} to port=${pushPort}`);
}
run() {
this.isStart = true;
this.pushRtmp.on('status', (info) => {
if (info.code === 'NetStream.Publish.Start') {
this.pullRtmp.startPull();
}
});
this.pullRtmp.on('audio', (audioData, timestamp) => {
this.pushRtmp.pushAudio(audioData, timestamp);
});
this.pullRtmp.on('video', (videoData, timestamp) => {
this.pushRtmp.pushVideo(videoData, timestamp);
});
this.pullRtmp.on('script', (scriptData, timestamp) => {
this.pushRtmp.pushScript(scriptData, timestamp);
});
this.pushRtmp.startPush();
}
stop() {
this.isStart = false;
this.pullRtmp.stop();
this.pushRtmp.stop();
Logger.debug(`[rtmp ipc] Stop ipc stream ${this.streamPath}`);
}
}
module.exports = NodeIpcSession