2018-05-12 03:58:10 +00:00
|
|
|
import { Component, OnDestroy, OnInit } from "@angular/core";
|
2017-10-10 02:26:46 +00:00
|
|
|
import { ActivatedRoute } from "@angular/router";
|
|
|
|
import { DomSanitizer, SafeUrl } from "@angular/platform-browser";
|
2017-12-24 09:02:57 +00:00
|
|
|
import { WidgetApiService } from "../../shared/services/integrations/widget-api.service";
|
2018-05-12 03:58:10 +00:00
|
|
|
import { ScalarWidgetApi } from "../../shared/services/scalar/scalar-widget.api";
|
|
|
|
import { Subscription } from "rxjs/Subscription";
|
|
|
|
import { ScalarToWidgetRequest } from "../../shared/models/scalar-widget-actions";
|
2017-10-10 02:26:46 +00:00
|
|
|
|
|
|
|
@Component({
|
2017-10-10 02:49:26 +00:00
|
|
|
selector: "my-generic-widget-wrapper",
|
|
|
|
templateUrl: "generic.component.html",
|
|
|
|
styleUrls: ["generic.component.scss"],
|
2017-10-10 02:26:46 +00:00
|
|
|
})
|
2018-05-12 03:58:10 +00:00
|
|
|
export class GenericWidgetWrapperComponent implements OnInit, OnDestroy {
|
2017-10-10 02:26:46 +00:00
|
|
|
|
|
|
|
public isLoading = true;
|
|
|
|
public canEmbed = false;
|
|
|
|
public embedUrl: SafeUrl = null;
|
|
|
|
|
2018-05-12 03:58:10 +00:00
|
|
|
private widgetApiSubscription: Subscription;
|
|
|
|
|
2017-12-24 09:02:57 +00:00
|
|
|
constructor(widgetApi: WidgetApiService, activatedRoute: ActivatedRoute, sanitizer: DomSanitizer) {
|
2017-10-10 02:26:46 +00:00
|
|
|
let params: any = activatedRoute.snapshot.queryParams;
|
|
|
|
|
2018-05-12 03:58:10 +00:00
|
|
|
ScalarWidgetApi.setWidgetId("test");
|
|
|
|
|
2017-12-24 09:02:57 +00:00
|
|
|
widgetApi.isEmbeddable(params.url).then(result => {
|
2017-10-10 02:26:46 +00:00
|
|
|
this.canEmbed = result.canEmbed;
|
|
|
|
this.isLoading = false;
|
|
|
|
this.embedUrl = sanitizer.bypassSecurityTrustResourceUrl(params.url);
|
|
|
|
}).catch(err => {
|
|
|
|
console.error(err);
|
|
|
|
this.canEmbed = false;
|
|
|
|
this.isLoading = false;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-05-12 03:58:10 +00:00
|
|
|
public ngOnInit() {
|
|
|
|
this.widgetApiSubscription = ScalarWidgetApi.requestReceived.subscribe(e => this.onWidgetRequest(e));
|
|
|
|
}
|
|
|
|
|
|
|
|
public ngOnDestroy() {
|
|
|
|
if (this.widgetApiSubscription) this.widgetApiSubscription.unsubscribe();
|
|
|
|
}
|
|
|
|
|
|
|
|
private onWidgetRequest(request: ScalarToWidgetRequest) {
|
|
|
|
if (request.action === "capabilities") {
|
|
|
|
// Taking of the screenshot is handled elsewhere
|
|
|
|
// TODO: Re-enable screenshots via a configuration flag when Riot has better support for them (and move it to an abstract class)
|
|
|
|
ScalarWidgetApi.replyCapabilities(request, [/*"m.capability.screenshot"*/]);
|
|
|
|
}
|
|
|
|
}
|
2017-10-10 02:26:46 +00:00
|
|
|
}
|