2017-12-23 17:03:24 -05:00
|
|
|
import { WidgetComponent } from "../widget.component";
|
|
|
|
import { EditableWidget, WIDGET_TWITCH } from "../../../shared/models/widget";
|
|
|
|
import { Component } from "@angular/core";
|
2020-10-23 07:30:20 -04:00
|
|
|
import { TranslateService } from "@ngx-translate/core";
|
2017-12-23 17:03:24 -05:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
templateUrl: "twitch.widget.component.html",
|
|
|
|
styleUrls: ["twitch.widget.component.scss"],
|
|
|
|
})
|
|
|
|
export class TwitchWidgetConfigComponent extends WidgetComponent {
|
2020-10-23 07:30:20 -04:00
|
|
|
constructor(public translate: TranslateService) {
|
2020-12-28 23:05:45 -05:00
|
|
|
super(WIDGET_TWITCH, "Twitch Livestream", "video", translate , "twitch");
|
2017-12-23 17:03:24 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
protected OnNewWidgetPrepared(widget: EditableWidget) {
|
|
|
|
widget.dimension.newData.channelName = "";
|
|
|
|
}
|
|
|
|
|
|
|
|
protected OnWidgetsDiscovered(widgets: EditableWidget[]) {
|
|
|
|
for (const widget of widgets) {
|
|
|
|
if (!widget.data.channelName) {
|
|
|
|
// Convert legacy Dimension widgets to new format
|
|
|
|
widget.data.channelName = widget.data.dimChannelName;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected OnWidgetBeforeAdd(widget: EditableWidget) {
|
|
|
|
this.setTwitchUrl(widget);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected OnWidgetBeforeEdit(widget: EditableWidget) {
|
|
|
|
this.setTwitchUrl(widget);
|
|
|
|
}
|
|
|
|
|
|
|
|
private setTwitchUrl(widget: EditableWidget) {
|
|
|
|
if (!widget.dimension.newData.channelName || widget.dimension.newData.channelName.trim().length === 0) {
|
2017-12-23 17:28:42 -05:00
|
|
|
throw new Error("Please enter a channel name");
|
2017-12-23 17:03:24 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
widget.dimension.newUrl = "https://player.twitch.tv/?channel=$channelName";
|
|
|
|
widget.dimension.newTitle = widget.dimension.newData.channelName;
|
|
|
|
}
|
2020-10-23 07:30:20 -04:00
|
|
|
}
|