From 1dfe3454b4dff4da8ded7fad54417f24eaddaf53 Mon Sep 17 00:00:00 2001 From: rainbow napkin Date: Sat, 10 Oct 2026 02:40:57 -0400 Subject: [PATCH] Capped bitrates for WebRTC Streams --- www/js/channel/webRTCHandler.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/www/js/channel/webRTCHandler.js b/www/js/channel/webRTCHandler.js index be79747..4210431 100644 --- a/www/js/channel/webRTCHandler.js +++ b/www/js/channel/webRTCHandler.js @@ -359,6 +359,23 @@ class connectedViewer{ peer.addTrack(track, this.broadcastingStream); } + //For each sender for this peer + for(let sender of peer.getSenders()){ + //Set audio tracks to 192kbps and video tracks to 1200kbps + const bitrate = (sender.track.kind == "audio") ? 192 * 1000 : 1200 * 1000; + //gank parms from the sender + const parms = sender.getParameters(); + + //Run through all listed encodings in the current sender paramters + for(let encodingIndex in parms.encodings){ + //Set max bitrate to chosen bitrate + parms.encodings[encodingIndex].maxBitrate = bitrate; + } + + //Set sender parameters to modified parameters + sender.setParameters(parms); + } + //Set peer remote description to connection offer from viewer peer.setRemoteDescription(new RTCSessionDescription(offer));