Skip to content

Commit 3fe5d21

Browse files
authored
html: fix id_key to use device.name (#92)
* html: use const/let; add baseURL constant * html: fix id_key [Object object]
1 parent f73ac32 commit 3fe5d21

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

html/control.html

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -472,9 +472,10 @@ <h1>Release</h1>
472472

473473
<script>
474474
document.addEventListener('DOMContentLoaded', function (event) {
475-
var streamURL = 'stream';
476-
var snapshotURL = 'snapshot';
477-
var webrtcURL = 'webrtc';
475+
const streamURL = 'stream';
476+
const snapshotURL = 'snapshot';
477+
const webrtcURL = 'webrtc';
478+
const baseURL = '';
478479

479480
const header = document.getElementById('logo')
480481
const settings = document.getElementById('sidebar')
@@ -539,7 +540,7 @@ <h1>Release</h1>
539540
key = encodeURIComponent(key);
540541
value = encodeURIComponent(value);
541542

542-
return fetch(`option?device=${device}&key=${key}&value=${value}`, {
543+
return fetch(`${baseURL}option?device=${device}&key=${key}&value=${value}`, {
543544
method: 'POST'
544545
}).then(function (response) {
545546
return response
@@ -554,7 +555,7 @@ <h1>Release</h1>
554555
}
555556

556557
const createDeviceOption = (device, key, option) => {
557-
const id_key = `${device}_${key}`;
558+
const id_key = `${device.name}_${key}`;
558559
const groupEl = insertControl("div");
559560
groupEl.className = "input-group";
560561

@@ -603,7 +604,7 @@ <h1>Release</h1>
603604
selectEl.add(optionEl);
604605
}
605606

606-
for (var value in option.menu) {
607+
for (let value in option.menu) {
607608
const optionEl = document.createElement("option");
608609
optionEl.value = value;
609610
optionEl.text = option.menu[value];
@@ -695,24 +696,24 @@ <h1>Release</h1>
695696
}
696697

697698
const createControls = (state) => {
698-
for (var device of state.devices) {
699+
for (let device of state.devices) {
699700
const heading = insertControl("h1");
700701
heading.textContent = device.name;
701702

702-
for (var key in device.options) {
703+
for (let key in device.options) {
703704
createDeviceOption(device, key, device.options[key]);
704705
}
705706
}
706707
};
707708

708-
var rtcPeerConfig = {
709+
const rtcPeerConfig = {
709710
sdpSemantics: 'unified-plan'
710711
};
711712

712-
rtcPeerConnection = new RTCPeerConnection(rtcPeerConfig);
713+
let rtcPeerConnection = new RTCPeerConnection(rtcPeerConfig);
713714

714715
// read initial values
715-
fetch(`status`)
716+
fetch(`${baseURL}status`)
716717
.then(function (response) {
717718
return response.json()
718719
})
@@ -757,7 +758,7 @@ <h1>Release</h1>
757758
{ urls: ['stun:stun.l.google.com:19302'] }
758759
];
759760

760-
fetch(webrtcURL, {
761+
fetch(baseURL + webrtcURL, {
761762
body: JSON.stringify({type: 'request', iceServers: iceServers}),
762763
headers: {'Content-Type': 'application/json'},
763764
method: 'POST'
@@ -780,7 +781,7 @@ <h1>Release</h1>
780781
});
781782
rtcPeerConnection.addEventListener("icecandidate", function(e) {
782783
if (e.candidate) {
783-
return fetch(webrtcURL, {
784+
return fetch(baseURL + webrtcURL, {
784785
body: JSON.stringify({
785786
type: 'remote_candidate',
786787
id: rtcPeerConnection.remote_pc_id,
@@ -800,9 +801,9 @@ <h1>Release</h1>
800801
}).then(function(answer) {
801802
return rtcPeerConnection.setLocalDescription(answer);
802803
}).then(function(answer) {
803-
var offer = rtcPeerConnection.localDescription;
804+
const offer = rtcPeerConnection.localDescription;
804805

805-
return fetch(webrtcURL, {
806+
return fetch(baseURL + webrtcURL, {
806807
body: JSON.stringify({
807808
type: offer.type,
808809
id: rtcPeerConnection.remote_pc_id,

0 commit comments

Comments
 (0)