openvidu-components: Refactored Participant model

pull/809/head
Carlos Santos 2023-03-21 16:30:50 +01:00
parent 197b46f212
commit fb057a5823
3 changed files with 13 additions and 13 deletions

View File

@ -300,9 +300,9 @@ export class SessionComponent implements OnInit, OnDestroy {
private subscribeToConnectionCreatedAndDestroyed() { private subscribeToConnectionCreatedAndDestroyed() {
this.session.on('connectionCreated', async (event: ConnectionEvent) => { this.session.on('connectionCreated', async (event: ConnectionEvent) => {
const connectionId = event.connection?.connectionId; const connectionId = event.connection?.connectionId;
const newNickname: string = this.participantService.getNicknameFromConnectionData(event.connection.data); const connectionNickname: string = this.participantService.getNicknameFromConnectionData(event.connection.data);
const isRemoteConnection: boolean = !this.openviduService.isMyOwnConnection(connectionId); const isRemoteConnection: boolean = !this.openviduService.isMyOwnConnection(connectionId);
const isCameraConnection: boolean = !newNickname?.includes(`_${VideoType.SCREEN}`); const isCameraConnection: boolean = !connectionNickname?.includes(`_${VideoType.SCREEN}`);
const nickname = this.participantService.getMyNickname(); const nickname = this.participantService.getMyNickname();
const data = event.connection?.data; const data = event.connection?.data;
@ -310,9 +310,9 @@ export class SessionComponent implements OnInit, OnDestroy {
// Adding participant when connection is created and it's not screen // Adding participant when connection is created and it's not screen
this.participantService.addRemoteConnection(connectionId, data, null); this.participantService.addRemoteConnection(connectionId, data, null);
//Sending nicnkanme signal to new participants //Sending nicnkanme signal to new connection
if (this.openviduService.needSendNicknameSignal(nickname)) { if (this.openviduService.myNicknameHasBeenChanged()) {
const data = { clientData: this.participantService.getMyNickname() }; const data = { clientData: nickname };
await this.openviduService.sendSignal(Signal.NICKNAME_CHANGED, [event.connection], data); await this.openviduService.sendSignal(Signal.NICKNAME_CHANGED, [event.connection], data);
} }
} }

View File

@ -21,7 +21,7 @@ export interface StreamModel {
/** /**
* The streamManager object from openvidu-browser library.{@link https://docs.openvidu.io/en/stable/api/openvidu-browser/classes/StreamManager.html} * The streamManager object from openvidu-browser library.{@link https://docs.openvidu.io/en/stable/api/openvidu-browser/classes/StreamManager.html}
*/ */
streamManager: StreamManager; streamManager: StreamManager | undefined;
/** /**
* Whether the stream is enlarged or not * Whether the stream is enlarged or not
*/ */
@ -29,7 +29,7 @@ export interface StreamModel {
/** /**
* Unique identifier of the stream * Unique identifier of the stream
*/ */
connectionId: string; connectionId: string | undefined;
/** /**
* The participant object * The participant object
*/ */
@ -68,7 +68,7 @@ export abstract class ParticipantAbstractModel {
isMutedForcibly: boolean; isMutedForcibly: boolean;
constructor(props: ParticipantProperties, model?: StreamModel) { constructor(props: ParticipantProperties, model?: StreamModel) {
this.id = props.id ? props.id : Math.random().toString(32).replace('.','_'); this.id = props.id || Math.random().toString(32).replace('.','_');
this.local = props.local; this.local = props.local;
this.nickname = props.nickname; this.nickname = props.nickname;
this.colorProfile = !!props.colorProfile ? props.colorProfile : `hsl(${Math.random() * 360}, 100%, 80%)`; this.colorProfile = !!props.colorProfile ? props.colorProfile : `hsl(${Math.random() * 360}, 100%, 80%)`;
@ -76,9 +76,9 @@ export abstract class ParticipantAbstractModel {
let streamModel: StreamModel = { let streamModel: StreamModel = {
connected: model ? model.connected : true, connected: model ? model.connected : true,
type: model ? model.type : VideoType.CAMERA, type: model ? model.type : VideoType.CAMERA,
streamManager: model ? model.streamManager : null, streamManager: model?.streamManager,
videoEnlarged: model ? model.videoEnlarged : false, videoEnlarged: model ? model.videoEnlarged : false,
connectionId: model ? model.connectionId : null, connectionId: model?.connectionId,
participant: this participant: this
}; };
this.streams.set(streamModel.type, streamModel); this.streams.set(streamModel.type, streamModel);
@ -113,7 +113,7 @@ export abstract class ParticipantAbstractModel {
private isCameraAudioActive(): boolean { private isCameraAudioActive(): boolean {
const cameraConnection = this.getCameraConnection(); const cameraConnection = this.getCameraConnection();
if (cameraConnection?.connected) { if (cameraConnection?.connected) {
return cameraConnection.streamManager?.stream?.audioActive; return cameraConnection.streamManager?.stream?.audioActive || false;
} }
return false; return false;
} }
@ -132,7 +132,7 @@ export abstract class ParticipantAbstractModel {
isScreenAudioActive(): boolean { isScreenAudioActive(): boolean {
const screenConnection = this.getScreenConnection(); const screenConnection = this.getScreenConnection();
if (screenConnection?.connected) { if (screenConnection?.connected) {
return screenConnection?.streamManager?.stream?.audioActive; return screenConnection?.streamManager?.stream?.audioActive || false;
} }
return false; return false;
} }

View File

@ -557,7 +557,7 @@ export class OpenViduService {
/** /**
* @internal * @internal
*/ */
needSendNicknameSignal(): boolean { myNicknameHasBeenChanged(): boolean {
const participantService = this.injector.get(ParticipantService); const participantService = this.injector.get(ParticipantService);
let oldNickname: string = ""; let oldNickname: string = "";
try { try {