mirror of https://github.com/vector-im/riot-web
Fix Jitsi for new widget-api
parent
b9b859dd28
commit
82749c3de3
|
@ -20,6 +20,7 @@ require("./index.scss");
|
||||||
import * as qs from 'querystring';
|
import * as qs from 'querystring';
|
||||||
import {KJUR} from 'jsrsasign';
|
import {KJUR} from 'jsrsasign';
|
||||||
import {
|
import {
|
||||||
|
IOpenIDCredentials,
|
||||||
IWidgetApiRequest,
|
IWidgetApiRequest,
|
||||||
IWidgetApiRequestEmptyData,
|
IWidgetApiRequestEmptyData,
|
||||||
VideoConferenceCapabilities,
|
VideoConferenceCapabilities,
|
||||||
|
@ -43,6 +44,7 @@ let avatarUrl: string;
|
||||||
let userId: string;
|
let userId: string;
|
||||||
let jitsiAuth: string;
|
let jitsiAuth: string;
|
||||||
let roomId: string;
|
let roomId: string;
|
||||||
|
let openIdToken: IOpenIDCredentials;
|
||||||
|
|
||||||
let widgetApi: WidgetApi;
|
let widgetApi: WidgetApi;
|
||||||
|
|
||||||
|
@ -72,9 +74,16 @@ let widgetApi: WidgetApi;
|
||||||
widgetApi = new WidgetApi(qsParam("widgetId"), parentOrigin);
|
widgetApi = new WidgetApi(qsParam("widgetId"), parentOrigin);
|
||||||
widgetApi.requestCapabilities(VideoConferenceCapabilities);
|
widgetApi.requestCapabilities(VideoConferenceCapabilities);
|
||||||
readyPromise = Promise.all([
|
readyPromise = Promise.all([
|
||||||
widgetApi.waitFor<CustomEvent<IWidgetApiRequest>>("im.vector.ready")
|
new Promise<void>(resolve => {
|
||||||
.then(ev => widgetApi.transport.reply(ev.detail, {})),
|
widgetApi.once<CustomEvent<IWidgetApiRequest>>("action:im.vector.ready", ev => {
|
||||||
widgetApi.waitFor("ready").then<void>(),
|
ev.preventDefault();
|
||||||
|
widgetApi.transport.reply(ev.detail, {});
|
||||||
|
resolve();
|
||||||
|
});
|
||||||
|
}),
|
||||||
|
new Promise<void>(resolve => {
|
||||||
|
widgetApi.once("ready", () => resolve());
|
||||||
|
}),
|
||||||
]);
|
]);
|
||||||
widgetApi.start();
|
widgetApi.start();
|
||||||
} else {
|
} else {
|
||||||
|
@ -97,8 +106,9 @@ let widgetApi: WidgetApi;
|
||||||
// See https://github.com/matrix-org/prosody-mod-auth-matrix-user-verification
|
// See https://github.com/matrix-org/prosody-mod-auth-matrix-user-verification
|
||||||
if (jitsiAuth === JITSI_OPENIDTOKEN_JWT_AUTH) {
|
if (jitsiAuth === JITSI_OPENIDTOKEN_JWT_AUTH) {
|
||||||
// Request credentials, give callback to continue when received
|
// Request credentials, give callback to continue when received
|
||||||
// TODO: Implement in widget API
|
openIdToken = await widgetApi.requestOpenIDConnectToken();
|
||||||
//widgetApi.requestOpenIDCredentials(credentialsResponseCallback);
|
console.log("Got OpenID Connect token");
|
||||||
|
enableJoinButton();
|
||||||
} else {
|
} else {
|
||||||
enableJoinButton();
|
enableJoinButton();
|
||||||
}
|
}
|
||||||
|
@ -112,19 +122,6 @@ let widgetApi: WidgetApi;
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
|
|
||||||
/**
|
|
||||||
* Enable or show error depending on what the credentials response is.
|
|
||||||
*/
|
|
||||||
function credentialsResponseCallback() {
|
|
||||||
if (widgetApi.openIDCredentials) {
|
|
||||||
console.info('Successfully got OpenID credentials.');
|
|
||||||
enableJoinButton();
|
|
||||||
} else {
|
|
||||||
console.warn('OpenID credentials request was blocked by user.');
|
|
||||||
document.getElementById("widgetActionContainer").innerText = "Failed to load Jitsi widget";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function enableJoinButton() {
|
function enableJoinButton() {
|
||||||
document.getElementById("joinButton").onclick = () => joinConference();
|
document.getElementById("joinButton").onclick = () => joinConference();
|
||||||
}
|
}
|
||||||
|
@ -154,7 +151,7 @@ function createJWTToken() {
|
||||||
room: "*",
|
room: "*",
|
||||||
context: {
|
context: {
|
||||||
matrix: {
|
matrix: {
|
||||||
token: widgetApi.openIDCredentials.accessToken,
|
token: openIdToken.access_token,
|
||||||
room_id: roomId,
|
room_id: roomId,
|
||||||
},
|
},
|
||||||
user: {
|
user: {
|
||||||
|
@ -177,7 +174,7 @@ function createJWTToken() {
|
||||||
function joinConference() { // event handler bound in HTML
|
function joinConference() { // event handler bound in HTML
|
||||||
let jwt;
|
let jwt;
|
||||||
if (jitsiAuth === JITSI_OPENIDTOKEN_JWT_AUTH) {
|
if (jitsiAuth === JITSI_OPENIDTOKEN_JWT_AUTH) {
|
||||||
if (!widgetApi.openIDCredentials || !widgetApi.openIDCredentials.accessToken) {
|
if (!openIdToken?.access_token) {
|
||||||
// We've failing to get a token, don't try to init conference
|
// We've failing to get a token, don't try to init conference
|
||||||
console.warn('Expected to have an OpenID credential, cannot initialize widget.');
|
console.warn('Expected to have an OpenID credential, cannot initialize widget.');
|
||||||
document.getElementById("widgetActionContainer").innerText = "Failed to load Jitsi widget";
|
document.getElementById("widgetActionContainer").innerText = "Failed to load Jitsi widget";
|
||||||
|
|
Loading…
Reference in New Issue