update webrtc add switch track

This commit is contained in:
vdalex
2023-03-20 12:36:13 +03:00
parent d230786dc1
commit ec315352fb
3 changed files with 634 additions and 612 deletions

File diff suppressed because one or more lines are too long

49
dist/index.html vendored
View File

@@ -5,7 +5,8 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>RTSPtoWEBPlayer demo</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<script src="RTSPtoWEBPlayer.js"></script>
</head>
<body>
@@ -15,40 +16,56 @@
<div class="col-12">
<div class="input-group mb-3">
<input type="text" class="form-control" placeholder="url link" id="link"
value=""/>
value=""/>
<button class="btn btn-outline-secondary" type="button" onclick="play()">PLAY</button>
<button class="btn btn-outline-secondary" type="button" onclick="stop()">STOP</button>
</div>
<h6 class="text-center mb-3"><small><a href="#" id="outerLink"></a></small></h6>
</div>
<div class="col-12">
<div id="player"></div>
</div>
<div id="control"></div>
</div>
</div>
</body>
<script>
const options={
const options = {
parentElement: document.getElementById('player'),
debug: true
autoplay: true,
debug: true,
getPresets: (video, audio) => {
document.getElementById("control").innerHTML = '';
for (let i = 0; i < video.length; i++) {
const button = document.createElement('button');
button.onclick = () => player.switchStream(i);
button.innerHTML = video[i].idx;
document.getElementById("control").append(button);
}
}
};
const player=new RTSPtoWEBPlayer(options);
const play = ()=>{
const link=document.getElementById("link").value;
const url=new URL(window.location.href);
if(link!==''){
const player = new RTSPtoWEBPlayer(options);
const play = () => {
const link = document.getElementById("link").value;
const url = new URL(window.location.href);
if (link !== '') {
player.load(link);
outerLink.innerHTML=`${url.origin+url.pathname+url.search}#${link}`;
outerLink.setAttribute('href',`${url.origin+url.pathname+url.search}#${link}`)
outerLink.innerHTML = `${url.origin + url.pathname + url.search}#${link}`;
outerLink.setAttribute('href', `${url.origin + url.pathname + url.search}#${link}`)
}
}
const stop = () => {
player.destroy();
}
if(window.location.hash){
try{
const href=new URL(window.location.hash.substr(1));
document.getElementById("link").value=window.location.hash.substr(1);
if (window.location.hash) {
try {
const href = new URL(window.location.hash.substr(1));
document.getElementById("link").value = window.location.hash.substr(1);
play();
}catch (e){
} catch (e) {
console.log(e);
}

File diff suppressed because it is too large Load Diff