Finished streamType Configuration backend
This commit is contained in:
parent
e3507b00f8
commit
a819d14861
3 changed files with 80 additions and 15 deletions
|
|
@ -20,15 +20,6 @@ const { checkSchema, checkExact } = require('express-validator');
|
||||||
//local imports
|
//local imports
|
||||||
const accountValidator = require('./accountValidator');
|
const accountValidator = require('./accountValidator');
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
|
|
||||||
settingsMap: () => checkExact(checkSchema({
|
|
||||||
'settingsMap.hidden': {
|
|
||||||
optional: true,
|
|
||||||
isBoolean: true,
|
|
||||||
} }))
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports.name = function(field = 'name'){
|
module.exports.name = function(field = 'name'){
|
||||||
return checkSchema({
|
return checkSchema({
|
||||||
[field]: {
|
[field]: {
|
||||||
|
|
@ -89,6 +80,13 @@ module.exports.settingsMap = function(){
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
errorMessage: "Invalid Stream URL"
|
errorMessage: "Invalid Stream URL"
|
||||||
|
},
|
||||||
|
'settingsMap.streamType': {
|
||||||
|
optional: true,
|
||||||
|
errorMessage: "Invalid Stream Type",
|
||||||
|
matches: {
|
||||||
|
options: [/\b(?:webrtc|hls)\b/]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -38,14 +38,14 @@ along with this program. If not, see <https://www.gnu.org/licenses/>. %>
|
||||||
<p>Livestream Type:</p>
|
<p>Livestream Type:</p>
|
||||||
<span id="channel-preference-list-stream-settings-grid">
|
<span id="channel-preference-list-stream-settings-grid">
|
||||||
<span>
|
<span>
|
||||||
<input type="radio" name="streamType" id="webrtc" value="webrtc">
|
<input type="radio" name="streamType" id="channel-preference-list-stream-type-webrtc" value="webrtc" <% if(channel.settings["streamType"] == "webrtc"){ %> checked <% }%> >
|
||||||
<label for="webrtc">Peer-to-Peer (WebRTC/STUN)</label>
|
<label for="channel-preference-list-stream-type-webrtc">Peer-to-Peer (WebRTC/STUN)</label>
|
||||||
</span>
|
</span>
|
||||||
<span>
|
<span>
|
||||||
<input type="radio" name="streamType" id="hls" value="hls">
|
<input type="radio" name="streamType" id="channel-preference-list-stream-type-hls" value="hls" <% if(channel.settings["streamType"] == "hls"){ %> checked <% }%> >
|
||||||
<label for="hls">Self-Hosted (HLS)</label>
|
<label for="channel-preference-list-stream-type-hls">Self-Hosted (HLS)</label>
|
||||||
</span>
|
</span>
|
||||||
<input disabled id="channel-preference-list-stream-url" placeholder="Stream URL" value="<%= channel.settings["streamURL"] %>">
|
<input <% if(channel.settings["streamType"] != "hls"){ %> disabled <%}%> id="channel-preference-list-stream-url" placeholder="Stream URL" value="<%= channel.settings["streamURL"] %>">
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
</span>
|
</span>
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@ class channelSettingsPage{
|
||||||
this.banList = new banList(this.channel);
|
this.banList = new banList(this.channel);
|
||||||
this.permList = new permList(this.channel);
|
this.permList = new permList(this.channel);
|
||||||
this.prefrenceList = new prefrenceList(this.channel);
|
this.prefrenceList = new prefrenceList(this.channel);
|
||||||
|
this.livestreamPreferences = new livestreamPreferences(this.channel);
|
||||||
this.tokeCommandList = new tokeCommandList(this.channel);
|
this.tokeCommandList = new tokeCommandList(this.channel);
|
||||||
this.emoteList = new emoteList(this.channel);
|
this.emoteList = new emoteList(this.channel);
|
||||||
this.deleteBtn = new deleteBtn(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{
|
class permList{
|
||||||
constructor(channel){
|
constructor(channel){
|
||||||
this.channel = channel
|
this.channel = channel
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue