Skip to content

Commit

Permalink
feat webui add stop
Browse files Browse the repository at this point in the history
  • Loading branch information
a-wing committed Jan 7, 2024
1 parent d64df81 commit 692b154
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
29 changes: 27 additions & 2 deletions assets/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,20 @@
<option value="240">240px</option>
</select></section>
<section>SVC Layer: <select id="whip-layer-select"></select></section>
<button onclick="startWhip()"> WebRTC Start Whip</button>
<section>
<button onclick="startWhip()">Start</button>
<button id="whip-button-stop">Stop</button>
</section>
<br />Logs: <br /><div id="whip-logs"></div>
</fieldset>

<fieldset>
<legend>WHEP</legend>
<section>SVC Layer: <select disabled id="whep-layer-select"></select></section>
<button onclick="startWhep()"> WebRTC Start Whep</button>
<section>
<button onclick="startWhep()">Start</button>
<button id="whep-button-stop">Stop</button>
</section>
<br />Logs: <br /><div id="whep-logs"></div>
</fieldset>
</div>
Expand Down Expand Up @@ -137,6 +143,7 @@
const idWhipAudioDevice = "whip-audio-device"
const idWhipVideoDevice = "whip-video-device"
const idWhipVideoWidthMax = "whip-video-width-max"
const idWhipButtonStop = "whip-button-stop"

initLayerSelect(idWhipLayerSelect, [
{ value: "f", text: "Base" },
Expand Down Expand Up @@ -217,12 +224,24 @@
logWhip(e)
}

const stop = async () => {
await whip.stop()
logWhip("stopped")
}

// leave page
addEventListener("beforeunload", stop)

const element = document.getElementById(idWhipButtonStop)
if (element) element.addEventListener('click', stop)

document.getElementById(idWhipLayerSelect).disabled = true
}
window.startWhip = startWhip

// WHEP
const idWhepLayerSelect = "whep-layer-select"
const idWhepButtonStop = "whep-button-stop"
initLayerSelect(idWhepLayerSelect, [
{ value: "", text: "AUTO" },
{ value: "q", text: "LOW" },
Expand Down Expand Up @@ -269,6 +288,12 @@
logWhep(e)
}

const element = document.getElementById(idWhepButtonStop)
if (element) element.addEventListener('click', async () => {
await whep.stop()
logWhep("stopped")
})

const initEvevt = () => {
const el = document.getElementById(idWhepLayerSelect)
if (el) el.onchange = ev => !ev.target.value ? whep.unselectLayer() : whep.selectLayer({"encodingId": ev.target.value}).catch(e => logWhep(e))
Expand Down
2 changes: 2 additions & 0 deletions assets/whep.js
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,8 @@ export class WHEPClient extends EventTarget {
if (this.token)
headers["Authorization"] = "Bearer " + this.token;

if (this.etag) headers["If-Match"] = this.etag;

//Send a delete
await fetch(this.resourceURL, {
method: "DELETE",
Expand Down
2 changes: 2 additions & 0 deletions assets/whip.js
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,8 @@ export class WHIPClient {
if (this.token)
headers["Authorization"] = "Bearer " + this.token;

if (this.etag) headers["If-Match"] = this.etag;

//Send a delete
await fetch(this.resourceURL, {
method: "DELETE",
Expand Down

0 comments on commit 692b154

Please sign in to comment.