加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
node_ipc_session.js 1.54 KB
一键复制 编辑 原始数据 按行查看 历史
illuspas 提交于 2018-06-22 14:14 . All platforms use TCP socket for ipc
//
// 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
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化