2017-11-10 12:31:46 -05:00
|
|
|
import { Component } from "@angular/core";
|
2017-12-09 18:34:59 -05:00
|
|
|
import { DialogRef, ModalComponent } from "ngx-modialog";
|
2017-11-10 12:31:46 -05:00
|
|
|
import { WidgetComponent } from "../widget.component";
|
|
|
|
import { ScalarService } from "../../../shared/scalar.service";
|
|
|
|
import { ConfigModalContext } from "../../../integration/integration.component";
|
|
|
|
import { ToasterService } from "angular2-toaster";
|
2017-12-14 00:44:20 -05:00
|
|
|
import { EditableWidget, WIDGET_TWITCH } from "../../../shared/models/widget";
|
2017-11-10 12:31:46 -05:00
|
|
|
|
|
|
|
@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(
|
2017-12-14 00:44:20 -05:00
|
|
|
window,
|
2017-11-10 12:31:46 -05:00
|
|
|
toaster,
|
|
|
|
scalarService,
|
|
|
|
dialog.context.roomId,
|
2017-12-11 17:39:15 -05:00
|
|
|
dialog.context.integration,
|
2017-11-10 12:31:46 -05:00
|
|
|
dialog.context.integrationId,
|
2017-12-14 00:44:20 -05:00
|
|
|
WIDGET_TWITCH,
|
2017-11-10 12:31:46 -05:00
|
|
|
"Twitch Widget",
|
|
|
|
"video", // wrapper
|
|
|
|
"twitch" // scalar wrapper
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-12-14 00:44:20 -05:00
|
|
|
protected onNewWidgetPrepared() {
|
|
|
|
this.newWidget.dimension.newData.channelName = "";
|
|
|
|
}
|
|
|
|
|
|
|
|
protected onWidgetsDiscovered() {
|
|
|
|
for (const widget of this.widgets) {
|
|
|
|
// Convert dimChannelName to channelName
|
|
|
|
if (!widget.data.channelName) {
|
|
|
|
widget.data.channelName = widget.data.dimChannelName;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-11-10 12:31:46 -05:00
|
|
|
|
2017-12-14 00:44:20 -05:00
|
|
|
public validateAndAddWidget() {
|
|
|
|
if (!this.newWidget.dimension.newData.channelName) {
|
|
|
|
this.toaster.pop("warning", "Please enter a Twitch Livestream channel name");
|
2017-11-10 12:31:46 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-12-14 00:44:20 -05:00
|
|
|
this.setTwitchUrl(this.newWidget);
|
|
|
|
this.addWidget();
|
2017-11-10 12:31:46 -05:00
|
|
|
}
|
|
|
|
|
2017-12-14 00:44:20 -05:00
|
|
|
public validateAndSaveWidget(widget: EditableWidget) {
|
|
|
|
if (!widget.dimension.newData.channelName) {
|
|
|
|
this.toaster.pop("warning", "Please enter a Twitch Livestream channel name");
|
2017-11-10 12:31:46 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-12-14 00:44:20 -05:00
|
|
|
this.setTwitchUrl(widget);
|
2017-11-10 12:31:46 -05:00
|
|
|
this.saveWidget(widget);
|
|
|
|
}
|
|
|
|
|
2017-12-14 00:44:20 -05:00
|
|
|
private setTwitchUrl(widget: EditableWidget) {
|
|
|
|
// TODO: This should use templating when mobile riot supports it
|
|
|
|
widget.dimension.newUrl = "https://player.twitch.tv/?channel=" + widget.dimension.newData.channelName;
|
2017-11-10 12:31:46 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|