Skip to content

Commit

Permalink
DRY
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
  • Loading branch information
t3chguy committed Jul 25, 2024
1 parent 5a1b38c commit 88ddf05
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/vector/jitsi/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,14 @@ let widgetApi: WidgetApi | undefined;
let meetApi: _JitsiMeetExternalAPI | undefined;
let skipOurWelcomeScreen = false;

async function checkAudioVideoEnabled(): Promise<[audioEnabled: boolean, videoEnabled: boolean]> {
if (!meetApi) return [false, false];
const [audioEnabled, videoEnabled] = (await Promise.all([meetApi.isAudioMuted(), meetApi.isVideoMuted()])).map(
(muted) => !muted,
);
return [audioEnabled, videoEnabled];
}

const setupCompleted = (async (): Promise<string | void> => {
try {
// Queue a config.json lookup asap, so we can use it later on. We want this to be concurrent with
Expand Down Expand Up @@ -195,9 +203,7 @@ const setupCompleted = (async (): Promise<string | void> => {
handleAction(ElementWidgetActions.DeviceMute, async (params) => {
if (!meetApi) return;

const [audioEnabled, videoEnabled] = (
await Promise.all([meetApi.isAudioMuted(), meetApi.isVideoMuted()])
).map((muted) => !muted);
const [audioEnabled, videoEnabled] = await checkAudioVideoEnabled();

if (Object.keys(params).length === 0) {
// Handle query
Expand Down Expand Up @@ -526,9 +532,10 @@ const onErrorOccurred = ({ error }: Parameters<ExternalAPIEventCallbacks["errorO

const onMuteStatusChanged = async (): Promise<void> => {
if (!meetApi) return;
const [audioEnabled, videoEnabled] = await checkAudioVideoEnabled();
void widgetApi?.transport.send(ElementWidgetActions.DeviceMute, {
audio_enabled: !(await meetApi.isAudioMuted()),
video_enabled: !(await meetApi.isVideoMuted()),
audio_enabled: audioEnabled,
video_enabled: videoEnabled,
});
};

Expand Down

0 comments on commit 88ddf05

Please sign in to comment.