2022-03-21 16:33:09 +01:00
|
|
|
import { HttpClient, HttpHeaders } from '@angular/common/http';
|
2022-12-14 13:08:30 +01:00
|
|
|
import { Component, OnInit } from '@angular/core';
|
2022-03-21 16:33:09 +01:00
|
|
|
|
2022-03-22 16:14:24 +01:00
|
|
|
import { ActivatedRoute } from '@angular/router';
|
2022-04-07 12:54:34 +02:00
|
|
|
import { PanelService } from 'openvidu-angular';
|
2022-12-14 13:08:30 +01:00
|
|
|
import { Subscription, throwError as observableThrowError } from 'rxjs';
|
|
|
|
import { catchError } from 'rxjs/operators';
|
2022-03-21 14:23:50 +01:00
|
|
|
|
|
|
|
interface TemplateDirectives {
|
|
|
|
name: string;
|
|
|
|
subDirectives?: TemplateDirectives[];
|
|
|
|
}
|
|
|
|
|
2022-03-22 16:14:24 +01:00
|
|
|
interface APIDirectives {
|
|
|
|
component: string;
|
|
|
|
directives: AttributeDirective[];
|
|
|
|
}
|
|
|
|
|
|
|
|
enum StructuralDirectives {
|
2022-03-21 14:23:50 +01:00
|
|
|
TOOLBAR = 'ovToolbar',
|
|
|
|
TOOLBAR_BUTTONS = 'ovToolbarAdditionalButtons',
|
2022-04-07 12:54:34 +02:00
|
|
|
TOOLBAR_PANEL_BUTTONS = 'ovToolbarAdditionalPanelButtons',
|
2022-03-21 14:23:50 +01:00
|
|
|
PANEL = 'ovPanel',
|
2022-04-07 12:54:34 +02:00
|
|
|
ADDITIONAL_PANELS = 'ovAdditionalPanels',
|
2022-03-21 14:23:50 +01:00
|
|
|
CHAT_PANEL = 'ovChatPanel',
|
|
|
|
PARTICIPANTS_PANEL = 'ovParticipantsPanel',
|
|
|
|
PARTICIPANTS_PANEL_ITEM = 'ovParticipantPanelItem',
|
2022-03-22 16:14:24 +01:00
|
|
|
PARTICIPANTS_PANEL_ITEM_ELEMENTS = 'ovParticipantPanelItemElements',
|
2022-06-01 18:15:44 +02:00
|
|
|
ACTIVITIES_PANEL = 'ovActivitiesPanel',
|
2022-03-21 14:23:50 +01:00
|
|
|
LAYOUT = 'ovLayout',
|
|
|
|
STREAM = 'ovStream'
|
|
|
|
}
|
|
|
|
|
2022-03-22 16:14:24 +01:00
|
|
|
export enum AttributeDirective {
|
|
|
|
// MINIMAL = 'minimal',
|
|
|
|
// PARTICIPANT_NAME = 'participantName',
|
|
|
|
// PREJOIN = 'prejoin',
|
|
|
|
// VIDEO_MUTED = 'videoMuted',
|
|
|
|
// AUDIO_MUTED = 'audioMuted',
|
|
|
|
TOOLBAR_SCREENSHARE = 'screenshareButton',
|
|
|
|
TOOLBAR_FULLSCREEN = 'fullscreenButton',
|
|
|
|
TOOLBAR_LEAVE = 'leaveButton',
|
|
|
|
TOOLBAR_PARTICIPANTS_PANEL = 'participantsPanelButton',
|
2022-06-01 18:15:44 +02:00
|
|
|
TOOLBAR_ACTIVITIES_PANEL = 'activitiesPanelButton',
|
2022-03-22 16:14:24 +01:00
|
|
|
TOOLBAR_CHAT_PANEL = 'chatPanelButton',
|
|
|
|
TOOLBAR_DISPLAY_SESSION = 'displaySessionName',
|
|
|
|
TOOLBAR_DISPLAY_LOGO = 'displayLogo',
|
|
|
|
STREAM_PARTICIPANT_NAME = 'displayParticipantName',
|
|
|
|
STREAM_AUDIO_DETECTION = 'displayAudioDetection',
|
|
|
|
STREAM_SETTINGS = 'settingsButton',
|
2022-12-14 13:08:30 +01:00
|
|
|
PARTICIPANT_ITEM_MUTE = 'muteButton',
|
|
|
|
RECORDING_ACTIVITY = 'recordingActivity'
|
2022-03-22 16:14:24 +01:00
|
|
|
}
|
|
|
|
|
2022-03-21 14:23:50 +01:00
|
|
|
@Component({
|
|
|
|
selector: 'app-testing',
|
|
|
|
templateUrl: './testing.component.html',
|
|
|
|
styleUrls: ['./testing.component.scss']
|
|
|
|
})
|
|
|
|
export class TestingComponent implements OnInit {
|
2022-09-23 11:42:38 +02:00
|
|
|
OPENVIDU_SERVER_URL = 'http://localhost:4443';
|
2022-03-21 16:33:09 +01:00
|
|
|
OPENVIDU_SERVER_SECRET = 'MY_SECRET';
|
|
|
|
sessionId: string;
|
2022-03-22 16:14:24 +01:00
|
|
|
templateDirectives: TemplateDirectives[] = [
|
2022-03-21 14:23:50 +01:00
|
|
|
{
|
2022-03-22 16:14:24 +01:00
|
|
|
name: StructuralDirectives.TOOLBAR,
|
2022-04-07 12:54:34 +02:00
|
|
|
subDirectives: [{ name: StructuralDirectives.TOOLBAR_BUTTONS }, { name: StructuralDirectives.TOOLBAR_PANEL_BUTTONS }]
|
2022-03-21 14:23:50 +01:00
|
|
|
},
|
|
|
|
{
|
2022-03-22 16:14:24 +01:00
|
|
|
name: StructuralDirectives.PANEL,
|
2022-03-21 14:23:50 +01:00
|
|
|
subDirectives: [
|
2022-06-01 18:15:44 +02:00
|
|
|
{ name: StructuralDirectives.ACTIVITIES_PANEL },
|
2022-04-07 12:54:34 +02:00
|
|
|
{ name: StructuralDirectives.ADDITIONAL_PANELS },
|
2022-03-22 16:14:24 +01:00
|
|
|
{ name: StructuralDirectives.CHAT_PANEL },
|
2022-03-21 14:23:50 +01:00
|
|
|
{
|
2022-03-22 16:14:24 +01:00
|
|
|
name: StructuralDirectives.PARTICIPANTS_PANEL,
|
2022-03-21 14:23:50 +01:00
|
|
|
subDirectives: [
|
|
|
|
{
|
2022-03-22 16:14:24 +01:00
|
|
|
name: StructuralDirectives.PARTICIPANTS_PANEL_ITEM,
|
|
|
|
subDirectives: [{ name: StructuralDirectives.PARTICIPANTS_PANEL_ITEM_ELEMENTS }]
|
2022-03-21 14:23:50 +01:00
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
2022-03-22 16:14:24 +01:00
|
|
|
name: StructuralDirectives.LAYOUT,
|
|
|
|
subDirectives: [{ name: StructuralDirectives.STREAM }]
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
apiDirectives: APIDirectives[] = [
|
|
|
|
{
|
|
|
|
component: StructuralDirectives.TOOLBAR,
|
|
|
|
directives: [
|
|
|
|
AttributeDirective.TOOLBAR_CHAT_PANEL,
|
|
|
|
AttributeDirective.TOOLBAR_DISPLAY_LOGO,
|
|
|
|
AttributeDirective.TOOLBAR_DISPLAY_SESSION,
|
|
|
|
AttributeDirective.TOOLBAR_FULLSCREEN,
|
|
|
|
AttributeDirective.TOOLBAR_LEAVE,
|
|
|
|
AttributeDirective.TOOLBAR_PARTICIPANTS_PANEL,
|
2022-06-01 18:15:44 +02:00
|
|
|
AttributeDirective.TOOLBAR_ACTIVITIES_PANEL,
|
2022-03-22 16:14:24 +01:00
|
|
|
AttributeDirective.TOOLBAR_SCREENSHARE
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
component: StructuralDirectives.STREAM,
|
|
|
|
directives: [
|
|
|
|
AttributeDirective.STREAM_AUDIO_DETECTION,
|
|
|
|
AttributeDirective.STREAM_PARTICIPANT_NAME,
|
|
|
|
AttributeDirective.STREAM_SETTINGS
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
component: StructuralDirectives.PARTICIPANTS_PANEL_ITEM,
|
|
|
|
directives: [AttributeDirective.PARTICIPANT_ITEM_MUTE]
|
2022-12-14 13:08:30 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
component: StructuralDirectives.ACTIVITIES_PANEL,
|
|
|
|
directives: [AttributeDirective.RECORDING_ACTIVITY]
|
2022-03-21 14:23:50 +01:00
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
showDirectives: boolean = true;
|
|
|
|
ovToolbarSelected = false;
|
|
|
|
ovToolbarAdditionalButtonsSelected = false;
|
2022-04-07 12:54:34 +02:00
|
|
|
ovToolbarAdditionalPanelButtonsSelected = false;
|
2022-03-21 14:23:50 +01:00
|
|
|
ovPanelSelected = false;
|
2022-06-01 18:15:44 +02:00
|
|
|
ovActivitiesPanelSelected = false;
|
2022-04-07 12:54:34 +02:00
|
|
|
ovAdditionalPanelsSelected = false;
|
2022-03-21 14:23:50 +01:00
|
|
|
ovChatPanelSelected = false;
|
|
|
|
ovParticipantsPanelSelected = false;
|
|
|
|
ovParticipantPanelItemSelected = false;
|
|
|
|
ovParticipantPanelItemElementsSelected = false;
|
|
|
|
ovLayoutSelected = false;
|
|
|
|
ovStreamSelected = false;
|
2022-03-22 16:14:24 +01:00
|
|
|
|
|
|
|
displayLogo = true;
|
|
|
|
chatPanelBtn = true;
|
|
|
|
displaySessionId = true;
|
|
|
|
fullscreenBtn = true;
|
|
|
|
leaveBtn = true;
|
|
|
|
participantsPanelBtn = true;
|
2022-06-01 18:15:44 +02:00
|
|
|
activitiesPanelBtn = true;
|
2022-03-22 16:14:24 +01:00
|
|
|
screenshareBtn = true;
|
|
|
|
|
|
|
|
audioDetection = true;
|
|
|
|
participantName = true;
|
|
|
|
settingsBtn = true;
|
|
|
|
participantItemMuteBtn = true;
|
|
|
|
|
2022-03-21 14:23:50 +01:00
|
|
|
tokens: { webcam: any; screen: any };
|
|
|
|
|
2022-03-22 16:14:24 +01:00
|
|
|
subscription: Subscription;
|
|
|
|
|
2022-12-14 13:08:30 +01:00
|
|
|
recordingActivity = true;
|
|
|
|
|
2022-04-07 12:54:34 +02:00
|
|
|
constructor(private httpClient: HttpClient, private route: ActivatedRoute, private panelService: PanelService) {}
|
2022-03-21 14:23:50 +01:00
|
|
|
|
2022-03-22 16:14:24 +01:00
|
|
|
ngOnInit() {
|
|
|
|
this.subscription = this.route.queryParams.subscribe(async (params) => {
|
|
|
|
console.warn(params);
|
2022-04-07 12:54:34 +02:00
|
|
|
if (params?.sessionId) {
|
|
|
|
this.sessionId = params.sessionId;
|
2022-03-22 16:14:24 +01:00
|
|
|
} else {
|
|
|
|
this.sessionId = `testingSession-${(Math.random() + 1).toString(36).substring(7)}`;
|
|
|
|
}
|
|
|
|
|
2022-04-07 12:54:34 +02:00
|
|
|
console.warn('SESSION ID', this.sessionId);
|
2022-03-22 16:14:24 +01:00
|
|
|
this.tokens = {
|
|
|
|
webcam: await this.getToken(this.sessionId),
|
|
|
|
screen: await this.getToken(this.sessionId)
|
|
|
|
};
|
|
|
|
});
|
|
|
|
this.subscription.unsubscribe();
|
2022-03-21 14:23:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
appendElement(id: string) {
|
2022-03-21 16:33:09 +01:00
|
|
|
console.log(id);
|
2022-03-21 14:23:50 +01:00
|
|
|
const eventsDiv = document.getElementById('events');
|
|
|
|
const element = document.createElement('div');
|
|
|
|
element.setAttribute('id', id);
|
|
|
|
element.setAttribute('style', 'height: 1px;');
|
2022-03-22 16:14:24 +01:00
|
|
|
eventsDiv?.appendChild(element);
|
2022-03-21 14:23:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
updateSelection(id: string, value: boolean) {
|
|
|
|
switch (id) {
|
2022-03-22 16:14:24 +01:00
|
|
|
case StructuralDirectives.TOOLBAR:
|
2022-03-21 14:23:50 +01:00
|
|
|
this.ovToolbarSelected = value;
|
|
|
|
break;
|
|
|
|
|
2022-03-22 16:14:24 +01:00
|
|
|
case StructuralDirectives.TOOLBAR_BUTTONS:
|
2022-03-21 14:23:50 +01:00
|
|
|
this.ovToolbarAdditionalButtonsSelected = value;
|
|
|
|
break;
|
|
|
|
|
2022-04-07 12:54:34 +02:00
|
|
|
case StructuralDirectives.TOOLBAR_PANEL_BUTTONS:
|
|
|
|
this.ovToolbarAdditionalPanelButtonsSelected = value;
|
|
|
|
break;
|
|
|
|
|
2022-03-22 16:14:24 +01:00
|
|
|
case StructuralDirectives.PANEL:
|
2022-03-21 14:23:50 +01:00
|
|
|
this.ovPanelSelected = value;
|
|
|
|
break;
|
|
|
|
|
2022-04-07 12:54:34 +02:00
|
|
|
case StructuralDirectives.ADDITIONAL_PANELS:
|
|
|
|
this.ovAdditionalPanelsSelected = value;
|
|
|
|
break;
|
|
|
|
|
2022-06-01 18:15:44 +02:00
|
|
|
case StructuralDirectives.ACTIVITIES_PANEL:
|
|
|
|
this.ovActivitiesPanelSelected = value;
|
|
|
|
break;
|
|
|
|
|
2022-03-22 16:14:24 +01:00
|
|
|
case StructuralDirectives.CHAT_PANEL:
|
2022-03-21 14:23:50 +01:00
|
|
|
this.ovChatPanelSelected = value;
|
|
|
|
break;
|
|
|
|
|
2022-03-22 16:14:24 +01:00
|
|
|
case StructuralDirectives.PARTICIPANTS_PANEL:
|
2022-03-21 14:23:50 +01:00
|
|
|
this.ovParticipantsPanelSelected = value;
|
|
|
|
break;
|
|
|
|
|
2022-03-22 16:14:24 +01:00
|
|
|
case StructuralDirectives.PARTICIPANTS_PANEL_ITEM:
|
2022-03-21 14:23:50 +01:00
|
|
|
this.ovParticipantPanelItemSelected = value;
|
|
|
|
break;
|
|
|
|
|
2022-03-22 16:14:24 +01:00
|
|
|
case StructuralDirectives.PARTICIPANTS_PANEL_ITEM_ELEMENTS:
|
2022-03-21 14:23:50 +01:00
|
|
|
this.ovParticipantPanelItemElementsSelected = value;
|
|
|
|
break;
|
|
|
|
|
2022-03-22 16:14:24 +01:00
|
|
|
case StructuralDirectives.LAYOUT:
|
2022-03-21 14:23:50 +01:00
|
|
|
this.ovLayoutSelected = value;
|
|
|
|
break;
|
|
|
|
|
2022-03-22 16:14:24 +01:00
|
|
|
case StructuralDirectives.STREAM:
|
2022-03-21 14:23:50 +01:00
|
|
|
this.ovStreamSelected = value;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-22 16:14:24 +01:00
|
|
|
updateApiDirective(id: string, value: boolean) {
|
|
|
|
switch (id) {
|
|
|
|
case AttributeDirective.TOOLBAR_CHAT_PANEL:
|
|
|
|
this.chatPanelBtn = value;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AttributeDirective.TOOLBAR_DISPLAY_LOGO:
|
|
|
|
this.displayLogo = value;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AttributeDirective.TOOLBAR_DISPLAY_SESSION:
|
|
|
|
this.displaySessionId = value;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AttributeDirective.TOOLBAR_FULLSCREEN:
|
|
|
|
this.fullscreenBtn = value;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AttributeDirective.TOOLBAR_LEAVE:
|
|
|
|
this.leaveBtn = value;
|
|
|
|
break;
|
|
|
|
case AttributeDirective.TOOLBAR_PARTICIPANTS_PANEL:
|
|
|
|
this.participantsPanelBtn = value;
|
|
|
|
break;
|
2022-06-01 18:15:44 +02:00
|
|
|
case AttributeDirective.TOOLBAR_ACTIVITIES_PANEL:
|
|
|
|
this.activitiesPanelBtn = value;
|
|
|
|
break;
|
2022-03-22 16:14:24 +01:00
|
|
|
case AttributeDirective.TOOLBAR_SCREENSHARE:
|
|
|
|
this.screenshareBtn = value;
|
|
|
|
break;
|
|
|
|
case AttributeDirective.STREAM_AUDIO_DETECTION:
|
|
|
|
this.audioDetection = value;
|
|
|
|
break;
|
|
|
|
case AttributeDirective.STREAM_PARTICIPANT_NAME:
|
|
|
|
this.participantName = value;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AttributeDirective.STREAM_SETTINGS:
|
|
|
|
this.settingsBtn = value;
|
|
|
|
break;
|
|
|
|
case AttributeDirective.PARTICIPANT_ITEM_MUTE:
|
|
|
|
this.participantItemMuteBtn = value;
|
|
|
|
break;
|
2022-12-14 13:08:30 +01:00
|
|
|
case AttributeDirective.RECORDING_ACTIVITY:
|
|
|
|
this.recordingActivity = value;
|
|
|
|
break;
|
2022-03-22 16:14:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-21 14:23:50 +01:00
|
|
|
apply() {
|
|
|
|
this.showDirectives = false;
|
|
|
|
}
|
2022-03-21 16:33:09 +01:00
|
|
|
|
2022-04-07 12:54:34 +02:00
|
|
|
toggleMyPanel(type: string) {
|
|
|
|
this.panelService.togglePanel(type);
|
|
|
|
}
|
|
|
|
|
2022-03-21 16:33:09 +01:00
|
|
|
/**
|
|
|
|
* --------------------------
|
|
|
|
* SERVER-SIDE RESPONSIBILITY
|
|
|
|
* --------------------------
|
|
|
|
* This method retrieve the mandatory user token from OpenVidu Server,
|
|
|
|
* in this case making use Angular http API.
|
|
|
|
* This behavior MUST BE IN YOUR SERVER-SIDE IN PRODUCTION. In this case:
|
|
|
|
* 1) Initialize a Session in OpenVidu Server (POST /openvidu/api/sessions)
|
|
|
|
* 2) Create a Connection in OpenVidu Server (POST /openvidu/api/sessions/<SESSION_ID>/connection)
|
|
|
|
* 3) The Connection.token must be consumed in Session.connect() method
|
|
|
|
*/
|
|
|
|
|
|
|
|
async getToken(sessionId: string): Promise<string> {
|
|
|
|
const id = await this.createSession(sessionId);
|
|
|
|
return await this.createToken(id);
|
|
|
|
}
|
|
|
|
|
2022-03-22 16:14:24 +01:00
|
|
|
createSession(sessionId: string) {
|
2022-03-21 16:33:09 +01:00
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
const body = JSON.stringify({ customSessionId: sessionId });
|
|
|
|
const options = {
|
|
|
|
headers: new HttpHeaders({
|
|
|
|
Authorization: 'Basic ' + btoa('OPENVIDUAPP:' + this.OPENVIDU_SERVER_SECRET),
|
|
|
|
'Content-Type': 'application/json'
|
|
|
|
})
|
|
|
|
};
|
|
|
|
return this.httpClient
|
|
|
|
.post(this.OPENVIDU_SERVER_URL + '/openvidu/api/sessions', body, options)
|
|
|
|
.pipe(
|
|
|
|
catchError((error) => {
|
|
|
|
if (error.status === 409) {
|
|
|
|
resolve(sessionId);
|
|
|
|
} else {
|
|
|
|
console.warn(
|
|
|
|
'No connection to OpenVidu Server. This may be a certificate error at ' + this.OPENVIDU_SERVER_URL
|
|
|
|
);
|
|
|
|
if (
|
|
|
|
window.confirm(
|
|
|
|
'No connection to OpenVidu Server. This may be a certificate error at "' +
|
|
|
|
this.OPENVIDU_SERVER_URL +
|
|
|
|
'"\n\nClick OK to navigate and accept it. If no certificate warning is shown, then check that your OpenVidu Server' +
|
|
|
|
'is up and running at "' +
|
|
|
|
this.OPENVIDU_SERVER_URL +
|
|
|
|
'"'
|
|
|
|
)
|
|
|
|
) {
|
|
|
|
location.assign(this.OPENVIDU_SERVER_URL + '/accept-certificate');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return observableThrowError(error);
|
|
|
|
})
|
|
|
|
)
|
|
|
|
.subscribe((response) => {
|
|
|
|
console.log(response);
|
|
|
|
resolve(response['id']);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
createToken(sessionId): Promise<string> {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
const body = {};
|
|
|
|
const options = {
|
|
|
|
headers: new HttpHeaders({
|
|
|
|
Authorization: 'Basic ' + btoa('OPENVIDUAPP:' + this.OPENVIDU_SERVER_SECRET),
|
|
|
|
'Content-Type': 'application/json'
|
|
|
|
})
|
|
|
|
};
|
|
|
|
return this.httpClient
|
|
|
|
.post(this.OPENVIDU_SERVER_URL + '/openvidu/api/sessions/' + sessionId + '/connection', body, options)
|
|
|
|
.pipe(
|
|
|
|
catchError((error) => {
|
|
|
|
reject(error);
|
|
|
|
return observableThrowError(error);
|
|
|
|
})
|
|
|
|
)
|
|
|
|
.subscribe((response) => {
|
|
|
|
console.log(response);
|
|
|
|
resolve(response['token']);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
2022-03-21 14:23:50 +01:00
|
|
|
}
|