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}`,
|
widgetApi.on(`action:${ElementWidgetActions.JoinCall}`,
|
||||||
(ev: CustomEvent<IWidgetApiRequest>) => {
|
(ev: CustomEvent<IWidgetApiRequest>) => {
|
||||||
const { audioDevice, videoDevice } = ev.detail.data;
|
const { audioDevice, videoDevice } = ev.detail.data;
|
||||||
joinConference(audioDevice as string, videoDevice as string);
|
joinConference(audioDevice as string | null, videoDevice as string | null);
|
||||||
ack(ev);
|
ack(ev);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
@ -322,7 +322,11 @@ function closeConference() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// event handler bound in HTML
|
// 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;
|
let jwt;
|
||||||
if (jitsiAuth === JITSI_OPENIDTOKEN_JWT_AUTH) {
|
if (jitsiAuth === JITSI_OPENIDTOKEN_JWT_AUTH) {
|
||||||
if (!openIdToken?.access_token) { // eslint-disable-line camelcase
|
if (!openIdToken?.access_token) { // eslint-disable-line camelcase
|
||||||
|
@ -364,8 +368,8 @@ function joinConference(audioDevice?: string, videoDevice?: string) {
|
||||||
configOverwrite: {
|
configOverwrite: {
|
||||||
subject: roomName,
|
subject: roomName,
|
||||||
startAudioOnly,
|
startAudioOnly,
|
||||||
startWithAudioMuted: audioDevice == null,
|
startWithAudioMuted: audioDevice === null,
|
||||||
startWithVideoMuted: videoDevice == null,
|
startWithVideoMuted: videoDevice === null,
|
||||||
// Request some log levels for inclusion in rageshakes
|
// Request some log levels for inclusion in rageshakes
|
||||||
// Ideally we would capture all possible log levels, but this can
|
// Ideally we would capture all possible log levels, but this can
|
||||||
// cause Jitsi Meet to try to post various circular data structures
|
// 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
|
// fires once when user joins the conference
|
||||||
// (regardless of video on or off)
|
// (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
|
// 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
|
// 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
|
// 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
|
// Video rooms should start in tile mode
|
||||||
if (isVideoChannel) meetApi.executeCommand("setTileView", true);
|
if (isVideoChannel) meetApi.executeCommand("setTileView", true);
|
||||||
});
|
};
|
||||||
|
|
||||||
meetApi.on("videoConferenceLeft", () => {
|
const onVideoConferenceLeft = () => {
|
||||||
notifyHangup();
|
notifyHangup();
|
||||||
meetApi = null;
|
meetApi = null;
|
||||||
});
|
};
|
||||||
|
|
||||||
meetApi.on("readyToClose", closeConference);
|
const onErrorOccurred = ({ error }) => {
|
||||||
|
|
||||||
meetApi.on("errorOccurred", ({ error }) => {
|
|
||||||
if (error.isFatal) {
|
if (error.isFatal) {
|
||||||
// We got disconnected. Since Jitsi Meet might send us back to the
|
// 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.
|
// 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;
|
meetApi = null;
|
||||||
closeConference();
|
closeConference();
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
|
|
||||||
meetApi.on("audioMuteStatusChanged", ({ muted }) => {
|
const onAudioMuteStatusChanged = ({ muted }) => {
|
||||||
const action = muted ? ElementWidgetActions.MuteAudio : ElementWidgetActions.UnmuteAudio;
|
const action = muted ? ElementWidgetActions.MuteAudio : ElementWidgetActions.UnmuteAudio;
|
||||||
widgetApi?.transport.send(action, {});
|
widgetApi?.transport.send(action, {});
|
||||||
});
|
};
|
||||||
|
|
||||||
meetApi.on("videoMuteStatusChanged", ({ muted }) => {
|
const onVideoMuteStatusChanged = ({ muted }) => {
|
||||||
if (muted) {
|
if (muted) {
|
||||||
// Jitsi Meet always sends a "video muted" event directly before
|
// Jitsi Meet always sends a "video muted" event directly before
|
||||||
// hanging up, which we need to ignore by padding the timeout here,
|
// hanging up, which we need to ignore by padding the timeout here,
|
||||||
|
@ -451,18 +468,13 @@ function joinConference(audioDevice?: string, videoDevice?: string) {
|
||||||
} else {
|
} else {
|
||||||
widgetApi?.transport.send(ElementWidgetActions.UnmuteVideo, {});
|
widgetApi?.transport.send(ElementWidgetActions.UnmuteVideo, {});
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
|
|
||||||
["videoConferenceJoined", "participantJoined", "participantLeft"].forEach(event => {
|
const updateParticipants = () => {
|
||||||
meetApi.on(event, () => {
|
|
||||||
widgetApi?.transport.send(ElementWidgetActions.CallParticipants, {
|
widgetApi?.transport.send(ElementWidgetActions.CallParticipants, {
|
||||||
participants: meetApi.getParticipantsInfo(),
|
participants: meetApi.getParticipantsInfo(),
|
||||||
});
|
});
|
||||||
});
|
};
|
||||||
});
|
|
||||||
|
|
||||||
// Patch logs into rageshakes
|
const onLog = ({ logLevel, args }) =>
|
||||||
meetApi.on("log", ({ logLevel, args }) =>
|
(parent as unknown as typeof global).mx_rage_logger?.log(logLevel, ...args);
|
||||||
(parent as unknown as typeof global).mx_rage_logger?.log(logLevel, ...args),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue