Skip to content

Commit

Permalink
Add dynamic bandwidth selection (#186)
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrgregor authored Jun 8, 2021
1 parent 8ad0531 commit 2cebeca
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
41 changes: 41 additions & 0 deletions packages/js/src/Modules/Verto/webrtc/BaseCall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,47 @@ export default abstract class BaseCall implements IWebRTCCall {
toggleAudioTracks(this.options.remoteStream);
}

setAudioBandwidth(min: number, max: number) {
const { instance } = this.peer;
const sender = instance
.getSenders()
.find(({ track: { kind } }: RTCRtpSender) => kind === 'audio');

if (sender) {

let p = sender.getParameters();
const parameters = p as RTCRtpSendParameters;
if (!parameters.encodings) {
parameters.encodings = [{ rid : 'h' }];
}
logger.info("Parameters: ", parameters);

if (min) {
logger.info("Setting min audio bandwidth to: ", min, " [kbps]");
//parameters.encodings[0].minBitrate = min * 1024;
}
if (max) {
logger.info("Setting max audio bandwidth to: ", max, " [kbps]");
parameters.encodings[0].maxBitrate = max * 1024;
}
sender.setParameters(parameters)
.then(() => {
logger.info("New audio bandwidth settings in use: ", sender.getParameters());
})
.catch(e => console.error(e));
} else {
logger.error("Could not set audio bandwidth");
}
}

setAudioBandwidthMin(min: number) {
this.setAudioBandwidth(min, null);
}

setAudioBandwidthMax(max: number) {
this.setAudioBandwidth(null, max);
}

setState(state: State) {
this._prevState = this._state;
this._state = state;
Expand Down
2 changes: 2 additions & 0 deletions packages/js/src/Modules/Verto/webrtc/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ export interface IWebRTCCall {
deaf: () => void;
undeaf: () => void;
toggleDeaf: () => void;
setAudioBandwidthMin: (min: number) => void,
setAudioBandwidthMax: (max: number) => void,
setState: (state: any) => void;
// Privates
handleMessage: (msg: any) => void;
Expand Down

0 comments on commit 2cebeca

Please sign in to comment.