2018-10-17 19:34:11 -04:00
|
|
|
import { Component, OnDestroy, OnInit } from "@angular/core";
|
2017-12-10 02:59:36 -05:00
|
|
|
import { ActivatedRoute } from "@angular/router";
|
|
|
|
import * as $ from "jquery";
|
2017-12-24 04:02:57 -05:00
|
|
|
import { FE_JitsiWidget } from "../../shared/models/integration";
|
|
|
|
import { WidgetApiService } from "../../shared/services/integrations/widget-api.service";
|
2018-10-17 19:34:11 -04:00
|
|
|
import { Subscription } from "rxjs/Subscription";
|
|
|
|
import { ScalarWidgetApi } from "../../shared/services/scalar/scalar-widget.api";
|
2018-07-30 23:55:57 -04:00
|
|
|
import { CapableWidget } from "../capable-widget";
|
2017-12-10 02:59:36 -05:00
|
|
|
|
2021-09-01 19:01:01 -04:00
|
|
|
declare let JitsiMeetExternalAPI: any;
|
2017-12-10 02:59:36 -05:00
|
|
|
|
|
|
|
@Component({
|
2021-09-01 19:29:24 -04:00
|
|
|
selector: "my-jitsi-widget-wrapper",
|
2017-12-10 02:59:36 -05:00
|
|
|
templateUrl: "jitsi.component.html",
|
|
|
|
styleUrls: ["jitsi.component.scss"],
|
|
|
|
})
|
2021-09-01 19:01:01 -04:00
|
|
|
export class JitsiWidgetWrapperComponent
|
|
|
|
extends CapableWidget
|
|
|
|
implements OnInit, OnDestroy {
|
2017-12-10 02:59:36 -05:00
|
|
|
public isJoined = false;
|
2020-03-28 10:44:59 -04:00
|
|
|
public toggleVideo = false;
|
2017-12-10 02:59:36 -05:00
|
|
|
|
|
|
|
private domain: string;
|
|
|
|
private conferenceId: string;
|
|
|
|
private displayName: string;
|
|
|
|
private avatarUrl: string;
|
|
|
|
private userId: string;
|
2020-03-28 10:44:59 -04:00
|
|
|
private isAudioOnly: boolean;
|
2017-12-10 02:59:36 -05:00
|
|
|
private jitsiApiObj: any;
|
2018-10-17 19:34:11 -04:00
|
|
|
private jitsiApiSubscription: Subscription;
|
2017-12-10 02:59:36 -05:00
|
|
|
|
2021-09-01 19:01:01 -04:00
|
|
|
constructor(
|
|
|
|
activatedRoute: ActivatedRoute,
|
|
|
|
private widgetApi: WidgetApiService
|
|
|
|
) {
|
2018-07-30 23:55:57 -04:00
|
|
|
super();
|
|
|
|
this.supportsAlwaysOnScreen = true;
|
|
|
|
|
2021-09-01 19:01:01 -04:00
|
|
|
const params: any = activatedRoute.snapshot.queryParams;
|
2017-12-10 02:59:36 -05:00
|
|
|
|
2018-12-22 21:30:25 -05:00
|
|
|
this.domain = params.domain;
|
2019-03-24 17:37:39 -04:00
|
|
|
this.conferenceId = params.conferenceId || params.confId;
|
2017-12-10 02:59:36 -05:00
|
|
|
this.displayName = params.displayName;
|
|
|
|
this.avatarUrl = params.avatarUrl;
|
2020-07-15 20:24:23 -04:00
|
|
|
this.userId = params.userId || params.email; // Element uses `email` when placing a conference call
|
2021-09-01 19:01:01 -04:00
|
|
|
this.isAudioOnly = params.isAudioOnly === "true";
|
2020-03-28 10:44:59 -04:00
|
|
|
this.toggleVideo = !this.isAudioOnly;
|
2019-03-15 22:31:07 -04:00
|
|
|
|
|
|
|
// Set the widget ID if we have it
|
|
|
|
ScalarWidgetApi.widgetId = params.widgetId;
|
2017-12-10 02:59:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
public ngOnInit() {
|
2018-07-30 23:55:57 -04:00
|
|
|
super.ngOnInit();
|
2021-09-01 19:01:01 -04:00
|
|
|
this.widgetApi.getWidget("jitsi").then((integration) => {
|
2017-12-24 04:02:57 -05:00
|
|
|
const widget = <FE_JitsiWidget>integration;
|
2017-12-23 15:15:54 -05:00
|
|
|
$.getScript(widget.options.scriptUrl);
|
2018-12-22 21:30:25 -05:00
|
|
|
|
|
|
|
if (!this.domain) {
|
2020-07-15 20:24:23 -04:00
|
|
|
// Always fall back to jitsi.riot.im to maintain compatibility with widgets created by Element.
|
2021-09-01 19:01:01 -04:00
|
|
|
this.domain = widget.options.useDomainAsDefault
|
|
|
|
? widget.options.jitsiDomain
|
|
|
|
: "jitsi.riot.im";
|
2018-12-22 21:30:25 -05:00
|
|
|
}
|
2017-12-10 02:59:36 -05:00
|
|
|
});
|
2021-09-01 19:01:01 -04:00
|
|
|
this.jitsiApiSubscription = ScalarWidgetApi.requestReceived.subscribe(
|
|
|
|
(request) => {
|
|
|
|
if (!this.isJoined) {
|
2019-03-15 22:25:11 -04:00
|
|
|
return;
|
2021-09-01 19:01:01 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (request.action) {
|
|
|
|
case "audioToggle":
|
|
|
|
this.jitsiApiObj.executeCommand("toggleAudio");
|
|
|
|
break;
|
|
|
|
case "audioMute":
|
|
|
|
this.jitsiApiObj.isAudioMuted().then((muted) => {
|
|
|
|
// Toggle audio if Jitsi is not currently muted
|
|
|
|
if (!muted) {
|
|
|
|
this.jitsiApiObj.executeCommand("toggleAudio");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
case "audioUnmute":
|
|
|
|
this.jitsiApiObj.isAudioMuted().then((muted) => {
|
|
|
|
// Toggle audio if Jitsi is currently muted
|
|
|
|
if (muted) {
|
|
|
|
this.jitsiApiObj.executeCommand("toggleAudio");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
// Unknown command sent
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ScalarWidgetApi.replyAcknowledge(request);
|
2018-10-17 19:34:11 -04:00
|
|
|
}
|
2021-09-01 19:01:01 -04:00
|
|
|
);
|
2017-12-10 02:59:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
public joinConference() {
|
|
|
|
$(".join-conference-wrapper").hide();
|
|
|
|
$("#jitsiContainer").show();
|
|
|
|
|
2019-03-15 22:31:07 -04:00
|
|
|
ScalarWidgetApi.sendSetAlwaysOnScreen(true);
|
|
|
|
|
2017-12-10 02:59:36 -05:00
|
|
|
this.jitsiApiObj = new JitsiMeetExternalAPI(this.domain, {
|
|
|
|
width: "100%",
|
|
|
|
height: "100%",
|
|
|
|
parentNode: document.querySelector("#jitsiContainer"),
|
|
|
|
roomName: this.conferenceId,
|
|
|
|
interfaceConfigOverwrite: {
|
|
|
|
SHOW_JITSI_WATERMARK: false,
|
|
|
|
SHOW_WATERMARK_FOR_GUESTS: false,
|
|
|
|
MAIN_TOOLBAR_BUTTONS: [],
|
|
|
|
VIDEO_LAYOUT_FIT: "height",
|
2021-09-01 19:01:01 -04:00
|
|
|
},
|
2017-12-10 02:59:36 -05:00
|
|
|
});
|
2021-09-01 19:01:01 -04:00
|
|
|
if (this.displayName)
|
|
|
|
this.jitsiApiObj.executeCommand("displayName", this.displayName);
|
|
|
|
if (this.avatarUrl)
|
|
|
|
this.jitsiApiObj.executeCommand("avatarUrl", this.avatarUrl.toString());
|
2017-12-10 02:59:36 -05:00
|
|
|
if (this.userId) this.jitsiApiObj.executeCommand("email", this.userId);
|
2021-09-01 19:01:01 -04:00
|
|
|
if (this.isAudioOnly === this.toggleVideo)
|
|
|
|
this.jitsiApiObj.executeCommand("toggleVideo");
|
2017-12-10 02:59:36 -05:00
|
|
|
|
|
|
|
this.jitsiApiObj.on("readyToClose", () => {
|
|
|
|
this.isJoined = false;
|
2019-03-15 22:31:07 -04:00
|
|
|
ScalarWidgetApi.sendSetAlwaysOnScreen(false);
|
2017-12-10 02:59:36 -05:00
|
|
|
$(".join-conference-wrapper").show();
|
|
|
|
$("#jitsiContainer").hide().html("");
|
|
|
|
});
|
|
|
|
|
|
|
|
this.isJoined = true;
|
|
|
|
}
|
|
|
|
|
2018-10-17 19:34:11 -04:00
|
|
|
public ngOnDestroy() {
|
|
|
|
if (this.jitsiApiSubscription) this.jitsiApiSubscription.unsubscribe();
|
|
|
|
}
|
|
|
|
|
2019-03-15 22:31:07 -04:00
|
|
|
protected onCapabilitiesSent(): void {
|
|
|
|
super.onCapabilitiesSent();
|
|
|
|
ScalarWidgetApi.sendSetAlwaysOnScreen(false);
|
|
|
|
}
|
2017-12-10 02:59:36 -05:00
|
|
|
}
|