Skip to content
This repository has been archived by the owner on Aug 10, 2023. It is now read-only.

Jitsi widget supports audio mute manipulation #226

Merged
merged 3 commits into from
Nov 7, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 41 additions & 2 deletions web/app/widget-wrappers/jitsi/jitsi.component.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { Component, OnInit } from "@angular/core";
import { Component, OnDestroy, OnInit } from "@angular/core";
import { ActivatedRoute } from "@angular/router";
import * as $ from "jquery";
import { FE_JitsiWidget } from "../../shared/models/integration";
import { WidgetApiService } from "../../shared/services/integrations/widget-api.service";
import { Subscription } from "rxjs/Subscription";
import { ScalarWidgetApi } from "../../shared/services/scalar/scalar-widget.api";
import { CapableWidget } from "../capable-widget";

declare var JitsiMeetExternalAPI: any;
Expand All @@ -12,7 +14,7 @@ declare var JitsiMeetExternalAPI: any;
templateUrl: "jitsi.component.html",
styleUrls: ["jitsi.component.scss"],
})
export class JitsiWidgetWrapperComponent extends CapableWidget implements OnInit {
export class JitsiWidgetWrapperComponent extends CapableWidget implements OnInit, OnDestroy {

public isJoined = false;

Expand All @@ -22,6 +24,7 @@ export class JitsiWidgetWrapperComponent extends CapableWidget implements OnInit
private avatarUrl: string;
private userId: string;
private jitsiApiObj: any;
private jitsiApiSubscription: Subscription;

constructor(activatedRoute: ActivatedRoute, private widgetApi: WidgetApiService) {
super();
Expand All @@ -42,6 +45,38 @@ export class JitsiWidgetWrapperComponent extends CapableWidget implements OnInit
const widget = <FE_JitsiWidget>integration;
$.getScript(widget.options.scriptUrl);
});
this.jitsiApiSubscription = ScalarWidgetApi.requestReceived.subscribe(request => {
if (!this.isJoined) {
return;
}

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);
});
}

public joinConference() {
Expand Down Expand Up @@ -73,4 +108,8 @@ export class JitsiWidgetWrapperComponent extends CapableWidget implements OnInit
this.isJoined = true;
}

public ngOnDestroy() {
if (this.jitsiApiSubscription) this.jitsiApiSubscription.unsubscribe();
}

}