From a819d14861a0d190b4787cf0a2f2dd76109d6860 Mon Sep 17 00:00:00 2001 From: rainbow napkin Date: Mon, 6 Jul 2026 23:30:54 -0400 Subject: [PATCH] Finished streamType Configuration backend --- src/validators/channelValidator.js | 16 ++--- .../partial/channelSettings/settings.ejs | 12 ++-- www/js/channelSettings.js | 67 +++++++++++++++++++ 3 files changed, 80 insertions(+), 15 deletions(-) diff --git a/src/validators/channelValidator.js b/src/validators/channelValidator.js index 92ef4b5..9c87f55 100644 --- a/src/validators/channelValidator.js +++ b/src/validators/channelValidator.js @@ -20,15 +20,6 @@ const { checkSchema, checkExact } = require('express-validator'); //local imports const accountValidator = require('./accountValidator'); -module.exports = { - - settingsMap: () => checkExact(checkSchema({ - 'settingsMap.hidden': { - optional: true, - isBoolean: true, - } })) -} - module.exports.name = function(field = 'name'){ return checkSchema({ [field]: { @@ -89,6 +80,13 @@ module.exports.settingsMap = function(){ } }, errorMessage: "Invalid Stream URL" + }, + 'settingsMap.streamType': { + optional: true, + errorMessage: "Invalid Stream Type", + matches: { + options: [/\b(?:webrtc|hls)\b/] + } } }) ); diff --git a/src/views/partial/channelSettings/settings.ejs b/src/views/partial/channelSettings/settings.ejs index b077763..d8dd2ea 100644 --- a/src/views/partial/channelSettings/settings.ejs +++ b/src/views/partial/channelSettings/settings.ejs @@ -37,15 +37,15 @@ along with this program. If not, see . %>

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