Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed multiple dynamic relays #472

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions src/node_relay_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,14 @@ class NodeRelayServer {
}
let regRes = /\/(.*)\/(.*)/gi.exec(streamPath);
let [app, stream] = _.slice(regRes, 1);
let i = this.config.relay.tasks.length;
while (i--) {
let conf = this.config.relay.tasks[i];

let conf = this.config.relay.tasks.find((config) => config.name === stream);
if (conf) {
let isPull = conf.mode === 'pull';
if (isPull && app === conf.app && !context.publishers.has(streamPath)) {
let hasApp = conf.edge.match(/rtmp:\/\/([^\/]+)\/([^\/]+)/);
conf.ffmpeg = this.config.relay.ffmpeg;
conf.inPath = hasApp ? `${conf.edge}/${stream}` : `${conf.edge}${streamPath}`;
conf.inPath = hasApp ? `${conf.edge}/${stream}` : `${conf.edge}`;
conf.ouPath = `rtmp://127.0.0.1:${this.config.rtmp.port}${streamPath}`;
if(Object.keys(args).length > 0) {
conf.inPath += '?';
Expand All @@ -142,11 +142,12 @@ class NodeRelayServer {
session.run();
Logger.log('[relay dynamic pull] start id=' + id, conf.inPath, 'to', conf.ouPath);
}

}
}

onDonePlay(id, streamPath, args) {
let session = this.dynamicSessions.get(id);
let session = Array.from(this.dynamicSessions, ([name, value]) => value ).find((session)=>{return session.conf.name === streamPath.split('/')[2]});
let publisher = context.sessions.get(context.publishers.get(streamPath));
if (session && publisher.players.size == 0) {
session.end();
Expand Down
8 changes: 8 additions & 0 deletions src/node_rtmp_session.js
Original file line number Diff line number Diff line change
Expand Up @@ -1079,13 +1079,21 @@ class NodeRtmpSession {
this.isPublishing = true;

this.sendStatusMessage(this.publishStreamId, 'status', 'NetStream.Publish.Start', `${this.publishStreamPath} is now published.`);
let idlePlayerFound = false;
for (let idlePlayerId of context.idlePlayers) {
let idlePlayer = context.sessions.get(idlePlayerId);
if (idlePlayer && idlePlayer.playStreamPath === this.publishStreamPath) {
idlePlayer.onStartPlay();
context.idlePlayers.delete(idlePlayerId);
idlePlayerFound = true;
}
}
const streamMode = this.config.relay?.tasks.find((task)=>task.name === invokeMessage.streamName)?.mode;
if (!idlePlayerFound && streamMode === 'pull') {
// This RTMP session is doesn't have any idle players waiting for a video feed and this RTMP session was created in "pull" mode (not "static"). It can be stopped.
// This may occur when a socket connection is broken before the stream can finish publishing.
this.stop();
}
context.nodeEvent.emit('postPublish', this.id, this.publishStreamPath, this.publishArgs);
}
}
Expand Down