2017-12-23 16:16:22 -05:00
|
|
|
import { DISABLE_AUTOMATIC_WRAPPING, WidgetComponent } from "../widget.component";
|
|
|
|
import { EditableWidget, WIDGET_JITSI } from "../../../shared/models/widget";
|
|
|
|
import { Component } from "@angular/core";
|
2017-12-24 04:02:57 -05:00
|
|
|
import { FE_JitsiWidget } from "../../../shared/models/integration";
|
2017-12-23 16:16:22 -05:00
|
|
|
import { SessionStorage } from "../../../shared/SessionStorage";
|
|
|
|
import { NameService } from "../../../shared/services/name.service";
|
|
|
|
import * as url from "url";
|
2020-10-23 07:30:20 -04:00
|
|
|
import { TranslateService } from "@ngx-translate/core";
|
2017-12-23 16:16:22 -05:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
templateUrl: "jitsi.widget.component.html",
|
|
|
|
styleUrls: ["jitsi.widget.component.scss"],
|
|
|
|
})
|
|
|
|
export class JitsiWidgetConfigComponent extends WidgetComponent {
|
|
|
|
|
2017-12-24 04:02:57 -05:00
|
|
|
private jitsiWidget: FE_JitsiWidget = <FE_JitsiWidget>SessionStorage.editIntegration;
|
2017-12-23 16:16:22 -05:00
|
|
|
|
2020-10-23 07:30:20 -04:00
|
|
|
constructor(private nameService: NameService, public translate: TranslateService) {
|
|
|
|
super(WIDGET_JITSI, "Jitsi Video Conference", DISABLE_AUTOMATIC_WRAPPING, translate);
|
2017-12-23 16:16:22 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
protected OnWidgetsDiscovered(widgets: EditableWidget[]) {
|
|
|
|
for (const widget of widgets) {
|
|
|
|
const templatedUrl = this.templateUrl(widget.url, widget.data);
|
|
|
|
const parsedUrl = url.parse(templatedUrl, true);
|
|
|
|
const conferenceId = parsedUrl.query["conferenceId"];
|
|
|
|
const confId = parsedUrl.query["confId"];
|
|
|
|
const domain = parsedUrl.query["domain"];
|
2018-03-22 14:55:50 -04:00
|
|
|
let isAudioConf: string | boolean = <string>parsedUrl.query["isAudioConf"];
|
2019-03-24 17:37:39 -04:00
|
|
|
let isAudioOnly: string | boolean = <string>parsedUrl.query["isAudioOnly"];
|
2017-12-23 16:16:22 -05:00
|
|
|
|
|
|
|
// Convert isAudioConf to boolean
|
|
|
|
if (isAudioConf === "true") isAudioConf = true;
|
|
|
|
else if (isAudioConf === "false") isAudioConf = false;
|
2019-03-24 17:37:39 -04:00
|
|
|
else if (isAudioConf && isAudioConf[0] === '$') isAudioConf = widget.data["isAudioConf"];
|
|
|
|
else isAudioConf = null; // default
|
2017-12-23 16:16:22 -05:00
|
|
|
|
2019-03-24 17:37:39 -04:00
|
|
|
// Convert isAudioOnly to boolean
|
|
|
|
if (isAudioOnly === "true") isAudioOnly = true;
|
|
|
|
else if (isAudioOnly === "false") isAudioOnly = false;
|
|
|
|
else if (isAudioOnly && isAudioOnly[0] === '$') isAudioOnly = widget.data["isAudioOnly"];
|
|
|
|
else isAudioOnly = null; // default
|
|
|
|
|
|
|
|
if (confId) {
|
2017-12-23 16:16:22 -05:00
|
|
|
// It's a legacy Dimension widget
|
2019-03-24 17:37:39 -04:00
|
|
|
widget.data.conferenceId = confId;
|
|
|
|
} else widget.data.conferenceId = conferenceId;
|
2017-12-23 16:16:22 -05:00
|
|
|
|
|
|
|
if (domain) widget.data.domain = domain;
|
|
|
|
else widget.data.domain = "jitsi.riot.im";
|
|
|
|
|
2019-03-24 17:37:39 -04:00
|
|
|
if (isAudioConf !== null) {
|
|
|
|
// It's a legacy Dimension widget
|
|
|
|
widget.data.isAudioOnly = isAudioConf;
|
|
|
|
} else widget.data.isAudioOnly = !!isAudioOnly;
|
|
|
|
|
|
|
|
widget.data.conferenceUrl = "https://" + widget.data.domain + "/" + widget.data.conferenceId;
|
2017-12-23 16:16:22 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected OnNewWidgetPrepared(widget: EditableWidget): void {
|
|
|
|
const name = this.nameService.getHumanReadableName();
|
|
|
|
|
|
|
|
let rootUrl = "https://jitsi.riot.im/";
|
|
|
|
if (this.jitsiWidget.options && this.jitsiWidget.options.jitsiDomain) {
|
|
|
|
rootUrl = "https://" + this.jitsiWidget.options.jitsiDomain + "/";
|
|
|
|
}
|
|
|
|
|
|
|
|
widget.dimension.newData["conferenceUrl"] = rootUrl + name;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected OnWidgetBeforeAdd(widget: EditableWidget) {
|
|
|
|
this.setJitsiUrl(widget);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected OnWidgetBeforeEdit(widget: EditableWidget) {
|
|
|
|
this.setJitsiUrl(widget);
|
|
|
|
}
|
|
|
|
|
|
|
|
private setJitsiUrl(widget: EditableWidget) {
|
|
|
|
const jitsiUrl = url.parse(widget.dimension.newData.conferenceUrl);
|
|
|
|
widget.dimension.newData.domain = jitsiUrl.host;
|
2019-03-24 17:37:39 -04:00
|
|
|
widget.dimension.newData.conferenceId = jitsiUrl.path.substring(1);
|
2017-12-23 16:16:22 -05:00
|
|
|
|
|
|
|
let widgetQueryString = url.format({
|
|
|
|
query: {
|
2019-03-24 17:37:39 -04:00
|
|
|
"conferenceId": "$conferenceId",
|
|
|
|
"domain": "$domain",
|
|
|
|
"isAudioOnly": "$isAudioOnly",
|
2017-12-23 16:16:22 -05:00
|
|
|
"displayName": "$matrix_display_name",
|
|
|
|
"avatarUrl": "$matrix_avatar_url",
|
|
|
|
"userId": "$matrix_user_id",
|
|
|
|
},
|
|
|
|
});
|
|
|
|
widgetQueryString = this.decodeParams(widgetQueryString, Object.keys(widget.dimension.newData).map(k => "$" + k));
|
|
|
|
|
|
|
|
widget.dimension.newUrl = window.location.origin + "/widgets/jitsi" + widgetQueryString;
|
|
|
|
}
|
2020-10-23 07:30:20 -04:00
|
|
|
}
|