This commit is contained in:
Richard Lewis 2018-01-18 12:02:45 +00:00
parent f8d7ab10fa
commit 1293c53c4b

View file

@ -160,10 +160,30 @@ export default class AppTile extends React.Component {
// postMessaging API // postMessaging API
window.addEventListener('message', this._onMessage, false); window.addEventListener('message', this._onMessage, false);
// General event handler // Widget action listeners
this.dispatcherRef = dis.register(this._onWidgetAction); this.dispatcherRef = dis.register(this._onWidgetAction);
} }
componentWillUnmount() {
// Widget action listeners
console.warn('Removing widget event listener', this.dispatcherRef);
dis.unregister(this.dispatcherRef);
// Widget postMessage listeners
try {
if (this.widgetMessaging) {
this.widgetMessaging.stopListening();
this.widgetMessaging.removeEndpoint(this.props.id, this.props.url);
} else {
console.warn('WidgetMessaging not initialised. Not stopping.');
}
} catch (e) {
console.error('Failed to stop listening for widgetMessaging events', e.message);
}
// Jitsi listener
window.removeEventListener('message', this._onMessage);
}
/** /**
* Adds a scalar token to the widget URL, if required * Adds a scalar token to the widget URL, if required
* Component initialisation is only complete when this function has resolved * Component initialisation is only complete when this function has resolved
@ -216,23 +236,6 @@ export default class AppTile extends React.Component {
}); });
} }
componentWillUnmount() {
// Widget action listeners
dis.unregister(this.dispatcherRef);
// Widget postMessage listeners
try {
if (this.widgetMessaging) {
this.widgetMessaging.stopListening();
this.widgetMessaging.removeEndpoint(this.props.id, this.props.url);
}
} catch (e) {
console.error('Failed to stop listening for widgetMessaging events', e.message);
}
// Jitsi listener
window.removeEventListener('message', this._onMessage);
}
componentWillReceiveProps(nextProps) { componentWillReceiveProps(nextProps) {
if (nextProps.url !== this.props.url) { if (nextProps.url !== this.props.url) {
this._getNewState(nextProps); this._getNewState(nextProps);