Skip to content

Commit

Permalink
Allow multiple tasks per same stream
Browse files Browse the repository at this point in the history
  • Loading branch information
Llorx authored Jun 8, 2019
1 parent 7f1639e commit 2768a22
Showing 1 changed file with 51 additions and 15 deletions.
66 changes: 51 additions & 15 deletions node_relay_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,18 @@ class NodeRelayServer {
let session = new NodeRelaySession(conf);
session.id = id;
session.on('end', (id) => {
this.dynamicSessions.delete(id);
let list = this.dynamicSessions.get(id);
if (list.indexOf(session) > -1) {
list.splice(list.indexOf(session), 1);
if (list.length == 0) {
this.dynamicSessions.delete(id);
}
}
});
this.dynamicSessions.set(id, session);
if (!this.dynamicSessions.has(id)) {
this.dynamicSessions.set(id, []);
}
this.dynamicSessions.get(id).push(session);
session.run();
Logger.log('[Relay dynamic pull] start', id, conf.inPath, ' to ', conf.ouPath);
return id;
Expand All @@ -102,9 +111,18 @@ class NodeRelayServer {
let session = new NodeRelaySession(conf);
session.id = id;
session.on('end', (id) => {
this.dynamicSessions.delete(id);
let list = this.dynamicSessions.get(id);
if (list.indexOf(session) > -1) {
list.splice(list.indexOf(session), 1);
if (list.length == 0) {
this.dynamicSessions.delete(id);
}
}
});
this.dynamicSessions.set(id, session);
if (!this.dynamicSessions.has(id)) {
this.dynamicSessions.set(id, []);
}
this.dynamicSessions.get(id).push(session);
session.run();
Logger.log('[Relay dynamic push] start', id, conf.inPath, ' to ', conf.ouPath);
}
Expand All @@ -127,20 +145,29 @@ class NodeRelayServer {
let session = new NodeRelaySession(conf);
session.id = id;
session.on('end', (id) => {
this.dynamicSessions.delete(id);
let list = this.dynamicSessions.get(id);
if (list.indexOf(session) > -1) {
list.splice(list.indexOf(session), 1);
if (list.length == 0) {
this.dynamicSessions.delete(id);
}
}
});
this.dynamicSessions.set(id, session);
if (!this.dynamicSessions.has(id)) {
this.dynamicSessions.set(id, []);
}
this.dynamicSessions.get(id).push(session);
session.run();
Logger.log('[Relay dynamic pull] start', id, conf.inPath, ' to ', conf.ouPath);
}
}
}

onDonePlay(id, streamPath, args) {
let session = this.dynamicSessions.get(id);
let list = this.dynamicSessions.get(id);
let publisher = context.sessions.get(context.publishers.get(streamPath));
if (session && publisher.players.size == 0) {
session.end();
if (list && publisher.players.size == 0) {
list.slice().forEach(session => session.end());
}
}

Expand All @@ -158,13 +185,22 @@ class NodeRelayServer {
let hasApp = conf.edge.match(/rtmp:\/\/([^\/]+)\/([^\/]+)/);
conf.ffmpeg = this.config.relay.ffmpeg;
conf.inPath = `rtmp://127.0.0.1:${this.config.rtmp.port}${streamPath}`;
conf.ouPath = hasApp ? `${conf.edge}/${stream}` : `${conf.edge}${streamPath}`;
conf.ouPath = conf.appendName === false ? conf.edge : (hasApp ? `${conf.edge}/${stream}` : `${conf.edge}${streamPath}`);
let session = new NodeRelaySession(conf);
session.id = id;
session.on('end', (id) => {
this.dynamicSessions.delete(id);
let list = this.dynamicSessions.get(id);
if (list.indexOf(session) > -1) {
list.splice(list.indexOf(session), 1);
if (list.length == 0) {
this.dynamicSessions.delete(id);
}
}
});
this.dynamicSessions.set(id, session);
if (!this.dynamicSessions.has(id)) {
this.dynamicSessions.set(id, []);
}
this.dynamicSessions.get(id).push(session);
session.run();
Logger.log('[Relay dynamic push] start', id, conf.inPath, ' to ', conf.ouPath);
}
Expand All @@ -173,9 +209,9 @@ class NodeRelayServer {
}

onDonePublish(id, streamPath, args) {
let session = this.dynamicSessions.get(id);
if (session) {
session.end();
let list = this.dynamicSessions.get(id);
if (list) {
list.slice().forEach(session => session.end());
}

for (session of this.staticSessions.values()) {
Expand Down

0 comments on commit 2768a22

Please sign in to comment.