mirror of
https://github.com/element-hq/element-web
synced 2024-11-22 01:05:42 +03:00
Fix Jitsi by updating device mute updates over postMessage API
Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
parent
334d268555
commit
dd17436eb0
1 changed files with 25 additions and 27 deletions
|
@ -34,7 +34,6 @@ import type {
|
||||||
JitsiMeetExternalAPIConstructor,
|
JitsiMeetExternalAPIConstructor,
|
||||||
ExternalAPIEventCallbacks,
|
ExternalAPIEventCallbacks,
|
||||||
JitsiMeetExternalAPI as _JitsiMeetExternalAPI,
|
JitsiMeetExternalAPI as _JitsiMeetExternalAPI,
|
||||||
AudioMuteStatusChangedEvent,
|
|
||||||
LogEvent,
|
LogEvent,
|
||||||
VideoMuteStatusChangedEvent,
|
VideoMuteStatusChangedEvent,
|
||||||
ExternalAPIOptions as _ExternalAPIOptions,
|
ExternalAPIOptions as _ExternalAPIOptions,
|
||||||
|
@ -159,7 +158,7 @@ const setupCompleted = (async (): Promise<string | void> => {
|
||||||
|
|
||||||
const handleAction = (
|
const handleAction = (
|
||||||
action: WidgetApiAction,
|
action: WidgetApiAction,
|
||||||
handler: (request: IWidgetApiRequestData) => Promise<void>,
|
handler: (request: IWidgetApiRequestData) => Promise<IWidgetApiResponseData | void>,
|
||||||
): void => {
|
): void => {
|
||||||
widgetApi!.on(`action:${action}`, async (ev: CustomEvent<IWidgetApiRequest>) => {
|
widgetApi!.on(`action:${action}`, async (ev: CustomEvent<IWidgetApiRequest>) => {
|
||||||
ev.preventDefault();
|
ev.preventDefault();
|
||||||
|
@ -167,8 +166,7 @@ const setupCompleted = (async (): Promise<string | void> => {
|
||||||
|
|
||||||
let response: IWidgetApiResponseData;
|
let response: IWidgetApiResponseData;
|
||||||
try {
|
try {
|
||||||
await handler(ev.detail.data);
|
response = (await handler(ev.detail.data)) ?? {};
|
||||||
response = {};
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e instanceof Error) {
|
if (e instanceof Error) {
|
||||||
response = { error: { message: e.message } };
|
response = { error: { message: e.message } };
|
||||||
|
@ -194,25 +192,24 @@ const setupCompleted = (async (): Promise<string | void> => {
|
||||||
meetApi?.executeCommand("hangup");
|
meetApi?.executeCommand("hangup");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
handleAction(ElementWidgetActions.MuteAudio, async () => {
|
handleAction(ElementWidgetActions.DeviceMute, async (params) => {
|
||||||
if (meetApi && !(await meetApi.isAudioMuted())) {
|
if (!meetApi) return;
|
||||||
|
|
||||||
|
if (Object.keys(params).length === 0) {
|
||||||
|
// Handle query
|
||||||
|
return {
|
||||||
|
audio_enabled: !(await meetApi.isAudioMuted()),
|
||||||
|
video_enabled: !(await meetApi.isVideoMuted()),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (params.audio_enabled !== !(await meetApi.isAudioMuted())) {
|
||||||
meetApi.executeCommand("toggleAudio");
|
meetApi.executeCommand("toggleAudio");
|
||||||
}
|
}
|
||||||
});
|
if (params.video_enabled !== !(await meetApi.isVideoMuted())) {
|
||||||
handleAction(ElementWidgetActions.UnmuteAudio, async () => {
|
|
||||||
if (meetApi && (await meetApi.isAudioMuted())) {
|
|
||||||
meetApi.executeCommand("toggleAudio");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
handleAction(ElementWidgetActions.MuteVideo, async () => {
|
|
||||||
if (meetApi && !(await meetApi.isVideoMuted())) {
|
|
||||||
meetApi.executeCommand("toggleVideo");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
handleAction(ElementWidgetActions.UnmuteVideo, async () => {
|
|
||||||
if (meetApi && (await meetApi.isVideoMuted())) {
|
|
||||||
meetApi.executeCommand("toggleVideo");
|
meetApi.executeCommand("toggleVideo");
|
||||||
}
|
}
|
||||||
|
return params;
|
||||||
});
|
});
|
||||||
handleAction(ElementWidgetActions.TileLayout, async () => {
|
handleAction(ElementWidgetActions.TileLayout, async () => {
|
||||||
meetApi?.executeCommand("setTileView", true);
|
meetApi?.executeCommand("setTileView", true);
|
||||||
|
@ -473,7 +470,7 @@ async function joinConference(audioInput?: string | null, videoInput?: string |
|
||||||
meetApi.on("videoConferenceLeft", onVideoConferenceLeft);
|
meetApi.on("videoConferenceLeft", onVideoConferenceLeft);
|
||||||
meetApi.on("readyToClose", closeConference as ExternalAPIEventCallbacks["readyToClose"]);
|
meetApi.on("readyToClose", closeConference as ExternalAPIEventCallbacks["readyToClose"]);
|
||||||
meetApi.on("errorOccurred", onErrorOccurred);
|
meetApi.on("errorOccurred", onErrorOccurred);
|
||||||
meetApi.on("audioMuteStatusChanged", onAudioMuteStatusChanged);
|
meetApi.on("audioMuteStatusChanged", onMuteStatusChanged);
|
||||||
meetApi.on("videoMuteStatusChanged", onVideoMuteStatusChanged);
|
meetApi.on("videoMuteStatusChanged", onVideoMuteStatusChanged);
|
||||||
|
|
||||||
(["videoConferenceJoined", "participantJoined", "participantLeft"] as const).forEach((event) => {
|
(["videoConferenceJoined", "participantJoined", "participantLeft"] as const).forEach((event) => {
|
||||||
|
@ -523,9 +520,12 @@ const onErrorOccurred = ({ error }: Parameters<ExternalAPIEventCallbacks["errorO
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const onAudioMuteStatusChanged = ({ muted }: AudioMuteStatusChangedEvent): void => {
|
const onMuteStatusChanged = async (): Promise<void> => {
|
||||||
const action = muted ? ElementWidgetActions.MuteAudio : ElementWidgetActions.UnmuteAudio;
|
if (!meetApi) return;
|
||||||
void widgetApi?.transport.send(action, {});
|
void widgetApi?.transport.send(ElementWidgetActions.DeviceMute, {
|
||||||
|
audio_enabled: !(await meetApi.isAudioMuted()),
|
||||||
|
video_enabled: !(await meetApi.isVideoMuted()),
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const onVideoMuteStatusChanged = ({ muted }: VideoMuteStatusChangedEvent): void => {
|
const onVideoMuteStatusChanged = ({ muted }: VideoMuteStatusChangedEvent): void => {
|
||||||
|
@ -534,11 +534,9 @@ const onVideoMuteStatusChanged = ({ muted }: VideoMuteStatusChangedEvent): void
|
||||||
// hanging up, which we need to ignore by padding the timeout here,
|
// hanging up, which we need to ignore by padding the timeout here,
|
||||||
// otherwise the React SDK will mistakenly think the user turned off
|
// otherwise the React SDK will mistakenly think the user turned off
|
||||||
// their video by hand
|
// their video by hand
|
||||||
setTimeout(() => {
|
setTimeout(() => onMuteStatusChanged, 200);
|
||||||
if (meetApi) void widgetApi?.transport.send(ElementWidgetActions.MuteVideo, {});
|
|
||||||
}, 200);
|
|
||||||
} else {
|
} else {
|
||||||
void widgetApi?.transport.send(ElementWidgetActions.UnmuteVideo, {});
|
void onMuteStatusChanged();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue