/*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 .*/ /** * 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;