2020-08-13 18:21:48 +02:00
|
|
|
import {DivImportance, layoutManager} from "./LayoutManager";
|
2020-08-21 22:53:17 +02:00
|
|
|
import {HtmlUtils} from "./HtmlUtils";
|
2020-12-04 11:30:35 +01:00
|
|
|
import {discussionManager, SendMessageCallback} from "./DiscussionManager";
|
2021-05-12 09:13:25 +02:00
|
|
|
import type {UserInputManager} from "../Phaser/UserInput/UserInputManager";
|
2021-03-30 22:38:44 +02:00
|
|
|
import {localUserStore} from "../Connexion/LocalUserStore";
|
2021-05-12 09:13:25 +02:00
|
|
|
import type {UserSimplePeerInterface} from "./SimplePeer";
|
2021-05-05 01:49:04 +02:00
|
|
|
import {SoundMeter} from "../Phaser/Components/SoundMeter";
|
2021-05-17 13:50:31 +02:00
|
|
|
import {DISABLE_NOTIFICATIONS} from "../Enum/EnvironmentVariable";
|
2021-05-18 16:38:56 +02:00
|
|
|
import {
|
2021-05-19 11:17:43 +02:00
|
|
|
gameOverlayVisibilityStore, localStreamStore,
|
2021-05-18 16:38:56 +02:00
|
|
|
} from "../Stores/MediaStore";
|
2021-05-21 18:26:50 +02:00
|
|
|
import {
|
|
|
|
screenSharingLocalStreamStore
|
|
|
|
} from "../Stores/ScreenSharingStore";
|
2021-06-01 09:08:02 +02:00
|
|
|
import {helpCameraSettingsVisibleStore} from "../Stores/HelpCameraSettingsStore";
|
2021-05-05 01:49:04 +02:00
|
|
|
|
2020-08-31 15:21:05 +02:00
|
|
|
export type UpdatedLocalStreamCallback = (media: MediaStream|null) => void;
|
|
|
|
export type StartScreenSharingCallback = (media: MediaStream) => void;
|
|
|
|
export type StopScreenSharingCallback = (media: MediaStream) => void;
|
2020-10-13 19:56:42 +02:00
|
|
|
export type ReportCallback = (message: string) => void;
|
2021-01-29 21:09:10 +01:00
|
|
|
export type ShowReportCallBack = (userId: string, userName: string|undefined) => void;
|
2021-05-05 01:49:04 +02:00
|
|
|
export type HelpCameraSettingsCallBack = () => void;
|
2020-06-23 14:56:57 +02:00
|
|
|
|
2021-06-03 20:15:50 +02:00
|
|
|
import {cowebsiteCloseButtonId} from "./CoWebsiteManager";
|
|
|
|
|
2020-06-23 12:24:36 +02:00
|
|
|
export class MediaManager {
|
2020-06-10 12:15:25 +02:00
|
|
|
private remoteVideo: Map<string, HTMLVideoElement> = new Map<string, HTMLVideoElement>();
|
2021-05-10 20:49:17 +02:00
|
|
|
//FIX ME SOUNDMETER: check stalability of sound meter calculation
|
|
|
|
//mySoundMeterElement: HTMLDivElement;
|
2020-08-21 22:53:17 +02:00
|
|
|
startScreenSharingCallBacks : Set<StartScreenSharingCallback> = new Set<StartScreenSharingCallback>();
|
|
|
|
stopScreenSharingCallBacks : Set<StopScreenSharingCallback> = new Set<StopScreenSharingCallback>();
|
2021-01-29 21:09:10 +01:00
|
|
|
showReportModalCallBacks : Set<ShowReportCallBack> = new Set<ShowReportCallBack>();
|
2021-05-11 10:56:50 +02:00
|
|
|
|
2020-10-26 22:39:52 +01:00
|
|
|
private focused : boolean = true;
|
|
|
|
|
2020-11-17 18:03:44 +01:00
|
|
|
private triggerCloseJistiFrame : Map<String, Function> = new Map<String, Function>();
|
|
|
|
|
2021-05-05 01:49:04 +02:00
|
|
|
private userInputManager?: UserInputManager;
|
|
|
|
|
2021-05-10 20:49:17 +02:00
|
|
|
//FIX ME SOUNDMETER: check stalability of sound meter calculation
|
|
|
|
/*private mySoundMeter?: SoundMeter|null;
|
2021-05-05 01:49:04 +02:00
|
|
|
private soundMeters: Map<string, SoundMeter> = new Map<string, SoundMeter>();
|
2021-05-10 20:49:17 +02:00
|
|
|
private soundMeterElements: Map<string, HTMLDivElement> = new Map<string, HTMLDivElement>();*/
|
2021-05-05 01:49:04 +02:00
|
|
|
|
2020-08-18 00:12:38 +02:00
|
|
|
constructor() {
|
2020-04-19 19:32:38 +02:00
|
|
|
|
2020-10-24 14:40:51 +02:00
|
|
|
this.pingCameraStatus();
|
2020-10-26 22:39:52 +01:00
|
|
|
|
2021-05-19 11:17:43 +02:00
|
|
|
//FIX ME SOUNDMETER: check stability of sound meter calculation
|
2021-05-10 20:49:17 +02:00
|
|
|
/*this.mySoundMeterElement = (HtmlUtils.getElementByIdOrFail('mySoundMeter'));
|
2021-05-05 01:49:04 +02:00
|
|
|
this.mySoundMeterElement.childNodes.forEach((value: ChildNode, index) => {
|
|
|
|
this.mySoundMeterElement.children.item(index)?.classList.remove('active');
|
2021-05-10 20:49:17 +02:00
|
|
|
});*/
|
2021-05-07 01:37:05 +02:00
|
|
|
|
|
|
|
//Check of ask notification navigator permission
|
|
|
|
this.getNotification();
|
2020-04-19 19:32:38 +02:00
|
|
|
|
2021-05-19 11:17:43 +02:00
|
|
|
localStreamStore.subscribe((result) => {
|
|
|
|
if (result.type === 'error') {
|
|
|
|
console.error(result.error);
|
2021-05-31 17:53:27 +02:00
|
|
|
layoutManager.addInformation('warning', 'Camera access denied. Click here and check your browser permissions.', () => {
|
2021-06-01 09:08:02 +02:00
|
|
|
helpCameraSettingsVisibleStore.set(true);
|
2021-05-19 11:17:43 +02:00
|
|
|
}, this.userInputManager);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
});
|
2021-05-20 18:05:03 +02:00
|
|
|
|
2021-05-21 18:02:57 +02:00
|
|
|
screenSharingLocalStreamStore.subscribe((result) => {
|
|
|
|
if (result.type === 'error') {
|
|
|
|
console.error(result.error);
|
2021-05-31 17:53:27 +02:00
|
|
|
layoutManager.addInformation('warning', 'Screen sharing denied. Click here and check your browser permissions.', () => {
|
2021-06-01 09:08:02 +02:00
|
|
|
helpCameraSettingsVisibleStore.set(true);
|
2021-05-21 18:02:57 +02:00
|
|
|
}, this.userInputManager);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (result.stream !== null) {
|
|
|
|
this.addScreenSharingActiveVideo('me', DivImportance.Normal);
|
|
|
|
HtmlUtils.getElementByIdOrFail<HTMLVideoElement>('screen-sharing-me').srcObject = result.stream;
|
|
|
|
} else {
|
|
|
|
this.removeActiveScreenSharingVideo('me');
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
2021-05-21 18:26:50 +02:00
|
|
|
|
2021-05-28 09:31:04 +02:00
|
|
|
/*screenSharingAvailableStore.subscribe((available) => {
|
2021-05-21 18:26:50 +02:00
|
|
|
if (available) {
|
|
|
|
document.querySelector('.btn-monitor')?.classList.remove('hide');
|
|
|
|
} else {
|
|
|
|
document.querySelector('.btn-monitor')?.classList.add('hide');
|
|
|
|
}
|
2021-05-28 09:31:04 +02:00
|
|
|
});*/
|
2021-05-11 14:52:51 +02:00
|
|
|
}
|
|
|
|
|
2021-05-19 11:17:43 +02:00
|
|
|
public updateScene(){
|
|
|
|
//FIX ME SOUNDMETER: check stability of sound meter calculation
|
|
|
|
//this.updateSoudMeter();
|
2020-04-26 20:55:20 +02:00
|
|
|
}
|
2020-04-19 19:32:38 +02:00
|
|
|
|
2021-05-11 14:52:51 +02:00
|
|
|
public showGameOverlay(): void {
|
2020-10-25 19:38:00 +01:00
|
|
|
const gameOverlay = HtmlUtils.getElementByIdOrFail('game-overlay');
|
2020-08-13 18:21:48 +02:00
|
|
|
gameOverlay.classList.add('active');
|
2020-11-17 18:03:44 +01:00
|
|
|
|
2021-06-03 20:05:39 +02:00
|
|
|
const buttonCloseFrame = HtmlUtils.getElementByIdOrFail(cowebsiteCloseButtonId);
|
2020-11-17 18:03:44 +01:00
|
|
|
const functionTrigger = () => {
|
|
|
|
this.triggerCloseJitsiFrameButton();
|
|
|
|
}
|
2021-06-03 20:05:39 +02:00
|
|
|
buttonCloseFrame.removeEventListener('click', () => {
|
|
|
|
buttonCloseFrame.blur();
|
|
|
|
functionTrigger();
|
|
|
|
});
|
2021-05-18 16:38:56 +02:00
|
|
|
|
|
|
|
gameOverlayVisibilityStore.showGameOverlay();
|
2020-04-19 19:32:38 +02:00
|
|
|
}
|
|
|
|
|
2021-05-11 14:52:51 +02:00
|
|
|
public hideGameOverlay(): void {
|
2020-10-25 19:38:00 +01:00
|
|
|
const gameOverlay = HtmlUtils.getElementByIdOrFail('game-overlay');
|
2020-09-01 14:43:21 +02:00
|
|
|
gameOverlay.classList.remove('active');
|
2020-11-17 18:03:44 +01:00
|
|
|
|
2021-06-03 20:05:39 +02:00
|
|
|
const buttonCloseFrame = HtmlUtils.getElementByIdOrFail(cowebsiteCloseButtonId);
|
2020-11-17 18:03:44 +01:00
|
|
|
const functionTrigger = () => {
|
|
|
|
this.triggerCloseJitsiFrameButton();
|
|
|
|
}
|
2021-06-03 20:05:39 +02:00
|
|
|
buttonCloseFrame.addEventListener('click', () => {
|
|
|
|
buttonCloseFrame.blur();
|
|
|
|
functionTrigger();
|
|
|
|
});
|
2021-05-18 16:38:56 +02:00
|
|
|
|
|
|
|
gameOverlayVisibilityStore.hideGameOverlay();
|
2020-09-01 14:43:21 +02:00
|
|
|
}
|
|
|
|
|
2021-02-02 18:19:51 +01:00
|
|
|
addActiveVideo(user: UserSimplePeerInterface, userName: string = ""){
|
|
|
|
const userId = ''+user.userId
|
2020-08-13 18:21:48 +02:00
|
|
|
|
2020-05-14 20:39:30 +02:00
|
|
|
userName = userName.toUpperCase();
|
2020-06-09 23:13:26 +02:00
|
|
|
const color = this.getColorByString(userName);
|
2020-08-13 18:21:48 +02:00
|
|
|
|
|
|
|
const html = `
|
|
|
|
<div id="div-${userId}" class="video-container">
|
|
|
|
<div class="connecting-spinner"></div>
|
|
|
|
<div class="rtc-error" style="display: none"></div>
|
2020-08-16 23:19:04 +02:00
|
|
|
<i id="name-${userId}" style="background-color: ${color};">${userName}</i>
|
2021-02-02 18:19:51 +01:00
|
|
|
<img id="microphone-${userId}" title="mute" src="resources/logos/microphone-close.svg">
|
|
|
|
<button id="report-${userId}" class="report">
|
|
|
|
<img title="report this user" src="resources/logos/report.svg">
|
|
|
|
<span>Report/Block</span>
|
|
|
|
</button>
|
2021-06-04 14:16:21 +02:00
|
|
|
<video id="${userId}" autoplay playsinline></video>
|
2021-02-02 18:19:51 +01:00
|
|
|
<img src="resources/logos/blockSign.svg" id="blocking-${userId}" class="block-logo">
|
2021-05-05 01:49:04 +02:00
|
|
|
<div id="soundMeter-${userId}" class="sound-progress">
|
|
|
|
<span></span>
|
|
|
|
<span></span>
|
|
|
|
<span></span>
|
|
|
|
<span></span>
|
|
|
|
<span></span>
|
|
|
|
</div>
|
2020-08-13 18:21:48 +02:00
|
|
|
</div>
|
|
|
|
`;
|
|
|
|
|
|
|
|
layoutManager.add(DivImportance.Normal, userId, html);
|
2021-05-11 10:56:50 +02:00
|
|
|
|
2020-10-25 19:38:00 +01:00
|
|
|
this.remoteVideo.set(userId, HtmlUtils.getElementByIdOrFail<HTMLVideoElement>(userId));
|
2020-10-25 21:59:14 +01:00
|
|
|
|
|
|
|
//permit to create participant in discussion part
|
2021-01-29 21:09:10 +01:00
|
|
|
const showReportUser = () => {
|
|
|
|
for(const callBack of this.showReportModalCallBacks){
|
|
|
|
callBack(userId, userName);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
this.addNewParticipant(userId, userName, undefined, showReportUser);
|
|
|
|
|
2021-02-02 18:19:51 +01:00
|
|
|
const reportBanUserActionEl: HTMLImageElement = HtmlUtils.getElementByIdOrFail<HTMLImageElement>(`report-${userId}`);
|
|
|
|
reportBanUserActionEl.addEventListener('click', (e) => {
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
showReportUser();
|
|
|
|
});
|
2020-04-26 19:12:01 +02:00
|
|
|
}
|
2021-05-11 10:56:50 +02:00
|
|
|
|
2020-09-18 13:57:38 +02:00
|
|
|
addScreenSharingActiveVideo(userId: string, divImportance: DivImportance = DivImportance.Important){
|
2020-08-20 00:05:00 +02:00
|
|
|
|
2021-02-02 18:19:51 +01:00
|
|
|
userId = this.getScreenSharingId(userId);
|
2020-08-20 00:05:00 +02:00
|
|
|
const html = `
|
|
|
|
<div id="div-${userId}" class="video-container">
|
2021-06-04 14:16:21 +02:00
|
|
|
<video id="${userId}" autoplay playsinline></video>
|
2020-06-08 09:20:36 +02:00
|
|
|
</div>
|
2020-08-20 00:05:00 +02:00
|
|
|
`;
|
|
|
|
|
2020-08-21 22:53:17 +02:00
|
|
|
layoutManager.add(divImportance, userId, html);
|
2020-08-20 00:05:00 +02:00
|
|
|
|
2020-10-25 19:38:00 +01:00
|
|
|
this.remoteVideo.set(userId, HtmlUtils.getElementByIdOrFail<HTMLVideoElement>(userId));
|
2020-06-08 09:20:36 +02:00
|
|
|
}
|
2021-02-02 18:19:51 +01:00
|
|
|
|
|
|
|
private getScreenSharingId(userId: string): string {
|
|
|
|
return `screen-sharing-${userId}`;
|
|
|
|
}
|
|
|
|
|
2020-09-18 13:57:38 +02:00
|
|
|
disabledMicrophoneByUserId(userId: number){
|
2020-06-09 23:13:26 +02:00
|
|
|
const element = document.getElementById(`microphone-${userId}`);
|
2020-05-14 20:39:30 +02:00
|
|
|
if(!element){
|
|
|
|
return;
|
|
|
|
}
|
2020-11-27 14:51:50 +01:00
|
|
|
element.classList.add('active') //todo: why does a method 'disable' add a class 'active'?
|
2020-05-14 20:39:30 +02:00
|
|
|
}
|
2021-05-11 10:56:50 +02:00
|
|
|
|
2020-09-18 13:57:38 +02:00
|
|
|
enabledMicrophoneByUserId(userId: number){
|
2020-06-09 23:13:26 +02:00
|
|
|
const element = document.getElementById(`microphone-${userId}`);
|
2020-05-14 20:39:30 +02:00
|
|
|
if(!element){
|
|
|
|
return;
|
|
|
|
}
|
2020-11-27 14:51:50 +01:00
|
|
|
element.classList.remove('active') //todo: why does a method 'enable' remove a class 'active'?
|
2020-05-14 20:39:30 +02:00
|
|
|
}
|
2021-05-11 10:56:50 +02:00
|
|
|
|
2020-09-18 13:57:38 +02:00
|
|
|
disabledVideoByUserId(userId: number) {
|
2020-05-14 20:39:30 +02:00
|
|
|
let element = document.getElementById(`${userId}`);
|
2020-05-14 20:54:34 +02:00
|
|
|
if (element) {
|
|
|
|
element.style.opacity = "0";
|
|
|
|
}
|
2020-08-16 23:19:04 +02:00
|
|
|
element = document.getElementById(`name-${userId}`);
|
|
|
|
if (element) {
|
|
|
|
element.style.display = "block";
|
2020-05-14 20:39:30 +02:00
|
|
|
}
|
|
|
|
}
|
2021-05-11 10:56:50 +02:00
|
|
|
|
2020-09-18 13:57:38 +02:00
|
|
|
enabledVideoByUserId(userId: number){
|
2020-05-14 20:39:30 +02:00
|
|
|
let element = document.getElementById(`${userId}`);
|
2020-05-14 20:54:34 +02:00
|
|
|
if(element){
|
|
|
|
element.style.opacity = "1";
|
|
|
|
}
|
2020-08-16 23:19:04 +02:00
|
|
|
element = document.getElementById(`name-${userId}`);
|
|
|
|
if(element){
|
|
|
|
element.style.display = "none";
|
2020-05-14 20:39:30 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-02 18:19:51 +01:00
|
|
|
toggleBlockLogo(userId: number, show: boolean): void {
|
|
|
|
const blockLogoElement = HtmlUtils.getElementByIdOrFail<HTMLImageElement>('blocking-'+userId);
|
|
|
|
show ? blockLogoElement.classList.add('active') : blockLogoElement.classList.remove('active');
|
|
|
|
}
|
2020-11-27 14:51:50 +01:00
|
|
|
addStreamRemoteVideo(userId: string, stream : MediaStream): void {
|
2020-06-10 12:15:25 +02:00
|
|
|
const remoteVideo = this.remoteVideo.get(userId);
|
|
|
|
if (remoteVideo === undefined) {
|
2020-10-20 18:02:44 +02:00
|
|
|
throw `Unable to find video for ${userId}`;
|
2020-06-10 12:15:25 +02:00
|
|
|
}
|
|
|
|
remoteVideo.srcObject = stream;
|
2021-05-05 01:49:04 +02:00
|
|
|
|
2021-05-10 20:49:17 +02:00
|
|
|
//FIX ME SOUNDMETER: check stalability of sound meter calculation
|
2021-05-05 01:49:04 +02:00
|
|
|
//sound metter
|
2021-05-10 20:49:17 +02:00
|
|
|
/*const soundMeter = new SoundMeter();
|
2021-05-05 01:49:04 +02:00
|
|
|
soundMeter.connectToSource(stream, new AudioContext());
|
|
|
|
this.soundMeters.set(userId, soundMeter);
|
2021-05-10 20:49:17 +02:00
|
|
|
this.soundMeterElements.set(userId, HtmlUtils.getElementByIdOrFail<HTMLImageElement>('soundMeter-'+userId));*/
|
2020-05-02 20:46:02 +02:00
|
|
|
}
|
2020-09-18 13:57:38 +02:00
|
|
|
addStreamRemoteScreenSharing(userId: string, stream : MediaStream){
|
2020-08-21 22:53:17 +02:00
|
|
|
// In the case of screen sharing (going both ways), we may need to create the HTML element if it does not exist yet
|
2021-02-02 18:19:51 +01:00
|
|
|
const remoteVideo = this.remoteVideo.get(this.getScreenSharingId(userId));
|
2020-08-21 22:53:17 +02:00
|
|
|
if (remoteVideo === undefined) {
|
|
|
|
this.addScreenSharingActiveVideo(userId);
|
|
|
|
}
|
|
|
|
|
2021-02-02 18:19:51 +01:00
|
|
|
this.addStreamRemoteVideo(this.getScreenSharingId(userId), stream);
|
2020-06-11 23:18:06 +02:00
|
|
|
}
|
2021-05-11 10:56:50 +02:00
|
|
|
|
2020-09-18 13:57:38 +02:00
|
|
|
removeActiveVideo(userId: string){
|
2020-08-13 18:21:48 +02:00
|
|
|
layoutManager.remove(userId);
|
2020-06-10 12:15:25 +02:00
|
|
|
this.remoteVideo.delete(userId);
|
2020-10-25 21:59:14 +01:00
|
|
|
|
2021-05-10 20:49:17 +02:00
|
|
|
//FIX ME SOUNDMETER: check stalability of sound meter calculation
|
|
|
|
/*this.soundMeters.get(userId)?.stop();
|
2021-05-05 01:49:04 +02:00
|
|
|
this.soundMeters.delete(userId);
|
2021-05-10 20:49:17 +02:00
|
|
|
this.soundMeterElements.delete(userId);*/
|
2021-05-05 01:49:04 +02:00
|
|
|
|
2020-10-25 21:59:14 +01:00
|
|
|
//permit to remove user in discussion part
|
|
|
|
this.removeParticipant(userId);
|
2020-04-25 20:29:03 +02:00
|
|
|
}
|
2020-09-18 13:57:38 +02:00
|
|
|
removeActiveScreenSharingVideo(userId: string) {
|
2021-02-02 18:19:51 +01:00
|
|
|
this.removeActiveVideo(this.getScreenSharingId(userId))
|
2020-06-11 23:18:06 +02:00
|
|
|
}
|
2021-05-11 10:56:50 +02:00
|
|
|
|
2020-09-18 13:57:38 +02:00
|
|
|
isConnecting(userId: string): void {
|
2020-06-09 23:13:26 +02:00
|
|
|
const connectingSpinnerDiv = this.getSpinner(userId);
|
2020-06-06 22:49:55 +02:00
|
|
|
if (connectingSpinnerDiv === null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
connectingSpinnerDiv.style.display = 'block';
|
|
|
|
}
|
|
|
|
|
2020-09-18 13:57:38 +02:00
|
|
|
isConnected(userId: string): void {
|
2020-06-09 23:13:26 +02:00
|
|
|
const connectingSpinnerDiv = this.getSpinner(userId);
|
2020-06-06 22:49:55 +02:00
|
|
|
if (connectingSpinnerDiv === null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
connectingSpinnerDiv.style.display = 'none';
|
|
|
|
}
|
|
|
|
|
2020-09-18 13:57:38 +02:00
|
|
|
isError(userId: string): void {
|
2020-11-27 16:24:07 +01:00
|
|
|
console.info("isError", `div-${userId}`);
|
2020-06-09 23:13:26 +02:00
|
|
|
const element = document.getElementById(`div-${userId}`);
|
2020-06-06 22:49:55 +02:00
|
|
|
if(!element){
|
|
|
|
return;
|
|
|
|
}
|
2020-06-09 23:13:26 +02:00
|
|
|
const errorDiv = element.getElementsByClassName('rtc-error').item(0) as HTMLDivElement|null;
|
2020-06-06 22:49:55 +02:00
|
|
|
if (errorDiv === null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
errorDiv.style.display = 'block';
|
|
|
|
}
|
2020-09-18 13:57:38 +02:00
|
|
|
isErrorScreenSharing(userId: string): void {
|
2021-02-02 18:19:51 +01:00
|
|
|
this.isError(this.getScreenSharingId(userId));
|
2020-06-14 14:47:16 +02:00
|
|
|
}
|
|
|
|
|
2020-06-06 22:49:55 +02:00
|
|
|
|
2020-09-18 13:57:38 +02:00
|
|
|
private getSpinner(userId: string): HTMLDivElement|null {
|
2020-06-09 23:13:26 +02:00
|
|
|
const element = document.getElementById(`div-${userId}`);
|
2020-06-06 22:49:55 +02:00
|
|
|
if(!element){
|
|
|
|
return null;
|
|
|
|
}
|
2020-06-09 23:13:26 +02:00
|
|
|
const connnectingSpinnerDiv = element.getElementsByClassName('connecting-spinner').item(0) as HTMLDivElement|null;
|
2020-06-06 22:49:55 +02:00
|
|
|
return connnectingSpinnerDiv;
|
|
|
|
}
|
2021-05-11 10:56:50 +02:00
|
|
|
|
2020-05-14 20:39:30 +02:00
|
|
|
private getColorByString(str: String) : String|null {
|
|
|
|
let hash = 0;
|
|
|
|
if (str.length === 0) return null;
|
|
|
|
for (let i = 0; i < str.length; i++) {
|
|
|
|
hash = str.charCodeAt(i) + ((hash << 5) - hash);
|
|
|
|
hash = hash & hash;
|
|
|
|
}
|
|
|
|
let color = '#';
|
|
|
|
for (let i = 0; i < 3; i++) {
|
2020-06-09 23:13:26 +02:00
|
|
|
const value = (hash >> (i * 8)) & 255;
|
2020-05-14 20:39:30 +02:00
|
|
|
color += ('00' + value.toString(16)).substr(-2);
|
|
|
|
}
|
|
|
|
return color;
|
|
|
|
}
|
2020-06-03 11:55:31 +02:00
|
|
|
|
2021-01-29 21:09:10 +01:00
|
|
|
public addNewParticipant(userId: number|string, name: string|undefined, img?: string, showReportUserCallBack?: ShowReportCallBack){
|
|
|
|
discussionManager.addParticipant(userId, name, img, false, showReportUserCallBack);
|
2020-10-25 21:59:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public removeParticipant(userId: number|string){
|
2020-12-04 11:30:35 +01:00
|
|
|
discussionManager.removeParticipant(userId);
|
2020-10-25 21:59:14 +01:00
|
|
|
}
|
2020-11-17 18:03:44 +01:00
|
|
|
public addTriggerCloseJitsiFrameButton(id: String, Function: Function){
|
|
|
|
this.triggerCloseJistiFrame.set(id, Function);
|
|
|
|
}
|
|
|
|
|
|
|
|
public removeTriggerCloseJitsiFrameButton(id: String){
|
|
|
|
this.triggerCloseJistiFrame.delete(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
private triggerCloseJitsiFrameButton(): void {
|
|
|
|
for (const callback of this.triggerCloseJistiFrame.values()) {
|
|
|
|
callback();
|
|
|
|
}
|
|
|
|
}
|
2020-11-04 12:42:33 +01:00
|
|
|
/**
|
|
|
|
* For some reasons, the microphone muted icon or the stream is not always up to date.
|
|
|
|
* Here, every 30 seconds, we are "reseting" the streams and sending again the constraints to the other peers via the data channel again (see SimplePeer::pushVideoToRemoteUser)
|
|
|
|
**/
|
2020-10-24 14:40:51 +02:00
|
|
|
private pingCameraStatus(){
|
2020-11-27 14:51:50 +01:00
|
|
|
/*setInterval(() => {
|
2020-10-24 14:40:51 +02:00
|
|
|
console.log('ping camera status');
|
2020-11-21 18:47:38 +01:00
|
|
|
this.triggerUpdatedLocalStreamCallbacks(this.localStream);
|
2020-11-27 14:51:50 +01:00
|
|
|
}, 30000);*/
|
2020-10-24 14:40:51 +02:00
|
|
|
}
|
2020-10-13 19:56:42 +02:00
|
|
|
|
2020-10-25 21:59:14 +01:00
|
|
|
public addNewMessage(name: string, message: string, isMe: boolean = false){
|
2020-12-04 11:30:35 +01:00
|
|
|
discussionManager.addMessage(name, message, isMe);
|
2020-11-17 16:46:46 +01:00
|
|
|
|
|
|
|
//when there are new message, show discussion
|
2020-12-04 11:30:35 +01:00
|
|
|
if(!discussionManager.activatedDiscussion) {
|
|
|
|
discussionManager.showDiscussionPart();
|
2020-11-17 16:46:46 +01:00
|
|
|
}
|
2020-10-25 21:59:14 +01:00
|
|
|
}
|
|
|
|
|
2020-10-26 14:13:51 +01:00
|
|
|
public addSendMessageCallback(userId: string|number, callback: SendMessageCallback){
|
2020-12-04 11:30:35 +01:00
|
|
|
discussionManager.onSendMessageCallback(userId, callback);
|
2020-10-25 21:59:14 +01:00
|
|
|
}
|
2020-10-27 20:46:53 +01:00
|
|
|
|
|
|
|
get activatedDiscussion(){
|
2020-12-04 11:30:35 +01:00
|
|
|
return discussionManager.activatedDiscussion;
|
2020-10-27 20:46:53 +01:00
|
|
|
}
|
2020-11-10 12:38:32 +01:00
|
|
|
|
|
|
|
public setUserInputManager(userInputManager : UserInputManager){
|
2021-05-05 01:49:04 +02:00
|
|
|
this.userInputManager = userInputManager;
|
2020-12-04 11:30:35 +01:00
|
|
|
discussionManager.setUserInputManager(userInputManager);
|
2020-11-10 12:38:32 +01:00
|
|
|
}
|
2021-01-29 21:09:10 +01:00
|
|
|
|
|
|
|
public setShowReportModalCallBacks(callback: ShowReportCallBack){
|
|
|
|
this.showReportModalCallBacks.add(callback);
|
|
|
|
}
|
2021-05-05 01:49:04 +02:00
|
|
|
|
2021-05-10 20:49:17 +02:00
|
|
|
//FIX ME SOUNDMETER: check stalability of sound meter calculation
|
|
|
|
/*updateSoudMeter(){
|
2021-05-05 01:49:04 +02:00
|
|
|
try{
|
|
|
|
const volume = parseInt(((this.mySoundMeter ? this.mySoundMeter.getVolume() : 0) / 10).toFixed(0));
|
|
|
|
this.setVolumeSoundMeter(volume, this.mySoundMeterElement);
|
2021-05-11 10:56:50 +02:00
|
|
|
|
2021-05-05 01:49:04 +02:00
|
|
|
for(const indexUserId of this.soundMeters.keys()){
|
|
|
|
const soundMeter = this.soundMeters.get(indexUserId);
|
|
|
|
const soundMeterElement = this.soundMeterElements.get(indexUserId);
|
|
|
|
if(!soundMeter || !soundMeterElement){
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const volumeByUser = parseInt((soundMeter.getVolume() / 10).toFixed(0));
|
|
|
|
this.setVolumeSoundMeter(volumeByUser, soundMeterElement);
|
|
|
|
}
|
|
|
|
}catch(err){
|
|
|
|
//console.error(err);
|
|
|
|
}
|
2021-05-10 20:49:17 +02:00
|
|
|
}*/
|
2021-05-05 01:49:04 +02:00
|
|
|
|
|
|
|
private setVolumeSoundMeter(volume: number, element: HTMLDivElement){
|
|
|
|
if(volume <= 0 && !element.classList.contains('active')){
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
element.classList.remove('active');
|
|
|
|
if(volume <= 0){
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
element.classList.add('active');
|
|
|
|
element.childNodes.forEach((value: ChildNode, index) => {
|
|
|
|
const elementChildre = element.children.item(index);
|
|
|
|
if(!elementChildre){
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
elementChildre.classList.remove('active');
|
|
|
|
if((index +1) > volume){
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
elementChildre.classList.add('active');
|
|
|
|
});
|
|
|
|
}
|
2021-05-07 01:37:05 +02:00
|
|
|
|
|
|
|
public getNotification(){
|
|
|
|
//Get notification
|
2021-05-17 13:50:31 +02:00
|
|
|
if (!DISABLE_NOTIFICATIONS && window.Notification && Notification.permission !== "granted") {
|
2021-06-03 10:17:38 +02:00
|
|
|
if (this.checkNotificationPromise()) {
|
|
|
|
Notification.requestPermission().catch((err) => {
|
|
|
|
console.error(`Notification permission error`, err);
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
Notification.requestPermission();
|
|
|
|
}
|
2021-05-07 01:37:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-03 10:17:38 +02:00
|
|
|
/**
|
|
|
|
* Return true if the browser supports the modern version of the Notification API (which is Promise based) or false
|
|
|
|
* if we are on Safari...
|
|
|
|
*
|
|
|
|
* See https://developer.mozilla.org/en-US/docs/Web/API/Notifications_API/Using_the_Notifications_API
|
|
|
|
*/
|
|
|
|
private checkNotificationPromise(): boolean {
|
|
|
|
try {
|
|
|
|
Notification.requestPermission().then();
|
|
|
|
} catch(e) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-05-07 01:37:05 +02:00
|
|
|
public createNotification(userName: string){
|
|
|
|
if(this.focused){
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (window.Notification && Notification.permission === "granted") {
|
|
|
|
const title = 'WorkAdventure';
|
|
|
|
const options = {
|
|
|
|
body: `Hi! ${userName} wants to discuss with you, don't be afraid!`,
|
|
|
|
icon: '/resources/logos/logo-WA-min.png',
|
|
|
|
image: '/resources/logos/logo-WA-min.png',
|
|
|
|
badge: '/resources/logos/logo-WA-min.png',
|
|
|
|
};
|
|
|
|
new Notification(title, options);
|
|
|
|
//new Notification(`Hi! ${userName} wants to discuss with you, don't be afraid!`);
|
|
|
|
}
|
|
|
|
}
|
2020-06-03 11:55:31 +02:00
|
|
|
}
|
2020-06-23 14:56:57 +02:00
|
|
|
|
|
|
|
export const mediaManager = new MediaManager();
|