From 7e331d5f826bcee5ac9c71f005974bee4bf2ec62 Mon Sep 17 00:00:00 2001 From: Jan Stabenow Date: Fri, 21 Oct 2022 22:15:36 +0200 Subject: [PATCH] Mod simplifies the setup of Restreamer-to-Restreamer connections --- CHANGELOG.md | 1 + src/misc/BoxText.js | 6 +- src/views/Publication/Services/Core.js | 199 ++++++++++++++++--------- 3 files changed, 136 insertions(+), 70 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 81a52dd..0c59a15 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - Add scale filter to non-hwaccel encoders - Add PeerTube and Media Network to publication services (plattforms, software) +- Mod simplifies the setup of Restreamer-to-Restreamer connections - Add reset button to hide a player logo (datarhei/restreamer#431) - Mod adds Istafeed.me as StreamKey service to Instagram's publishing service - Mod renames "Low delay" to "Low latency (buffer)" and set false as default (requires more feedback) diff --git a/src/misc/BoxText.js b/src/misc/BoxText.js index 4bb8c3b..9423eb9 100644 --- a/src/misc/BoxText.js +++ b/src/misc/BoxText.js @@ -47,8 +47,8 @@ export default function Component(props) { return ( v2.0 + if (settings.base_url && !settings.v2_protocol) { + if (settings.base_url.length !== 0) { + settings.v2_protocol = settings.protocol; + settings.v2_host = settings.base_url; + if (settings.protocol === 'srt') { + settings.v2_address = + `srt://${settings.base_url}?mode=caller&transtype=live&streamid=#!:m=publish,r=${settings.stream_name}` + + (settings.token.length !== 0 ? `,token=${settings.token}` : '') + + (settings.srt_passphrase.length !== 0 ? `&passphrase=${settings.srt_passphrase}` : ''); + settings.v2_stream_id = `#!:m=publish,r=${settings.stream_name}` + (settings.token.length !== 0 ? `,token=${settings.token}` : ''); + settings.v2_passphrase = settings.srt_passphrase; + } else { + settings.v2_address = + `${settings.protocol}://${settings.base_url}/` + + (settings.app_path.length !== 0 ? `${settings.app_path}/` : '') + + settings.stream_name + + (settings.token.length !== 0 ? `?token=${settings.token}` : ''); + settings.v2_stream_id = `/` + (settings.app_path.length !== 0 ? `${settings.app_path}/` : '') + settings.stream_name; + settings.v2_token = settings.token; + } + } + settings.base_url = ''; + settings.app_path = ''; + settings.stream_name = ''; + settings.token = ''; + settings.srt_passphrase = ''; + } + const initSettings = { - protocol: 'rtmp', - base_url: '', - app_path: 'live', - stream_name: '', - token: '', - srt_passphrase: '', + v2_address: '', + v2_protocol: '', + v2_host: '', + v2_stream_id: '', + v2_token: '', + v2_passphrase: '', ...settings, }; @@ -71,6 +100,45 @@ function Service(props) { settings[what] = value; + const url = urlparser(value); + + if (url.protocol === 'rtmp:' || url.protocol === 'rtmps:' || url.protocol === 'srt:') { + settings.v2_protocol = url.protocol.split(':')[0]; + settings.v2_host = url.host; + if (url.protocol === 'srt:') { + if (url.hash) { + if (url.hash.includes('passphrase=')) { + settings.v2_stream_id = url.hash.split('&')[0]; + settings.v2_passphrase = url.hash.split('&passphrase=')[1].split('&')[0]; + } else { + settings.v2_stream_id = url.hash.split('&')[0]; + settings.v2_passphrase = ''; + } + } else { + settings.v2_stream_id = ''; + settings.v2_passphrase = ''; + } + } else { + settings.v2_stream_id = url.pathname; + if (url.query) { + if (url.query.includes('token=')) { + settings.v2_token = url.query.split('token=')[1].split('&')[0]; + } else { + settings.v2_token = ''; + } + } else { + settings.v2_token = ''; + } + } + } else { + settings.v2_protocol = ''; + settings.v2_host = ''; + settings.v2_port = ''; + settings.v2_streamid = ''; + settings.v2_token = ''; + settings.v2_passphrase = ''; + } + const output = createOutput(settings); props.onChange([output], settings); @@ -82,19 +150,11 @@ function Service(props) { options: null, }; - if (settings.protocol !== 'srt') { - output.address = - `${settings.protocol}://${settings.base_url}/` + - (settings.app_path.length !== 0 ? `${settings.app_path}/` : '') + - settings.stream_name + - (settings.token.length !== 0 ? `?token=${settings.token}` : ''); - output.options = ['-f', 'flv']; - } else { - output.address = - `srt://${settings.base_url}?mode=caller&transtype=live&streamid=#!:m=publish,r=${settings.stream_name}` + - (settings.token.length !== 0 ? `,token=${settings.token}` : '') + - (settings.srt_passphrase.length !== 0 ? `&passphrase=${settings.srt_passphrase}` : ''); + output.address = settings.v2_address; + if (settings.v2_address.includes('srt://')) { output.options = ['-bsf:v', 'dump_extra', '-f', 'mpegts']; + } else { + output.options = ['-f', 'flv']; } return output; @@ -102,57 +162,60 @@ function Service(props) { return ( - - - - + Address} - placeholder="core-address:port" - value={settings.base_url} - onChange={handleChange('base_url')} + label={Target address} + value={settings.v2_address} + onChange={handleChange('v2_address')} /> - {settings.protocol !== 'srt' && ( - - App} value={settings.app_path} onChange={handleChange('app_path')} /> - - )} - - Stream name} - value={settings.stream_name} - onChange={handleChange('stream_name')} - placeholder={'streamId'} - /> - - - Security token} value={settings.token} onChange={handleChange('token')} /> - - {settings.protocol === 'srt' && ( - - Security passphrase} - value={settings.srt_passphrase} - onChange={handleChange('srt_passphrase')} - disabled={settings.protocol !== 'srt'} - /> - - )} - - - GET - + + + {!settings.v2_address && ( + + + Restreamer instructions: + +
+ 1. Switch to the interface of the target Restreamer. +
+ 2. Create a new channel and select RTMP or SRT server. +
+ 3. Copy the URL and paste it in the "Target address" field. +
+ )} + {settings.v2_address && ( + + + Protocol: + {' '} + {settings.v2_protocol} +
+ + Address: + {' '} + {settings.v2_host} +
+ Stream ID: {settings.v2_stream_id} +
+ {settings.v2_token && ( + + Token: {settings.v2_token} + + )} + {settings.v2_passphrase && ( + + + Passphrase: + {' '} + {settings.v2_passphrase} + + )} +
+ )} +
);