Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Fix popout support for jitsi widgets #4319

Merged
merged 5 commits into from
Apr 1, 2020
Merged
Show file tree
Hide file tree
Changes from 4 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
10 changes: 1 addition & 9 deletions src/FromWidgetPostMessageApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ import {MatrixClientPeg} from "./MatrixClientPeg";
import RoomViewStore from "./stores/RoomViewStore";
import {IntegrationManagers} from "./integrations/IntegrationManagers";
import SettingsStore from "./settings/SettingsStore";
import {Capability, KnownWidgetActions} from "./widgets/WidgetApi";
import SdkConfig from "./SdkConfig";
import {Capability} from "./widgets/WidgetApi";

const WIDGET_API_VERSION = '0.0.2'; // Current API version
const SUPPORTED_WIDGET_API_VERSIONS = [
Expand Down Expand Up @@ -220,13 +219,6 @@ export default class FromWidgetPostMessageApi {
}
} else if (action === 'get_openid') {
// Handled by caller
} else if (action === KnownWidgetActions.GetRiotWebConfig) {
if (ActiveWidgetStore.widgetHasCapability(widgetId, Capability.GetRiotWebConfig)) {
this.sendResponse(event, {
api: INBOUND_API_NAME,
config: SdkConfig.get(),
});
}
} else {
console.warn('Widget postMessage event unhandled');
this.sendError(event, {message: 'The postMessage was unhandled'});
Expand Down
2 changes: 0 additions & 2 deletions src/SdkConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ export const DEFAULTS: ConfigOptions = {
jitsi: {
// Default conference domain
preferredDomain: "jitsi.riot.im",
// Default Jitsi Meet API location
externalApiUrl: "https://jitsi.riot.im/libs/external_api.min.js",
},
};

Expand Down
178 changes: 121 additions & 57 deletions src/components/views/elements/AppTile.js

Large diffs are not rendered by default.

8 changes: 2 additions & 6 deletions src/components/views/elements/PersistentApp.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
Copyright 2018 New Vector Ltd
Copyright 2019 The Matrix.org Foundation C.I.C.
Copyright 2019, 2020 The Matrix.org Foundation C.I.C.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -75,11 +75,7 @@ export default createReactClass({
const AppTile = sdk.getComponent('elements.AppTile');
return <AppTile
key={app.id}
id={app.id}
eventId={app.eventId}
url={app.url}
name={app.name}
type={app.type}
app={app}
fullWidth={true}
room={persistentWidgetInRoom}
userId={MatrixClientPeg.get().credentials.userId}
Expand Down
6 changes: 1 addition & 5 deletions src/components/views/rooms/AppsDrawer.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,7 @@ export default createReactClass({

return (<AppTile
key={app.id}
id={app.id}
eventId={app.eventId}
url={app.url}
name={app.name}
type={app.type}
app={app}
fullWidth={arr.length<2 ? true : false}
room={this.props.room}
userId={this.props.userId}
Expand Down
13 changes: 9 additions & 4 deletions src/components/views/rooms/Stickerpicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,14 @@ export default class Stickerpicker extends React.Component {
// Set default name
stickerpickerWidget.content.name = stickerpickerWidget.name || _t("Stickerpack");

// FIXME: could this use the same code as other apps?
const stickerApp = {
id: stickerpickerWidget.id,
url: stickerpickerWidget.content.url,
name: stickerpickerWidget.content.name,
type: stickerpickerWidget.content.type,
};

stickersContent = (
<div className='mx_Stickers_content_container'>
<div
Expand All @@ -253,11 +261,8 @@ export default class Stickerpicker extends React.Component {
>
<PersistedElement persistKey={PERSISTED_ELEMENT_KEY} style={{zIndex: STICKERPICKER_Z_INDEX}}>
<AppTile
id={stickerpickerWidget.id}
url={stickerpickerWidget.content.url}
name={stickerpickerWidget.content.name}
app={stickerApp}
room={this.props.room}
type={stickerpickerWidget.content.type}
fullWidth={true}
userId={MatrixClientPeg.get().credentials.userId}
creatorUserId={stickerpickerWidget.sender || MatrixClientPeg.get().credentials.userId}
Expand Down
9 changes: 6 additions & 3 deletions src/utils/AutoDiscoveryUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {makeType} from "./TypeUtils";
import SdkConfig from '../SdkConfig';

const LIVELINESS_DISCOVERY_ERRORS = [
AutoDiscovery.ERROR_INVALID,
dbkr marked this conversation as resolved.
Show resolved Hide resolved
AutoDiscovery.ERROR_INVALID_HOMESERVER,
AutoDiscovery.ERROR_INVALID_IDENTITY_SERVER,
];
Expand Down Expand Up @@ -232,19 +233,21 @@ export default class AutoDiscoveryUtils {
const preferredHomeserverUrl = hsResult["base_url"];
let preferredHomeserverName = serverName ? serverName : hsResult["server_name"];

const url = new URL(preferredHomeserverUrl);
if (!preferredHomeserverName) preferredHomeserverName = url.hostname;
const url = preferredHomeserverUrl ? new URL(preferredHomeserverUrl) : null;
if (!preferredHomeserverName && url) preferredHomeserverName = url.hostname;

// It should have been set by now, so check it
if (!preferredHomeserverName) {
console.error("Failed to parse homeserver name from homeserver URL");
throw newTranslatableError(_td("Unexpected error resolving homeserver configuration"));
}

const hsNameIsDifferent = url ? (url.hostname !== preferredHomeserverName) : null;

return makeType(ValidatedServerConfig, {
hsUrl: preferredHomeserverUrl,
hsName: preferredHomeserverName,
hsNameIsDifferent: url.hostname !== preferredHomeserverName,
hsNameIsDifferent,
isUrl: preferredIdentityUrl,
isDefault: false,
warning: hsResult.error,
Expand Down
59 changes: 0 additions & 59 deletions src/utils/WidgetUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,26 +30,6 @@ import ActiveWidgetStore from "../stores/ActiveWidgetStore";
import {IntegrationManagers} from "../integrations/IntegrationManagers";
import {Capability} from "../widgets/WidgetApi";

/**
* Encodes a URI according to a set of template variables. Variables will be
* passed through encodeURIComponent.
* @param {string} pathTemplate The path with template variables e.g. '/foo/$bar'.
* @param {Object} variables The key/value pairs to replace the template
* variables with. E.g. { '$bar': 'baz' }.
* @return {string} The result of replacing all template variables e.g. '/foo/baz'.
*/
function encodeUri(pathTemplate, variables) {
for (const key in variables) {
if (!variables.hasOwnProperty(key)) {
continue;
}
pathTemplate = pathTemplate.replace(
key, encodeURIComponent(variables[key]),
);
}
return pathTemplate;
}

export default class WidgetUtils {
/* Returns true if user is able to send state events to modify widgets in this room
* (Does not apply to non-room-based / user widgets)
Expand Down Expand Up @@ -402,18 +382,6 @@ export default class WidgetUtils {
}

static makeAppConfig(appId, app, senderUserId, roomId, eventId) {
const myUserId = MatrixClientPeg.get().credentials.userId;
const user = MatrixClientPeg.get().getUser(myUserId);
const params = {
'$matrix_user_id': myUserId,
'$matrix_room_id': roomId,
'$matrix_display_name': user ? user.displayName : myUserId,
'$matrix_avatar_url': user ? MatrixClientPeg.get().mxcUrlToHttp(user.avatarUrl) : '',

// TODO: Namespace themes through some standard
'$theme': SettingsStore.getValue("theme"),
};

if (!senderUserId) {
throw new Error("Widgets must be created by someone - provide a senderUserId");
}
Expand All @@ -423,32 +391,6 @@ export default class WidgetUtils {
app.eventId = eventId;
app.name = app.name || app.type;

if (app.type === 'jitsi') {
console.log("Replacing Jitsi widget URL with local wrapper");
if (!app.data || !app.data.conferenceId) {
// Assumed to be a v1 widget: add a data object for visibility on the wrapper
// TODO: Remove this once mobile supports v2 widgets
console.log("Replacing v1 Jitsi widget with v2 equivalent");
jryans marked this conversation as resolved.
Show resolved Hide resolved
const parsed = new URL(app.url);
app.data = {
conferenceId: parsed.searchParams.get("confId"),
domain: "jitsi.riot.im", // v1 widgets have this hardcoded
};
}

app.url = WidgetUtils.getLocalJitsiWrapperUrl({forLocalRender: true});
}

if (app.data) {
Object.keys(app.data).forEach((key) => {
params['$' + key] = app.data[key];
});

app.waitForIframeLoad = (app.data.waitForIframeLoad === 'false' ? false : true);
}

app.url = encodeUri(app.url, params);

return app;
}

Expand All @@ -462,7 +404,6 @@ export default class WidgetUtils {
// widgets from at all, but it probably makes sense for sanity.
if (appType === 'jitsi') {
capWhitelist.push(Capability.AlwaysOnScreen);
capWhitelist.push(Capability.GetRiotWebConfig);
}

return capWhitelist;
Expand Down
10 changes: 0 additions & 10 deletions src/widgets/WidgetApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ export enum Capability {
Screenshot = "m.capability.screenshot",
Sticker = "m.sticker",
AlwaysOnScreen = "m.always_on_screen",
GetRiotWebConfig = "im.vector.web.riot_config",
}

export enum KnownWidgetActions {
Expand All @@ -34,7 +33,6 @@ export enum KnownWidgetActions {
UpdateVisibility = "visibility",
ReceiveOpenIDCredentials = "openid_credentials",
SetAlwaysOnScreen = "set_always_on_screen",
GetRiotWebConfig = "im.vector.web.riot_config",
ClientReady = "im.vector.ready",
}

Expand Down Expand Up @@ -157,12 +155,4 @@ export class WidgetApi {
resolve(); // SetAlwaysOnScreen is currently fire-and-forget, but that could change.
});
}

public getRiotConfig(): Promise<any> {
return new Promise<any>(resolve => {
this.callAction(KnownWidgetActions.GetRiotWebConfig, {}, response => {
resolve(response.response.config);
});
});
}
}