2018-05-12 18:46:08 -04:00
|
|
|
import { OnDestroy, OnInit } from "@angular/core";
|
|
|
|
import { Subscription } from "rxjs/Subscription";
|
|
|
|
import { ScalarWidgetApi } from "../shared/services/scalar/scalar-widget.api";
|
|
|
|
|
|
|
|
export abstract class CapableWidget implements OnInit, OnDestroy {
|
|
|
|
|
|
|
|
private widgetApiSubscription: Subscription;
|
|
|
|
|
|
|
|
// The capabilities we support
|
|
|
|
protected supportsScreenshots = false;
|
2018-05-14 00:32:13 -04:00
|
|
|
protected supportsStickers = false;
|
2018-05-12 18:46:08 -04:00
|
|
|
|
|
|
|
public ngOnInit() {
|
|
|
|
this.widgetApiSubscription = ScalarWidgetApi.requestReceived.subscribe(request => {
|
|
|
|
if (request.action === "capabilities") {
|
|
|
|
const capabilities = [];
|
|
|
|
|
|
|
|
if (this.supportsScreenshots) capabilities.push("m.capability.screenshot");
|
2018-05-14 00:32:13 -04:00
|
|
|
if (this.supportsStickers) capabilities.push("m.sticker");
|
2018-05-12 18:46:08 -04:00
|
|
|
|
|
|
|
ScalarWidgetApi.replyCapabilities(request, capabilities);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public ngOnDestroy() {
|
|
|
|
if (this.widgetApiSubscription) this.widgetApiSubscription.unsubscribe();
|
|
|
|
}
|
|
|
|
}
|