Skip to content
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

Update send/receive settings example #28

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
74 changes: 70 additions & 4 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import React, { useCallback, useState } from "react";
import Daily, { DailyEventObject } from "@daily-co/daily-js";
import React, { useCallback, useRef, useState } from "react";
import Daily, {
DailyEventObject,
DailyEventObjectNetworkQualityEvent,
} from "@daily-co/daily-js";

import {
useDaily,
Expand All @@ -12,6 +15,8 @@ import {
useInputSettings,
useNetwork,
useRecording,
useReceiveSettings,
useSendSettings,
useTranscription,
useParticipantCounts,
} from "@daily-co/daily-react";
Expand All @@ -31,7 +36,7 @@ export default function App() {
const [inputSettingsUpdated, setInputSettingsUpdated] = useState(false);
const [enableBlurClicked, setEnableBlurClicked] = useState(false);
const [enableBackgroundClicked, setEnableBackgroundClicked] = useState(false);
const [dailyRoomUrl, setDailyRoomUrl] = useState("");
const [dailyRoomUrl, setDailyRoomUrl] = useState("https://hush.daily.co/sfu");
const [dailyMeetingToken, setDailyMeetingToken] = useState("");

const {
Expand Down Expand Up @@ -66,9 +71,70 @@ export default function App() {
onTranscriptionStopped: logEvent,
});

const { sendSettings, updateSendSettings } = useSendSettings({
onSendSettingsUpdated: logEvent,
});

const { receiveSettings, updateReceiveSettings } = useReceiveSettings({
onReceiveSettingsUpdated: logEvent,
});

const previousThreshold = useRef<"good" | "low" | "very-low">("good");

const onNetworkQualityChange = useCallback(
(evt: DailyEventObjectNetworkQualityEvent) => {
logEvent(evt);

const { threshold } = evt;

if (threshold === previousThreshold.current) {
console.log("same threshold skip");
return;
}

// Update send settings based on network quality
switch (threshold) {
case "good":
updateReceiveSettings({ "*": { video: { layer: 2 } } });
updateSendSettings({
video: {
maxQuality: "high",
},
});
break;
case "low":
updateReceiveSettings({ "*": { video: { layer: 0 } } });
updateSendSettings({
video: {
maxQuality: "low",
},
});
break;
case "very-low":
// Turn off local video
console.log("Turning off local video");
// callObject?.setLocalVideo(false);
break;
default:
console.log("sendSettings: ", sendSettings);
console.log("receiveSettings: ", receiveSettings);
break;
}

previousThreshold.current = threshold;
},
[
logEvent,
receiveSettings,
sendSettings,
updateReceiveSettings,
updateSendSettings,
]
);

const network = useNetwork({
onNetworkConnection: logEvent,
onNetworkQualityChange: logEvent,
onNetworkQualityChange,
});

const { startRecording, stopRecording } = useRecording({
Expand Down