mirror of https://github.com/vector-im/riot-web
Connect to Jitsi unmuted by default (#22660)
* Connect to Jitsi unmuted by default * Refactor joinConference to placate SonarQubepull/22665/head
parent
9eda502a9b
commit
5f176fa9a6
|
@ -146,7 +146,7 @@ const ack = (ev: CustomEvent<IWidgetApiRequest>) => widgetApi.transport.reply(ev
|
|||
widgetApi.on(`action:${ElementWidgetActions.JoinCall}`,
|
||||
(ev: CustomEvent<IWidgetApiRequest>) => {
|
||||
const { audioDevice, videoDevice } = ev.detail.data;
|
||||
joinConference(audioDevice as string, videoDevice as string);
|
||||
joinConference(audioDevice as string | null, videoDevice as string | null);
|
||||
ack(ev);
|
||||
},
|
||||
);
|
||||
|
@ -322,7 +322,11 @@ function closeConference() {
|
|||
}
|
||||
|
||||
// event handler bound in HTML
|
||||
function joinConference(audioDevice?: string, videoDevice?: string) {
|
||||
// An audio device of undefined instructs Jitsi to start unmuted with whatever
|
||||
// audio device it can find, while a device of null instructs it to start muted,
|
||||
// and a non-nullish device specifies the label of a specific device to use.
|
||||
// Same for video devices.
|
||||
function joinConference(audioDevice?: string | null, videoDevice?: string | null) {
|
||||
let jwt;
|
||||
if (jitsiAuth === JITSI_OPENIDTOKEN_JWT_AUTH) {
|
||||
if (!openIdToken?.access_token) { // eslint-disable-line camelcase
|
||||
|
@ -364,8 +368,8 @@ function joinConference(audioDevice?: string, videoDevice?: string) {
|
|||
configOverwrite: {
|
||||
subject: roomName,
|
||||
startAudioOnly,
|
||||
startWithAudioMuted: audioDevice == null,
|
||||
startWithVideoMuted: videoDevice == null,
|
||||
startWithAudioMuted: audioDevice === null,
|
||||
startWithVideoMuted: videoDevice === null,
|
||||
// Request some log levels for inclusion in rageshakes
|
||||
// Ideally we would capture all possible log levels, but this can
|
||||
// cause Jitsi Meet to try to post various circular data structures
|
||||
|
@ -393,7 +397,22 @@ function joinConference(audioDevice?: string, videoDevice?: string) {
|
|||
|
||||
// fires once when user joins the conference
|
||||
// (regardless of video on or off)
|
||||
meetApi.on("videoConferenceJoined", () => {
|
||||
meetApi.on("videoConferenceJoined", onVideoConferenceJoined);
|
||||
meetApi.on("videoConferenceLeft", onVideoConferenceLeft);
|
||||
meetApi.on("readyToClose", closeConference);
|
||||
meetApi.on("errorOccurred", onErrorOccurred);
|
||||
meetApi.on("audioMuteStatusChanged", onAudioMuteStatusChanged);
|
||||
meetApi.on("videoMuteStatusChanged", onVideoMuteStatusChanged);
|
||||
|
||||
["videoConferenceJoined", "participantJoined", "participantLeft"].forEach(event => {
|
||||
meetApi.on(event, updateParticipants);
|
||||
});
|
||||
|
||||
// Patch logs into rageshakes
|
||||
meetApi.on("log", onLog);
|
||||
}
|
||||
|
||||
const onVideoConferenceJoined = () => {
|
||||
// Although we set our displayName with the userInfo option above, that
|
||||
// option has a bug where it causes the name to be the HTML encoding of
|
||||
// what was actually intended. So, we use the displayName command to at
|
||||
|
@ -415,16 +434,14 @@ function joinConference(audioDevice?: string, videoDevice?: string) {
|
|||
|
||||
// Video rooms should start in tile mode
|
||||
if (isVideoChannel) meetApi.executeCommand("setTileView", true);
|
||||
});
|
||||
};
|
||||
|
||||
meetApi.on("videoConferenceLeft", () => {
|
||||
const onVideoConferenceLeft = () => {
|
||||
notifyHangup();
|
||||
meetApi = null;
|
||||
});
|
||||
};
|
||||
|
||||
meetApi.on("readyToClose", closeConference);
|
||||
|
||||
meetApi.on("errorOccurred", ({ error }) => {
|
||||
const onErrorOccurred = ({ error }) => {
|
||||
if (error.isFatal) {
|
||||
// We got disconnected. Since Jitsi Meet might send us back to the
|
||||
// prejoin screen, we're forced to act as if we hung up entirely.
|
||||
|
@ -432,14 +449,14 @@ function joinConference(audioDevice?: string, videoDevice?: string) {
|
|||
meetApi = null;
|
||||
closeConference();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
meetApi.on("audioMuteStatusChanged", ({ muted }) => {
|
||||
const onAudioMuteStatusChanged = ({ muted }) => {
|
||||
const action = muted ? ElementWidgetActions.MuteAudio : ElementWidgetActions.UnmuteAudio;
|
||||
widgetApi?.transport.send(action, {});
|
||||
});
|
||||
};
|
||||
|
||||
meetApi.on("videoMuteStatusChanged", ({ muted }) => {
|
||||
const onVideoMuteStatusChanged = ({ muted }) => {
|
||||
if (muted) {
|
||||
// Jitsi Meet always sends a "video muted" event directly before
|
||||
// hanging up, which we need to ignore by padding the timeout here,
|
||||
|
@ -451,18 +468,13 @@ function joinConference(audioDevice?: string, videoDevice?: string) {
|
|||
} else {
|
||||
widgetApi?.transport.send(ElementWidgetActions.UnmuteVideo, {});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
["videoConferenceJoined", "participantJoined", "participantLeft"].forEach(event => {
|
||||
meetApi.on(event, () => {
|
||||
const updateParticipants = () => {
|
||||
widgetApi?.transport.send(ElementWidgetActions.CallParticipants, {
|
||||
participants: meetApi.getParticipantsInfo(),
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
// Patch logs into rageshakes
|
||||
meetApi.on("log", ({ logLevel, args }) =>
|
||||
(parent as unknown as typeof global).mx_rage_logger?.log(logLevel, ...args),
|
||||
);
|
||||
}
|
||||
const onLog = ({ logLevel, args }) =>
|
||||
(parent as unknown as typeof global).mx_rage_logger?.log(logLevel, ...args);
|
||||
|
|
Loading…
Reference in New Issue