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

Add data saver mode #94

Merged
merged 1 commit into from
Aug 22, 2024
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: 8 additions & 0 deletions app/components/OverflowMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ interface OverflowMenuProps {
export const OverflowMenu: FC<OverflowMenuProps> = ({ bugReportsEnabled }) => {
const {
room: { otherUsers, identity },
dataSaverMode,
setDataSaverMode,
} = useRoomContext()
const [settingsMenuOpen, setSettingMenuOpen] = useState(false)
const [bugReportMenuOpen, setBugReportMenuOpen] = useState(false)
Expand All @@ -33,6 +35,12 @@ export const OverflowMenu: FC<OverflowMenuProps> = ({ bugReportsEnabled }) => {
</DropdownMenu.Trigger>
<DropdownMenu.Portal>
<DropdownMenu.Content sideOffset={5}>
<DropdownMenu.Item
onSelect={() => setDataSaverMode(!dataSaverMode)}
>
<Icon type="WifiIcon" className="mr-2" />
{dataSaverMode ? 'Disable Data Saver' : 'Enable Data Saver'}
</DropdownMenu.Item>
<DropdownMenu.Item
onSelect={() => navigator.clipboard.writeText(roomUrl)}
>
Expand Down
4 changes: 2 additions & 2 deletions app/components/Participant.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export const Participant = forwardRef<
ref
) => {
const { data } = useUserMetadata(user.name)
const { traceLink, peer } = useRoomContext()
const { traceLink, peer, dataSaverMode } = useRoomContext()

useDeadPulledTrackMonitor(
user.tracks.video,
Expand Down Expand Up @@ -148,7 +148,7 @@ export const Participant = forwardRef<
{
'opacity-100': isScreenShare
? user.tracks.screenShareEnabled
: user.tracks.videoEnabled,
: user.tracks.videoEnabled && (!dataSaverMode || isSelf),
},
isSelf && isScreenShare && 'opacity-75'
)}
Expand Down
2 changes: 2 additions & 0 deletions app/hooks/useRoomContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ export type RoomContextType = {
userDirectoryUrl?: string
joined: boolean
setJoined: Dispatch<SetStateAction<boolean>>
dataSaverMode: boolean
setDataSaverMode: Dispatch<SetStateAction<boolean>>
userMedia: UserMedia
peer: RxjsPeer
iceConnectionState: RTCIceConnectionState
Expand Down
3 changes: 2 additions & 1 deletion app/routes/_room.$roomName.room.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ function JoinedRoom({ bugReportsEnabled }: { bugReportsEnabled: boolean }) {
const {
userMedia,
peer,
dataSaverMode,
pushedTracks,
room: { otherUsers, websocket, identity },
} = useRoomContext()
Expand Down Expand Up @@ -242,7 +243,7 @@ function JoinedRoom({ bugReportsEnabled }: { bugReportsEnabled: boolean }) {
{actorsOnStage.map((user) => (
<Fragment key={user.id}>
<PullVideoTrack
video={user.tracks.video}
video={dataSaverMode ? undefined : user.tracks.video}
audio={user.tracks.audio}
>
{({ videoTrack, audioTrack }) => (
Expand Down
3 changes: 3 additions & 0 deletions app/routes/_room.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ function tryToGetDimensions(videoStreamTrack?: MediaStreamTrack) {

function Room() {
const [joined, setJoined] = useState(false)
const [dataSaverMode, setDataSaverMode] = useState(false)
const { roomName } = useParams()
invariant(roomName)

Expand Down Expand Up @@ -176,6 +177,8 @@ function Room() {
const context: RoomContextType = {
joined,
setJoined,
dataSaverMode,
setDataSaverMode,
traceLink,
userMedia,
userDirectoryUrl,
Expand Down