From 8ee91d705b9419e6292ff4e70e915f5ce814846f Mon Sep 17 00:00:00 2001 From: johzzy Date: Sun, 9 Jul 2023 13:24:52 +0800 Subject: [PATCH] feat: support auto fill streamUrl by webrtc page(#2646) feat: support auto fill streamUrl by webrtc page, like "https://your-host/webrtc?app=live&stream=hello&type=push" --- www/webrtc/index.html | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/www/webrtc/index.html b/www/webrtc/index.html index 555fc5b5..269ae9b2 100644 --- a/www/webrtc/index.html +++ b/www/webrtc/index.html @@ -95,21 +95,28 @@ var ishttps = 'https:' == document.location.protocol ? true : false var isLocal = "file:" == document.location.protocol ? true : false - var url = document.location.protocol+"//"+window.location.host+"/index/api/webrtc?app=live&stream=test&type=play" + const searchParams = new URL(document.location.href).searchParams; + let type = searchParams.get('type'); + if (!['echo','push','play'].includes(type)) { + type = 'play'; + } + recvOnly = type === 'play'; + const apiPath = `/index/api/webrtc?app=${searchParams.get('app') ?? 'live'}&stream=${searchParams.get('stream') ?? 'test'}&type=${type}`; if(!ishttps && !isLocal){ alert('本demo需要在https的网站访问 ,如果你要推流的话(this demo must access in site of https if you want push stream)') } + + const apiHost = isLocal ? "http://127.0.0.1" : `${document.location.protocol}//${window.location.host}`; + var url = apiHost + apiPath; - if(isLocal){ - url = "http://127.0.0.1"+"/index/api/webrtc?app=live&stream=test&type=play" - } document.getElementById('streamUrl').value = url - document.getElementsByName("method").forEach((el,idx)=>{ - el.onclick=function(e){ + document.getElementsByName("method").forEach((el,idx) => { + el.checked = el.value === type; + el.onclick = function(e) { let url = new URL(document.getElementById('streamUrl').value); - url.searchParams.set("type",el.value) + url.searchParams.set("type",el.value); document.getElementById('streamUrl').value = url.toString() if(el.value == "play"){ @@ -275,7 +282,7 @@ } function fillStreamList(json) { clearStreamList(); - if (json.code != 0) { + if (json.code != 0 || !json.data) { return; } let ss = {};