matrix-dimension/web/app/configs/widget/twitch/twitch-config.component.ts
Travis Ralston 993dcdac21 Add Jitsi screensharing support
Self-hosted Jitsi Meet servers are possible for those running Dimension. The default server is Riot.IM's server.

Adds #87
2017-12-10 01:00:31 -07:00

71 lines
2.4 KiB
TypeScript

import { Component } from "@angular/core";
import { DialogRef, ModalComponent } from "ngx-modialog";
import { WidgetComponent } from "../widget.component";
import { ScalarService } from "../../../shared/scalar.service";
import { ConfigModalContext } from "../../../integration/integration.component";
import { ToasterService } from "angular2-toaster";
import { Widget, WIDGET_DIM_TWITCH, WIDGET_SCALAR_TWITCH } from "../../../shared/models/widget";
@Component({
selector: "my-twitchwidget-config",
templateUrl: "twitch-config.component.html",
styleUrls: ["twitch-config.component.scss", "./../../config.component.scss"],
})
export class TwitchWidgetConfigComponent extends WidgetComponent implements ModalComponent<ConfigModalContext> {
constructor(public dialog: DialogRef<ConfigModalContext>,
toaster: ToasterService,
scalarService: ScalarService,
window: Window) {
super(
toaster,
scalarService,
dialog.context.roomId,
window,
WIDGET_DIM_TWITCH,
WIDGET_SCALAR_TWITCH,
dialog.context.integrationId,
"Twitch Widget",
"video", // wrapper
"twitch" // scalar wrapper
);
}
public validateAndAddWidget() {
// Replace channel name with path to embedable Twitch Player
const url = "https://player.twitch.tv/?channel=" + this.newWidgetUrl;
// TODO Somehow Validate if it is a valid Username
if (!url) {
this.toaster.pop("warning", "Please enter a Twitch Livestream Channel Name");
return;
}
const originalUrl = this.newWidgetUrl;
this.newWidgetUrl = url;
this.addWidget({dimChannelName: originalUrl});
}
public validateAndSaveWidget(widget: Widget) {
const url = "https://player.twitch.tv/?channel=" + widget.data.dimChannelName;
// TODO Somehow Validate if it is a valid Username
if (!url) {
this.toaster.pop("warning", "Please enter a Twitch Livestream Channel Name");
return;
}
if (!widget.data) widget.data = {};
widget.newUrl = url;
widget.data.dimChannelName = widget.data.newDimChannelName;
this.saveWidget(widget);
}
public editWidget(widget: Widget) {
widget.data.newDimChannelName = widget.data.dimChannelName;
super.editWidget(widget);
}
}