Add stop functions

This commit is contained in:
Travis Ralston 2020-09-26 18:40:26 -06:00
parent cb06b8daf6
commit 96fa34eecf
2 changed files with 26 additions and 0 deletions

View File

@ -114,4 +114,24 @@ export class WidgetMessagingStore extends AsyncStoreWithClient<unknown> {
const driver = new SdkWidgetDriver(widget, WidgetKind.Account, userId);
return this.generateMessaging(userId, widget, iframe, driver);
}
/**
* Stops the messaging instance for the widget, unregistering it.
* @param {Room} room The room where the widget resides.
* @param {Widget} widget The widget
*/
public stopMessagingForRoomWidget(room: Room, widget: Widget) {
const api = this.widgetMap.getOrCreate(room.roomId, new EnhancedMap()).remove(widget.id);
if (api) api.messaging.stop();
}
/**
* Stops the messaging instance for the widget, unregistering it.
* @param {Widget} widget The widget
*/
public stopMessagingForAccountWidget(widget: Widget) {
if (!this.matrixClient) return;
const api = this.widgetMap.getOrCreate(this.matrixClient.getUserId(), new EnhancedMap()).remove(widget.id);
if (api) api.messaging.stop();
}
}

View File

@ -60,4 +60,10 @@ export class EnhancedMap<K, V> extends Map<K, V> {
this.set(key, def);
return def;
}
public remove(key: K): V {
const v = this.get(key);
this.delete(key);
return v;
}
}