From fcc411f8b93736d00abeecf1403be2627fda5731 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Thu, 8 Oct 2020 15:35:22 -0600 Subject: [PATCH 1/2] Use new preparing event for widget communications Fixes https://github.com/vector-im/element-web/issues/15404 We need to make sure we don't accidentally call the widget before its ready, but we can happily show it once it is loaded/prepared. --- src/components/views/elements/AppTile.js | 7 ++++++- src/stores/widgets/StopGapWidget.ts | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/components/views/elements/AppTile.js b/src/components/views/elements/AppTile.js index 3405d4ff16..fda2652d12 100644 --- a/src/components/views/elements/AppTile.js +++ b/src/components/views/elements/AppTile.js @@ -50,6 +50,7 @@ export default class AppTile extends React.Component { // The key used for PersistedElement this._persistKey = 'widget_' + this.props.app.id; this._sgWidget = new StopGapWidget(this.props); + this._sgWidget.on("preparing", this._onWidgetPrepared); this._sgWidget.on("ready", this._onWidgetReady); this.iframe = null; // ref to the iframe (callback style) @@ -142,6 +143,7 @@ export default class AppTile extends React.Component { this._sgWidget.stop(); } this._sgWidget = new StopGapWidget(newProps); + this._sgWidget.on("preparing", this._onWidgetPrepared); this._sgWidget.on("ready", this._onWidgetReady); this._startWidget(); } @@ -295,8 +297,11 @@ export default class AppTile extends React.Component { this._revokeWidgetPermission(); } - _onWidgetReady = () => { + _onWidgetPrepared = () => { this.setState({loading: false}); + }; + + _onWidgetReady = () => { if (WidgetType.JITSI.matches(this.props.app.type)) { this._sgWidget.widgetApi.transport.send(ElementWidgetActions.ClientReady, {}); } diff --git a/src/stores/widgets/StopGapWidget.ts b/src/stores/widgets/StopGapWidget.ts index 9e4d124d5b..dde756cf3b 100644 --- a/src/stores/widgets/StopGapWidget.ts +++ b/src/stores/widgets/StopGapWidget.ts @@ -163,6 +163,7 @@ export class StopGapWidget extends EventEmitter { if (this.started) return; const driver = new StopGapWidgetDriver( this.appTileProps.whitelistCapabilities || []); this.messaging = new ClientWidgetApi(this.mockWidget, iframe, driver); + this.messaging.addEventListener("preparing", () => this.emit("preparing")); this.messaging.addEventListener("ready", () => this.emit("ready")); WidgetMessagingStore.instance.storeMessaging(this.mockWidget, this.messaging); From 2caf679024742efdd21a5d031fe706fd2763b58a Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Thu, 8 Oct 2020 21:22:17 -0600 Subject: [PATCH 2/2] Update widget-api --- package.json | 2 +- yarn.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 0b371df5fe..532bb1c3e5 100644 --- a/package.json +++ b/package.json @@ -79,7 +79,7 @@ "linkifyjs": "^2.1.9", "lodash": "^4.17.19", "matrix-js-sdk": "8.5.0-rc.1", - "matrix-widget-api": "^0.1.0-beta.2", + "matrix-widget-api": "^0.1.0-beta.3", "minimist": "^1.2.5", "pako": "^1.0.11", "parse5": "^5.1.1", diff --git a/yarn.lock b/yarn.lock index a2c5cd6645..7dc34164d4 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5954,10 +5954,10 @@ matrix-react-test-utils@^0.2.2: resolved "https://registry.yarnpkg.com/matrix-react-test-utils/-/matrix-react-test-utils-0.2.2.tgz#c87144d3b910c7edc544a6699d13c7c2bf02f853" integrity sha512-49+7gfV6smvBIVbeloql+37IeWMTD+fiywalwCqk8Dnz53zAFjKSltB3rmWHso1uecLtQEcPtCijfhzcLXAxTQ== -matrix-widget-api@^0.1.0-beta.2: - version "0.1.0-beta.2" - resolved "https://registry.yarnpkg.com/matrix-widget-api/-/matrix-widget-api-0.1.0-beta.2.tgz#367da1ccd26b711f73fc5b6e02edf55ac2ea2692" - integrity sha512-q5g5RZN+RRjM4HmcJ+LYoQAYrB1wzyERmoQ+LvKbTV/+9Ov36Kp0QEP8CleSXEd5WLp6bkRlt60axDaY6pWGmg== +matrix-widget-api@^0.1.0-beta.3: + version "0.1.0-beta.3" + resolved "https://registry.yarnpkg.com/matrix-widget-api/-/matrix-widget-api-0.1.0-beta.3.tgz#356965ca357172ee056e3fd86fd96879b059a114" + integrity sha512-j7nxdhLQfdU6snsdBA29KQR0DmT8/vl6otOvGqPCV0OCHpq1312cP79Eg4JzJKIFI3A76Qha3nYx6G9/aapwXg== mdast-util-compact@^1.0.0: version "1.0.4"