Skip to content

Use sendSettings instead of camSimulcastEncodings and setBandwidth() #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jul 26, 2023
Merged
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: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"author": "Liza Shulyayeva",
"license": "BSD-2-Clause",
"dependencies": {
"@daily-co/daily-js": "^0.47.0",
"@daily-co/daily-js": "^0.48.0",
"@pixi/unsafe-eval": "^7.2.4",
"express": "^4.18.2",
"http-server": "^14.0.0",
Expand Down
57 changes: 34 additions & 23 deletions src/room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import DailyIframe, {
DailyRoomInfo,
DailyEventObjectParticipantLeft,
} from "@daily-co/daily-js";
import { globalZoneID, standardTileSize } from "./config";

Choose a reason for hiding this comment

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

Are we still using this standardTileSize somewhere else, or can we remove it from the config file as well ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's still used in several models within the world

import { globalZoneID } from "./config";

import {
enableScreenBtn,
Expand Down Expand Up @@ -66,8 +66,6 @@ export default class Room {

pendingAcks: { [key: string]: ReturnType<typeof setInterval> } = {};

localBandwidthLevel = BandwidthLevel.Unknown;

localState: State = { audio: null, video: null };

topology: Topology;
Expand All @@ -78,9 +76,28 @@ export default class Room {
this.isGlobal = isGlobal;
this.callObject = DailyIframe.createCallObject({
subscribeToTracksAutomatically: false,
sendSettings: {
video: {
encodings: {
low: {
maxBitrate: 75000,
scaleResolutionDownBy: 4,
maxFramerate: 15,
},
medium: {
maxBitrate: 300000,
scaleResolutionDownBy: 2,
maxFramerate: 30,
},
},
},
},
dailyConfig: {
camSimulcastEncodings: [{ maxBitrate: 600000, maxFramerate: 30 }],
avoidEval: true,
userMediaVideoConstraints: {
width: 400,
height: 400,
},
},
})
.on("camera-error", (e) => this.handleCameraError(e))
Expand All @@ -92,7 +109,7 @@ export default class Room {
.on("app-message", (e) => this.handleAppMessage(e))
.on("network-connection", (e) => this.handleNetworkConnectionChanged(e));

this.setBandwidth(BandwidthLevel.Tile);
this.setVideoQuality(BandwidthLevel.Tile);
}

async join() {
Expand Down Expand Up @@ -120,31 +137,25 @@ export default class Room {
delete this.pendingAcks[sessionID];
}

private setBandwidth(level: BandwidthLevel) {
private setVideoQuality(level: BandwidthLevel) {
switch (level) {
case BandwidthLevel.Tile:
this.localBandwidthLevel = level;
this.callObject.setBandwidth({
trackConstraints: {
width: standardTileSize,
height: standardTileSize,
frameRate: 15,
this.callObject.updateSendSettings({
video: {
maxQuality: "low",
},
});
break;
case BandwidthLevel.Focus:
this.localBandwidthLevel = level;
this.callObject.setBandwidth({
trackConstraints: {
width: 200,
height: 200,
frameRate: 30,
this.callObject.updateSendSettings({
video: {
maxQuality: "medium",
},
});
break;
default:
console.warn(
`setBandwidth called with unrecognized level (${level}). Not modifying any constraints.`,
`setVideoQuality() called with unrecognized level (${level}). This is a no-op.`,
);
}
}
Expand All @@ -165,11 +176,11 @@ export default class Room {
}

private handleCameraError(event: DailyEventObjectCameraError) {
console.error(`camera error in room ${this.url}": ${event}`);
console.error(`camera error in room ${this.url}`, event);
}

private handleError(event: DailyEventObjectFatalError) {
console.error(`error in room ${this.url}": ${event}`);
console.error(`error in room ${this.url}`, event);
}

private handleJoinedMeeting(event: DailyEventObjectParticipants) {
Expand Down Expand Up @@ -233,13 +244,13 @@ export default class Room {
// to other participants.
const onJoinZone = (zoneData: ZoneData, recipient: string = "*") => {
if (zoneData.zoneID === globalZoneID) {
this.setBandwidth(BandwidthLevel.Tile);
this.setVideoQuality(BandwidthLevel.Tile);
if (this.localState.screen) {
this.stopScreenShare();
}
enableScreenBtn(false);
} else {
this.setBandwidth(BandwidthLevel.Focus);
this.setVideoQuality(BandwidthLevel.Focus);
enableScreenBtn(true);
}
const data = {
Expand Down