Livestream Type:
- - - + + checked <% }%> > + - - + checked <% }%> > + - "> + disabled <%}%> id="channel-preference-list-stream-url" placeholder="Stream URL" value="<%= channel.settings["streamURL"] %>"> diff --git a/www/js/channelSettings.js b/www/js/channelSettings.js index 36fa99a..74bbe49 100644 --- a/www/js/channelSettings.js +++ b/www/js/channelSettings.js @@ -24,6 +24,7 @@ class channelSettingsPage{ this.banList = new banList(this.channel); this.permList = new permList(this.channel); this.prefrenceList = new prefrenceList(this.channel); + this.livestreamPreferences = new livestreamPreferences(this.channel); this.tokeCommandList = new tokeCommandList(this.channel); this.emoteList = new emoteList(this.channel); this.deleteBtn = new deleteBtn(this.channel); @@ -364,6 +365,72 @@ class prefrenceList{ } } +class livestreamPreferences{ + constructor(channel){ + this.channel = channel; + + //Grab inputs + this.webRTCButton = document.querySelector("#channel-preference-list-stream-type-webrtc"); + this.hlsButton = document.querySelector("#channel-preference-list-stream-type-hls"); + this.streamURL = document.querySelector("#channel-preference-list-stream-url"); + + //Setup Input + this.setupInput(); + } + + setupInput(){ + //Add event listeners + this.webRTCButton.addEventListener("change", this.submitTypeUpdate.bind(this)); + this.hlsButton.addEventListener("change", this.submitTypeUpdate.bind(this)); + this.streamURL.addEventListener("change",this.submitURLUpdate.bind(this)); + } + + async submitURLUpdate(event){ + //Grab value from event target + const value = event.target.value; + + //Send setting change request to server, and store update once its received + const update = await utils.ajax.setChannelSetting(this.channel, new Map([["streamURL", value]])); + + //If we we're given a good update + if(update != null && update.streamURL != null){ + //Display the new streamURL in the input (I'm not making a dedicated method for a fuckin' one-liner) + this.streamURL.value = update.streamURL + } + } + + async submitTypeUpdate(event){ + //Grab value from event target + const value = event.target.value; + + //Send setting change request to server, and store update once its received + const update = await utils.ajax.setChannelSetting(this.channel, new Map([["streamType", value]])); + + //Pass update to the handleUpdate method + this.handleTypeUpdate(update); + } + + handleTypeUpdate(data){ + //If the stream type is HLS + if(data.streamType == "hls"){ + //Ensure the hls button is checked + this.hlsButton.checked = true; + //Ensure the stream url input is enabled + this.streamURL.disabled = false; + //Otherwise + }else{ + //Ensure the stream url input is disabled + this.streamURL.disabled = true; + } + + //If the stream type is webrtc + if(data.streamType == "webrtc"){ + //Ensure the webrtc button is checked + this.webRTCButton.checked = true; + } + } +} + class permList{ constructor(channel){ this.channel = channel