Started work on WebRTC Negotation Relay Backend

This commit is contained in:
rainbow napkin 2026-07-11 03:07:17 -04:00
parent 8f02be793f
commit b68d55b7ef
7 changed files with 108 additions and 6 deletions

View file

@ -34,6 +34,11 @@
"address": "toke@42069.weed", "address": "toke@42069.weed",
"pass": "CHANGE_ME" "pass": "CHANGE_ME"
}, },
"iceServers":[
{
"url":"stun:stun.moonlight-stream.org:3478"
}
],
"links":{ "links":{
"About": "/about", "About": "/about",
"Code": "https://git.ourfore.st/rainbownapkin/canopy", "Code": "https://git.ourfore.st/rainbownapkin/canopy",

View file

@ -65,6 +65,12 @@
"address": "toke@42069.weed", "address": "toke@42069.weed",
"pass": "CHANGE_ME" "pass": "CHANGE_ME"
}, },
//Privdes STUN/TURN servers for WebRTC functionality
"iceServers":[
{
"url":"stun:stun.moonlight-stream.org:3478"
}
],
//Provides customizable links for navbar //Provides customizable links for navbar
"links":{ "links":{
"About": "/about", "About": "/about",

View file

@ -19,7 +19,8 @@ const connectedUser = require('./connectedUser');
const chatBuffer = require('./chatBuffer'); const chatBuffer = require('./chatBuffer');
const queue = require('./media/queue'); const queue = require('./media/queue');
const channelModel = require('../../schemas/channel/channelSchema'); const channelModel = require('../../schemas/channel/channelSchema');
const playlistHandler = require('./media/playlistHandler') const playlistHandler = require('./media/playlistHandler');
const webRTCHandler = require('./media/webRTCHandler');
/** /**
* Class representing a single active channel * Class representing a single active channel
@ -67,6 +68,11 @@ class activeChannel{
*/ */
this.playlistHandler = new playlistHandler(server, this); this.playlistHandler = new playlistHandler(server, this);
/**
* Child WebRTC Handler Object
*/
this.webRTCHandler = new webRTCHandler(server, this);
/** /**
* Child Chat Buffer Object * Child Chat Buffer Object
*/ */
@ -108,6 +114,7 @@ class activeChannel{
//Define per-channel event listeners //Define per-channel event listeners
this.queue.defineListeners(socket); this.queue.defineListeners(socket);
this.playlistHandler.defineListeners(socket); this.playlistHandler.defineListeners(socket);
this.webRTCHandler.defineListeners(socket);
//Hand off the connection initiation to it's user object //Hand off the connection initiation to it's user object
const activeUser = await userObj.handleConnection(userDB, chanDB, socket) const activeUser = await userObj.handleConnection(userDB, chanDB, socket)

View file

@ -236,7 +236,7 @@ class connectedUser{
const chatBuffer = this.channel.chatBuffer.buffer; const chatBuffer = this.channel.chatBuffer.buffer;
//Send off the metadata to our user's clients //Send off the metadata to our user's clients
this.emit("clientMetadata", {user: userObj, flairList, queueLock, chatBuffer, streamType: chanDB.settings.streamType}); this.emit("clientMetadata", {user: userObj, flairList, queueLock, chatBuffer, streamType: chanDB.settings.streamType, iceServers: config.iceServers});
} }
/** /**

View file

@ -331,8 +331,8 @@ class queue{
try{ try{
//Define and/or declare required variables //Define and/or declare required variables
let title = "Livestream"; let title = "Livestream";
let filename; let filename = '/';
let streamURL; let streamURL = '/';
if(data != null && data.title != null){ if(data != null && data.title != null){
//If the title is too long //If the title is too long
@ -368,10 +368,10 @@ class queue{
return; return;
} }
if(chanDB.settings.streamType == "webrtc"){ /*if(chanDB.settings.streamType == "webrtc"){
console.log("WEBRTC ENABLED, BAILING!"); console.log("WEBRTC ENABLED, BAILING!");
return; return;
} }*/
//If something is playing //If something is playing
if(this.nowPlaying != null){ if(this.nowPlaying != null){

View file

@ -0,0 +1,81 @@
/*Canopy - The next generation of stoner streaming software
Copyright (C) 2024-2026 Rainbownapkin and the TTN Community
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.*/
/**
* Object to relay WebRTC Negotiation data for a single channel
*/
class webRTCHandler{
/**
* Instantiates a new object to relay WebRTC Negotiation data for a single channel
* @param {channelManager} server - Parent server object
* @param {activeChannel} channel - Parent Channel object
*/
constructor(server, channel){
/**
* Parent Server Object
*/
this.server = server
/**
* Parent Channel Object
*/
this.channel = channel;
/**
* Declare class property to hold socked it of the current device/browser-tab we're streaming from
*/
this.currentStreamer;
}
/**
* Defines server-side socket.io listeners for newly connected sockets
* @param {Socket} socket - Newly connected socket to define listeners against
*/
defineListeners(socket){
//Queueing Functions
socket.on("relayRTCData", (data) => {this.relayRTCData(socket, data)});
}
startStream(socket){
this.currentStreamer = socket.id;
}
endStream(){
this.currentStreamer = null;
}
relayRTCData(socket, data){
//Set the recipient to the current streamer by default, assuming that this isn't coming from the streaming socket
let recipientID = this.currentStreamer;
//if data is being relayed from streaming socket to a viewer
if(socket.id == this.currentStreamer){
//Change recipient to reflect streaming socket's request
recipientID = data.recipient;
}
//Get recipient socket
const recipient = this.server.io.sockets.sockets.get(recipientID);
//Relay RTC Data
recipient.emit("RTCData", {
type: data.type,
body: data.body
});
}
}
module.exports = webRTCHandler;

View file

@ -153,6 +153,9 @@ class channel{
//Store streamType //Store streamType
this.streamType = data.streamType; this.streamType = data.streamType;
//Store URLs to known Internet Connectivitey Establishment servers.
this.iceServer = data.iceServers;
} }
/** /**