Skip to content
This repository has been archived by the owner on Dec 1, 2023. It is now read-only.

Commit

Permalink
www: move audio/videoEnabled upstream, to requestingDevices
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfgang42 committed Dec 5, 2022
1 parent bf59085 commit 64355cd
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
23 changes: 15 additions & 8 deletions www/atoms/local.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ export type Local =
| {
status: "requestingDevices";
name: string;
audioEnabled: boolean;
videoEnabled: boolean;
}
| {
status: "connecting";
Expand Down Expand Up @@ -46,18 +48,23 @@ const setAudioVideoEnabled =
return { ...local, audioEnabled, videoEnabled };
};

const setConnecting =
const setConnecting = (local: Local): Local => {
assert(local.status === "requestingDevices");
return { ...local, status: "connecting" };
};

const setRequestingDevices =
(audioEnabled: boolean, videoEnabled: boolean) =>
(local: Local): Local => {
assert(local.status === "requestingDevices");
return { ...local, status: "connecting", audioEnabled, videoEnabled };
assert(local.status === "requestingPermissions");
return {
...local,
status: "requestingDevices",
audioEnabled,
videoEnabled,
};
};

const setRequestingDevices = (local: Local): Local => {
assert(local.status === "requestingPermissions");
return { ...local, status: "requestingDevices" };
};

const setRequestingPermissions =
(name: string) =>
(local: Local): Local => {
Expand Down
4 changes: 1 addition & 3 deletions www/components/room/request-devices.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ export default function RequestDevices() {
}, []);

const joinRoom = React.useCallback(async () => {
const stream = mapGet(streamMap, LocalStreamKey);
const { audioEnabled, videoEnabled } = getVideoAudioEnabled(stream);
setLocal(localActions.setConnecting(audioEnabled, videoEnabled));
setLocal(localActions.setConnecting);
}, [setLocal]);

const handleDeviceChange = React.useCallback(
Expand Down
5 changes: 3 additions & 2 deletions www/components/room/request-permission.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from "react";
import { useSetRecoilState } from "recoil";
import { localActions, localState, LocalStreamKey } from "../../atoms/local";
import { streamMap } from "../../lib/mesh/maps";
import { createLocalStream } from "../../lib/mesh/stream";
import { createLocalStream, getVideoAudioEnabled } from "../../lib/mesh/stream";
import PreForm from "./pre-form";

export default function RequestPermission() {
Expand All @@ -11,7 +11,8 @@ export default function RequestPermission() {
const requestPermissions = React.useCallback(async () => {
const stream = await createLocalStream();
streamMap.set(LocalStreamKey, stream);
setLocal(localActions.setRequestingDevices);
const { audioEnabled, videoEnabled } = getVideoAudioEnabled(stream);
setLocal(localActions.setRequestingDevices(audioEnabled, videoEnabled));
}, [setLocal]);

return (
Expand Down

0 comments on commit 64355cd

Please sign in to comment.