How to push relay to facebook and youtube with dynamic relay url
See original GitHub issueFirst of all, thanks for your incredible job.
I have created a live server where each user has your own live url like this:
/live/9p5oPcRzI
and to work with facebook and youtube rtmp I had to modify node-media-server on node_relay_server.js to remove “stream” on “conf.ouPath”:
it it works pretty well to stream to youtube and facebook at same time
onPostPublish(id, streamPath, args) {
if (!this.config.relay.tasks) {
return;
}
console.log("AKI", streamPath);
let regRes = /\/(.*)\/(.*)/gi.exec(streamPath);
let [app, stream] = _.slice(regRes, 1);
console.log(stream);
let i = this.config.relay.tasks.length;
while (i--) {
let conf = this.config.relay.tasks[i];
let isPush = conf.mode === 'push';
if (isPush && app === conf.app) {
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}` : `${conf.edge}`;
let session = new NodeRelaySession(conf);
session.id = id;
session.on('end', (id) => {
this.dynamicSessions.delete(id);
});
this.dynamicSessions.set(id, session);
session.run();
Logger.log('[Relay dynamic push] start', id, conf.inPath, ' to ', conf.ouPath);
}
}
}
and in my project config
relay: {
ffmpeg: '/usr/bin/ffmpeg',
tasks: [
{
app: 'live',
mode: 'push',
edge: 'rtmp://a.rtmp.youtube.com/live2/keyyoutube',
},
{
app: 'live',
mode: 'push',
edge: 'rtmps://rtmp-pc.facebook.com:443/rtmp/keyface',
}
]
},
but it is too said because all users will relay to the same url.
but what I want is each user having your own rtmp list and for instance those live:
/live/9p5oPcRzI
relay to:
rtmp://a.rtmp.youtube.com/live2/firstuserkeyyoutube
rtmps://rtmp-pc.facebook.com:443/rtmp/firstuserkeyface
and to another live:
/live/1p3oPdRas
relay to:
rtmp://a.rtmp.youtube.com/live2/seconduserkeyyoutube
rtmps://rtmp-pc.facebook.com:443/rtmp/seconduserkeyface
Without need restart the server when user add new one
How can I pass those parameters from de user?
I’m almost sure that I can use it:
nms.on('postPublish', async (id, StreamPath, args) => {
to get from my database the user’s relay
Issue Analytics
- State:
- Created 4 years ago
- Comments:30 (2 by maintainers)
Top GitHub Comments
@kkrishnan90 - I have done some more testing and i would like to say a big thank you for your update on this. I tested this from my https server with valid certificates and for sure it worked, dynamically sending to FB live and Youtube. When doing the POST call, your arguments that you mentioned above are not correct.
When running this call i received a response of BAD REQUEST
URL: http://<server-ip>:<server-port>/api/relay/push HTTP METHOD: POST JSON REQUEST BODY:
{ app : 'live', mode : 'push', vc : 'libx264', ac : 'aac', edge : 'rtmp://127.0.0.1:1987/rtmp/<fb-stream-key>', appendName : false }
I changed the values as you can see below and the response comes back “OK”. “mode” to “name” , name being the steam key. “edge” to “url”, url being the place you want to push the stream.
URL: http://<server-ip>:<server-port>/api/relay/push HTTP METHOD: POST JSON REQUEST BODY:
{ app : 'live', name : 'push', vc : 'libx264', ac : 'aac', url : 'rtmp://127.0.0.1:1987/rtmp/<fb-stream-key>', appendName : false }
I would love to know a bit more about how this works and how you achieved this 😃.
Thank you @kkrishnan90 I’m not the maintainer @illuspas should review https://github.com/illuspas/Node-Media-Server/pull/361