2018-05-11 23:58:10 -04:00
|
|
|
import { Component, OnDestroy, OnInit } from "@angular/core";
|
2017-10-09 22:26:46 -04:00
|
|
|
import { ActivatedRoute } from "@angular/router";
|
|
|
|
import { DomSanitizer, SafeUrl } from "@angular/platform-browser";
|
2017-12-24 04:02:57 -05:00
|
|
|
import { WidgetApiService } from "../../shared/services/integrations/widget-api.service";
|
2018-05-11 23:58:10 -04: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-09 22:26:46 -04:00
|
|
|
|
|
|
|
@Component({
|
2017-10-09 22:49:26 -04:00
|
|
|
selector: "my-generic-widget-wrapper",
|
|
|
|
templateUrl: "generic.component.html",
|
|
|
|
styleUrls: ["generic.component.scss"],
|
2017-10-09 22:26:46 -04:00
|
|
|
})
|
2018-05-11 23:58:10 -04:00
|
|
|
export class GenericWidgetWrapperComponent implements OnInit, OnDestroy {
|
2017-10-09 22:26:46 -04:00
|
|
|
|
|
|
|
public isLoading = true;
|
|
|
|
public canEmbed = false;
|
|
|
|
public embedUrl: SafeUrl = null;
|
|
|
|
|
2018-05-11 23:58:10 -04:00
|
|
|
private widgetApiSubscription: Subscription;
|
|
|
|
|
2017-12-24 04:02:57 -05:00
|
|
|
constructor(widgetApi: WidgetApiService, activatedRoute: ActivatedRoute, sanitizer: DomSanitizer) {
|
2017-10-09 22:26:46 -04:00
|
|
|
let params: any = activatedRoute.snapshot.queryParams;
|
|
|
|
|
2018-05-11 23:58:10 -04:00
|
|
|
ScalarWidgetApi.setWidgetId("test");
|
|
|
|
|
2017-12-24 04:02:57 -05:00
|
|
|
widgetApi.isEmbeddable(params.url).then(result => {
|
2017-10-09 22:26:46 -04: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-11 23:58:10 -04: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-09 22:26:46 -04:00
|
|
|
}
|