General cleanup of handling for WidgetMessaging instances

When setting, delete the old one. Because delete checks if it exists first, we can safely call this.

The change in FromWidgetPostMessageApi is just something noticed while debugging.
This commit is contained in:
Travis Ralston 2019-04-01 19:50:05 -06:00
parent a4f76670c4
commit 51750cf153
3 changed files with 5 additions and 7 deletions

View file

@ -116,10 +116,8 @@ export default class FromWidgetPostMessageApi {
const origin = u.protocol + '//' + u.host; const origin = u.protocol + '//' + u.host;
if (this.widgetMessagingEndpoints && this.widgetMessagingEndpoints.length > 0) { if (this.widgetMessagingEndpoints && this.widgetMessagingEndpoints.length > 0) {
const length = this.widgetMessagingEndpoints.length; const length = this.widgetMessagingEndpoints.length;
this.widgetMessagingEndpoints = this.widgetMessagingEndpoints. this.widgetMessagingEndpoints = this.widgetMessagingEndpoints
filter(function(endpoint) { .filter((endpoint) => endpoint.widgetId !== widgetId || endpoint.endpointUrl !== origin);
return (endpoint.widgetId != widgetId || endpoint.endpointUrl != origin);
});
return (length > this.widgetMessagingEndpoints.length); return (length > this.widgetMessagingEndpoints.length);
} }
return false; return false;

View file

@ -339,9 +339,7 @@ export default class AppTile extends React.Component {
// Destroy the old widget messaging before starting it back up again. Some widgets // Destroy the old widget messaging before starting it back up again. Some widgets
// have startup routines that run when they are loaded, so we just need to reinitialize // have startup routines that run when they are loaded, so we just need to reinitialize
// the messaging for them. // the messaging for them.
if (ActiveWidgetStore.getWidgetMessaging(this.props.id)) {
ActiveWidgetStore.delWidgetMessaging(this.props.id); ActiveWidgetStore.delWidgetMessaging(this.props.id);
}
this._setupWidgetMessaging(); this._setupWidgetMessaging();
ActiveWidgetStore.setRoomId(this.props.id, this.props.room.roomId); ActiveWidgetStore.setRoomId(this.props.id, this.props.room.roomId);

View file

@ -116,6 +116,8 @@ class ActiveWidgetStore extends EventEmitter {
} }
setWidgetMessaging(widgetId, wm) { setWidgetMessaging(widgetId, wm) {
// Stop any existing widget messaging first
this.delWidgetMessaging(widgetId);
this._widgetMessagingByWidgetId[widgetId] = wm; this._widgetMessagingByWidgetId[widgetId] = wm;
this.emit('update'); this.emit('update');
} }