Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Voice rooms prototype #21476

Merged
merged 7 commits into from
Mar 22, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/labs.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,3 +196,7 @@ Threading allows users to branch out a new conversation from the main timeline o
Threads can be access by clicking their summary below the root event on the room timeline. Users can find a comprehensive list of threads by click the icon on the room header button.

This feature might work in degraded mode if the homeserver a user is connected to does not advertise support for the unstable feature `org.matrix.msc3440` when calling the `/versions` API endpoint.

## Voice & video rooms (`feature_voice_rooms`) [In Development]

Enables support for creating and joining voice & video rooms, which are persistent voice chats that users can jump in and out of.
74 changes: 67 additions & 7 deletions src/vector/jitsi/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ let widgetApi: WidgetApi;
let meetApi: any; // JitsiMeetExternalAPI
let skipOurWelcomeScreen = false;

const ack = (ev: CustomEvent<IWidgetApiRequest>) => widgetApi.transport.reply(ev.detail, {});

(async function() {
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 @@ -133,7 +135,6 @@ let skipOurWelcomeScreen = false;

if (widgetApi) {
await readyPromise;
await widgetApi.setAlwaysOnScreen(false); // start off as detachable from the screen

// See https://github.com/matrix-org/prosody-mod-auth-matrix-user-verification
if (jitsiAuth === JITSI_OPENIDTOKEN_JWT_AUTH) {
Expand All @@ -142,12 +143,48 @@ let skipOurWelcomeScreen = false;
logger.log("Got OpenID Connect token");
}

// TODO: register widgetApi listeners for PTT controls (https://github.com/vector-im/element-web/issues/12795)

widgetApi.on(`action:${ElementWidgetActions.JoinCall}`,
(ev: CustomEvent<IWidgetApiRequest>) => {
joinConference();
ack(ev);
},
);
widgetApi.on(`action:${ElementWidgetActions.HangupCall}`,
(ev: CustomEvent<IWidgetApiRequest>) => {
if (meetApi) meetApi.executeCommand('hangup');
widgetApi.transport.reply(ev.detail, {}); // ack
meetApi?.executeCommand('hangup');
ack(ev);
},
);
widgetApi.on(`action:${ElementWidgetActions.MuteAudio}`,
async (ev: CustomEvent<IWidgetApiRequest>) => {
if (meetApi && !await meetApi.isAudioMuted()) {
meetApi.executeCommand('toggleAudio');
}
ack(ev);
},
);
widgetApi.on(`action:${ElementWidgetActions.UnmuteAudio}`,
async (ev: CustomEvent<IWidgetApiRequest>) => {
if (meetApi && await meetApi.isAudioMuted()) {
meetApi.executeCommand('toggleAudio');
}
ack(ev);
},
);
widgetApi.on(`action:${ElementWidgetActions.MuteVideo}`,
async (ev: CustomEvent<IWidgetApiRequest>) => {
if (meetApi && !await meetApi.isVideoMuted()) {
meetApi.executeCommand('toggleVideo');
}
ack(ev);
},
);
widgetApi.on(`action:${ElementWidgetActions.UnmuteVideo}`,
async (ev: CustomEvent<IWidgetApiRequest>) => {
if (meetApi && await meetApi.isVideoMuted()) {
meetApi.executeCommand('toggleVideo');
}
ack(ev);
},
);
widgetApi.on(`action:${ElementWidgetActions.StartLiveStream}`,
Expand All @@ -160,7 +197,7 @@ let skipOurWelcomeScreen = false;
//rtmpStreamKey: ev.detail.data.rtmpStreamKey,
youtubeStreamKey: ev.detail.data.rtmpStreamKey,
});
widgetApi.transport.reply(ev.detail, {}); // ack
ack(ev);
} else {
widgetApi.transport.reply(ev.detail, { error: { message: "Conference not joined" } });
}
Expand Down Expand Up @@ -293,16 +330,21 @@ function joinConference() { // event handler bound in HTML
// ignored promise because we don't care if it works
// noinspection JSIgnoredPromiseFromCall
widgetApi.setAlwaysOnScreen(true);
widgetApi.transport.send(ElementWidgetActions.JoinCall, {});
}
});

meetApi.on("readyToClose", () => {
switchVisibleContainers();

if (widgetApi) {
// We send the hangup event before setAlwaysOnScreen, because the latter
// can cause the receiving side to instantly stop listening.
// ignored promise because we don't care if it works
// noinspection JSIgnoredPromiseFromCall
widgetApi.setAlwaysOnScreen(false);
widgetApi.transport.send(ElementWidgetActions.HangupCall, {}).then(() =>
widgetApi.setAlwaysOnScreen(false),
);
}

document.getElementById("jitsiContainer").innerHTML = "";
Expand All @@ -312,4 +354,22 @@ function joinConference() { // event handler bound in HTML
skipToJitsiSplashScreen();
}
});

meetApi.on("audioMuteStatusChanged", ({ muted }) => {
const action = muted ? ElementWidgetActions.MuteAudio : ElementWidgetActions.UnmuteAudio;
widgetApi.transport.send(action, {});
});

meetApi.on("videoMuteStatusChanged", ({ muted }) => {
const action = muted ? ElementWidgetActions.MuteVideo : ElementWidgetActions.UnmuteVideo;
widgetApi.transport.send(action, {});
});

["videoConferenceJoined", "participantJoined", "participantLeft"].forEach(event => {
meetApi.on(event, () => {
widgetApi?.transport.send(ElementWidgetActions.CallParticipants, {
participants: meetApi.getParticipantsInfo(),
});
});
});
}