2022-01-24 11:18:23 +01:00
|
|
|
import { Component, Input, OnInit } from '@angular/core';
|
2022-01-20 11:53:56 +01:00
|
|
|
import { RestService } from '../../services/rest/rest.service';
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'ov-videoconference',
|
|
|
|
templateUrl: './videoconference.component.html',
|
|
|
|
styleUrls: ['./videoconference.component.css']
|
|
|
|
})
|
|
|
|
export class VideoconferenceComponent implements OnInit {
|
|
|
|
@Input() sessionName: string;
|
|
|
|
@Input() userName: string;
|
|
|
|
@Input() openviduServerUrl: string;
|
|
|
|
@Input() openviduSecret: string;
|
2022-01-24 11:18:23 +01:00
|
|
|
@Input() tokens: { webcam: string; screen: string };
|
2022-01-20 11:53:56 +01:00
|
|
|
|
|
|
|
joinSessionClicked: boolean = false;
|
|
|
|
closeClicked: boolean = false;
|
|
|
|
isSessionAlive: boolean = false;
|
|
|
|
_tokens: { webcam: string; screen: string };
|
|
|
|
error: boolean = false;
|
|
|
|
errorMessage: string = '';
|
|
|
|
|
|
|
|
constructor(private restService: RestService) {}
|
|
|
|
|
|
|
|
ngOnInit() {}
|
|
|
|
|
|
|
|
async onJoinClicked() {
|
2022-01-24 11:18:23 +01:00
|
|
|
if (!this.tokens || (!this.tokens?.webcam && !this.tokens?.screen)) {
|
2022-01-20 11:53:56 +01:00
|
|
|
//No tokens received
|
|
|
|
|
|
|
|
if (!!this.sessionName && !!this.openviduServerUrl && !!this.openviduSecret) {
|
|
|
|
// Generate tokens
|
|
|
|
this._tokens = {
|
|
|
|
webcam: await this.restService.getToken(this.sessionName, this.openviduServerUrl, this.openviduSecret),
|
|
|
|
screen: await this.restService.getToken(this.sessionName, this.openviduServerUrl, this.openviduSecret)
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
// No tokens received and can't generate them
|
|
|
|
this.error = true;
|
|
|
|
this.errorMessage = `Cannot access to OpenVidu Server with url '${this.openviduServerUrl}' to genere tokens for session '${this.sessionName}'`;
|
|
|
|
throw this.errorMessage;
|
|
|
|
}
|
2022-01-24 11:18:23 +01:00
|
|
|
} else if (!this.tokens?.webcam || !this.tokens?.screen) {
|
2022-01-20 11:53:56 +01:00
|
|
|
// 1 token received
|
2022-01-24 11:18:23 +01:00
|
|
|
const aditionalToken = await this.restService.getToken(this.sessionName, this.openviduServerUrl, this.openviduSecret);
|
2022-01-20 11:53:56 +01:00
|
|
|
this._tokens = {
|
2022-01-24 11:18:23 +01:00
|
|
|
webcam: !!this.tokens.webcam ? this.tokens.webcam : aditionalToken,
|
|
|
|
screen: !!this.tokens.screen ? this.tokens.screen : aditionalToken
|
2022-01-20 11:53:56 +01:00
|
|
|
};
|
|
|
|
} else {
|
|
|
|
// 2 tokens received.
|
|
|
|
this._tokens = {
|
2022-01-24 11:18:23 +01:00
|
|
|
webcam: this.tokens.webcam,
|
|
|
|
screen: this.tokens.screen
|
2022-01-20 11:53:56 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
this.joinSessionClicked = true;
|
|
|
|
this.isSessionAlive = true;
|
|
|
|
}
|
|
|
|
onLeaveSessionClicked() {
|
|
|
|
this.isSessionAlive = false;
|
|
|
|
this.closeClicked = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
onMicClicked() {}
|
|
|
|
|
|
|
|
onCamClicked() {}
|
|
|
|
|
|
|
|
onScreenShareClicked() {}
|
|
|
|
|
|
|
|
onSpeakerLayoutClicked() {}
|
|
|
|
}
|