Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/utils/signaling.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ function Base(settings) {
this.signalingConnectionTimeout = null
this.signalingConnectionWarning = null
this.signalingConnectionError = null
this.maxStreamBits = 1048576
}

Signaling.Base = Base
Expand Down Expand Up @@ -1281,6 +1282,13 @@ Signaling.Standalone.prototype.joinCall = function(token, flags, silent, recordi

Signaling.Standalone.prototype.joinResponseReceived = function(data, token) {
console.debug('Joined', data, token)
if (data.room?.bandwidth?.maxstreambitrate) {
const totalBps = data.room.bandwidth.maxstreambitrate
if (typeof totalBps === 'number' && totalBps > 0) {
this.maxStreamBits = data.room.bandwidth.maxstreambitrate
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
this.maxStreamBits = data.room.bandwidth.maxstreambitrate
this.maxStreamBits = totalBps

Also you should reset this.maxStreamBits to the default value if no bandwidth limit is returned in the join response.

}
}

this.signalingRoomJoined = token
if (this.pendingJoinCall && token === this.pendingJoinCall.token) {
const pendingJoinCallResolve = this.pendingJoinCall.resolve
Expand Down
30 changes: 25 additions & 5 deletions src/utils/webrtc/simplewebrtc/simplewebrtc.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,30 @@ import webrtcSupport from 'webrtcsupport'
import WildEmitter from 'wildemitter'
import WebRTC from './webrtc.js'

/**
* Split totalBps into integer low/medium/high parts with ratio 1:4:16 (total 21 parts).
* Returned values are integers. Any remainder from integer division is omitted.
*
* @param {number} totalBps - Total bandwidth in bps (non-negative number).
* @returns {{ low: number, medium: number, high: number }}
*/
function splitBandwidthIntegersOmitRemainder(totalBps = 1048576) {
if (typeof totalBps !== 'number' || totalBps < 0) {
totalBps = 1048576
}

// Divide into 21 parts and distribute them in 2^2 way across the quality levels
// Additionally we divide and multiple with 100 but round down in between
// to create some safety bits
const partValue = Math.floor(totalBps / 21 / 100) * 100

return {
low: partValue,
medium: partValue * 4,
high: partValue * 16,
}
}

/**
* @param {object} opts the options object.
*/
Expand All @@ -19,11 +43,7 @@ export default function SimpleWebRTC(opts) {
debug: false,
enableDataChannels: true,
enableSimulcast: false,
maxBitrates: {
high: 900000,
medium: 300000,
low: 100000,
},
maxBitrates: splitBandwidthIntegersOmitRemainder(opts.connection?.maxStreamBits),
autoRequestMedia: false,
receiveMedia: {
offerToReceiveAudio: 1,
Expand Down
1 change: 1 addition & 0 deletions src/utils/webrtc/simplewebrtc/webrtc.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export default function WebRTC(opts) {
},
enableDataChannels: true,
enableSimulcast: false,
// Overwritten by simplewebrtc.js
maxBitrates: {
high: 900000,
medium: 300000,
Expand Down
Loading