Continued work expirementing with WebRTC

This commit is contained in:
rainbow napkin 2026-09-24 17:16:29 -04:00
parent 3517a1499a
commit 86e9c586b6
7 changed files with 341 additions and 15 deletions

View file

@ -369,11 +369,6 @@ class queue{
return;
}
/*if(chanDB.settings.streamType == "webrtc"){
console.log("WEBRTC ENABLED, BAILING!");
return;
}*/
//If something is playing
if(this.nowPlaying != null){
//Capture currently playing object
@ -410,6 +405,10 @@ class queue{
}
rawLink = {combo:[['default',streamURL]]};
//Otherwise if we're starting a web RTC Stream
}else if(chanDB.settings.streamType == "webrtc"){
//Let our webRTCHandler know
this.channel.webRTCHandler.startStream(socket);
}
//Create queued media object from stream URL and set it to nowPlaying
@ -1351,6 +1350,11 @@ class queue{
//Set duration from start and end time
wasPlaying.duration = (now - wasPlaying.startTime) / 1000;
//If we're ending a webrtc stream
if(wasPlaying.type == "webrtc"){
this.channel.webRTCHandler.endStream();
}
//If we're in pushback mode
if(this.liveMode == "pushback"){
await this.livestreamPushbackSchedule(wasPlaying, chanDB);

View file

@ -47,6 +47,15 @@ class webRTCHandler{
defineListeners(socket){
//Queueing Functions
socket.on("relayRTCData", (data) => {this.relayRTCData(socket, data)});
socket.on("disconnect", (data) => {this.handleStreamerDisconnect(socket, data)});
}
handleStreamerDisconnect(socket){
//If the disconnecting socket is the current streamer
if(socket.id == this.currentStreamer){
//Tell the queue to stop current stream
this.channel.queue.stop();
}
}
startStream(socket){
@ -61,20 +70,33 @@ class webRTCHandler{
//Set the recipient to the current streamer by default, assuming that this isn't coming from the streaming socket
let recipientID = this.currentStreamer;
//Create object to hold data being relayed to client
let webRTCData = {
type: data.type,
body: data.body
};
//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;
//Otherwise if the data is being relayed from a viewer to the streaming socket
}else{
//Add viewers socket id
webRTCData.source = {
user: socket.user.user,
socket: socket.id
};
}
//Get recipient socket
const recipient = this.server.io.sockets.sockets.get(recipientID);
//Relay RTC Data
recipient.emit("RTCData", {
type: data.type,
body: data.body
});
//If we have a recipient
if(recipient != null){
//Relay RTC Data
recipient.emit("RTCData", webRTCData);
}
}
}

View file

@ -48,6 +48,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>. %>
<script src="/js/channel/mediaHandler.js"></script>
<script src="/js/channel/player.js"></script>
<script src="/js/channel/pmHandler.js"></script>
<script src="/js/channel/webRTCHandler.js"></script>
<script src="/js/channel/cpanel.js"></script>
<%# panels %>
<script src="/js/channel/panels/emotePanel.js"></script>