openvidu-components: Refactored participant service

Moved some methods to participant model
pull/809/head
Carlos Santos 2023-03-01 18:04:17 +01:00
parent 749948a6d9
commit d78774b218
3 changed files with 35 additions and 39 deletions

View File

@ -253,12 +253,14 @@ export class SessionComponent implements OnInit, OnDestroy {
private async connectToSession(): Promise<void> {
try {
const nickname = this.participantService.getMyNickname();
const participantId = this.participantService.getLocalParticipant().id;
const participant = this.participantService.getLocalParticipant();
const nickname = participant.getNickname();
const participantId = participant.id;
const screenPublisher = this.participantService.getMyScreenPublisher();
const cameraPublisher = this.participantService.getMyCameraPublisher();
if (this.participantService.haveICameraAndScreenActive()) {
if (participant.hasCameraAndScreenActives()) {
const webcamSessionId = await this.openviduService.connectWebcamSession(participantId, nickname);
if (webcamSessionId) this.participantService.setMyCameraConnectionId(webcamSessionId);
@ -266,10 +268,9 @@ export class SessionComponent implements OnInit, OnDestroy {
const screenSessionId = await this.openviduService.connectScreenSession(participantId, nickname);
if (screenSessionId) this.participantService.setMyScreenConnectionId(screenSessionId);
await this.openviduService.publishCamera(cameraPublisher);
await this.openviduService.publishScreen(screenPublisher);
} else if (this.participantService.isOnlyMyScreenActive()) {
} else if (participant.hasOnlyScreenActive()) {
await this.openviduService.connectScreenSession(participantId, nickname);
await this.openviduService.publishScreen(screenPublisher);
} else {

View File

@ -218,7 +218,6 @@ export abstract class ParticipantAbstractModel {
*/
isLocal(): boolean {
return this.local;
// return Array.from(this.streams.values()).every((conn) => conn.local);
}
/**
@ -307,6 +306,30 @@ export abstract class ParticipantAbstractModel {
if (screenConnection) screenConnection.connected = false;
}
/**
* @internal
* @returns true if both camera and screen are active
*/
hasCameraAndScreenActives(): boolean {
return this.isCameraActive() && this.isScreenActive();
}
/**
* @internal
* @returns true if only screen is active
*/
hasOnlyScreenActive(): boolean {
return this.isScreenActive() && !this.isCameraActive();
}
/**
* @internal
* @returns true if only camera is active
*/
hasOnlyCameraActive(): boolean {
return this.isCameraActive() && !this.isScreenActive();
}
/**
* @internal
*/

View File

@ -76,12 +76,12 @@ export class ParticipantService {
const screenPublisher = this.getMyScreenPublisher();
// Disabling webcam
if (this.haveICameraAndScreenActive()) {
if (this.localParticipant.hasCameraAndScreenActives()) {
await this.publishVideoAux(cameraPublisher, publish);
this.disableWebcamStream();
this.openviduService.unpublishCamera(cameraPublisher);
this.publishAudioAux(screenPublisher, publishAudio);
} else if (this.isOnlyMyScreenActive()) {
} else if (this.localParticipant.hasOnlyScreenActive()) {
// Enabling webcam
const hasAudio = this.hasScreenAudioActive();
const sessionId = await this.openviduService.connectWebcamSession(this.getMyNickname(), this.getLocalParticipant().id);
@ -106,7 +106,7 @@ export class ParticipantService {
*/
publishAudio(publish: boolean): void {
if (this.isMyCameraActive()) {
if (this.isMyScreenActive() && this.hasScreenAudioActive()) {
if (this.localParticipant.isScreenActive() && this.hasScreenAudioActive()) {
this.publishAudioAux(this.getMyScreenPublisher(), false);
}
@ -129,12 +129,12 @@ export class ParticipantService {
const participantNickname = this.getMyNickname();
const participantId = this.getLocalParticipant().id;
if (this.haveICameraAndScreenActive()) {
if (this.localParticipant.hasCameraAndScreenActives()) {
// Disabling screenShare
this.disableScreenStream();
this.updateLocalParticipant();
this.openviduService.unpublishScreen(screenPublisher);
} else if (this.isOnlyMyCameraActive()) {
} else if (this.localParticipant.hasOnlyCameraActive()) {
// I only have the camera published
const willWebcamBePresent = this.isMyCameraActive() && this.isMyVideoActive();
const hasAudio = willWebcamBePresent ? false : this.isMyAudioActive();
@ -336,34 +336,6 @@ export class ParticipantService {
return this.localParticipant?.hasAudioActive();
}
/**
* @internal
*/
isMyScreenActive(): boolean {
return this.localParticipant.isScreenActive();
}
/**
* @internal
*/
isOnlyMyCameraActive(): boolean {
return this.isMyCameraActive() && !this.isMyScreenActive();
}
/**
* @internal
*/
isOnlyMyScreenActive(): boolean {
return this.isMyScreenActive() && !this.isMyCameraActive();
}
/**
* @internal
*/
haveICameraAndScreenActive(): boolean {
return this.isMyCameraActive() && this.isMyScreenActive();
}
/**
* @internal
*/