mirror of https://github.com/OpenVidu/openvidu.git
openvidu-components: Decoupled replaceTrack from participant service
- Refactored replace track method avoiding to use participant service - Split method in two replaceScreenTrack and replaceCameraTrackpull/809/head
parent
c52f632d7c
commit
197b46f212
|
@ -3,7 +3,6 @@ import { PublisherProperties } from 'openvidu-browser';
|
||||||
import { Subscription } from 'rxjs';
|
import { Subscription } from 'rxjs';
|
||||||
import { CustomDevice } from '../../../models/device.model';
|
import { CustomDevice } from '../../../models/device.model';
|
||||||
import { ParticipantAbstractModel } from '../../../models/participant.model';
|
import { ParticipantAbstractModel } from '../../../models/participant.model';
|
||||||
import { VideoType } from '../../../models/video-type.model';
|
|
||||||
import { DeviceService } from '../../../services/device/device.service';
|
import { DeviceService } from '../../../services/device/device.service';
|
||||||
import { OpenViduService } from '../../../services/openvidu/openvidu.service';
|
import { OpenViduService } from '../../../services/openvidu/openvidu.service';
|
||||||
import { ParticipantService } from '../../../services/participant/participant.service';
|
import { ParticipantService } from '../../../services/participant/participant.service';
|
||||||
|
@ -66,7 +65,8 @@ export class AudioDevicesComponent implements OnInit, OnDestroy {
|
||||||
const audioSource = event?.value;
|
const audioSource = event?.value;
|
||||||
if (this.deviceSrv.needUpdateAudioTrack(audioSource)) {
|
if (this.deviceSrv.needUpdateAudioTrack(audioSource)) {
|
||||||
const pp: PublisherProperties = { audioSource, videoSource: false };
|
const pp: PublisherProperties = { audioSource, videoSource: false };
|
||||||
await this.openviduService.replaceTrack(VideoType.CAMERA, pp);
|
const publisher = this.participantService.getMyCameraPublisher();
|
||||||
|
await this.openviduService.replaceCameraTrack(publisher, pp);
|
||||||
this.deviceSrv.setMicSelected(audioSource);
|
this.deviceSrv.setMicSelected(audioSource);
|
||||||
this.microphoneSelected = this.deviceSrv.getMicrophoneSelected();
|
this.microphoneSelected = this.deviceSrv.getMicrophoneSelected();
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,6 @@ import { Subscription } from 'rxjs';
|
||||||
import { CustomDevice } from '../../../models/device.model';
|
import { CustomDevice } from '../../../models/device.model';
|
||||||
import { PanelType } from '../../../models/panel.model';
|
import { PanelType } from '../../../models/panel.model';
|
||||||
import { ParticipantAbstractModel } from '../../../models/participant.model';
|
import { ParticipantAbstractModel } from '../../../models/participant.model';
|
||||||
import { VideoType } from '../../../models/video-type.model';
|
|
||||||
import { DeviceService } from '../../../services/device/device.service';
|
import { DeviceService } from '../../../services/device/device.service';
|
||||||
import { OpenViduService } from '../../../services/openvidu/openvidu.service';
|
import { OpenViduService } from '../../../services/openvidu/openvidu.service';
|
||||||
import { PanelService } from '../../../services/panel/panel.service';
|
import { PanelService } from '../../../services/panel/panel.service';
|
||||||
|
@ -88,7 +87,8 @@ export class VideoDevicesComponent implements OnInit, OnDestroy {
|
||||||
await this.backgroundService.removeBackground();
|
await this.backgroundService.removeBackground();
|
||||||
}
|
}
|
||||||
const pp: PublisherProperties = { videoSource: device.device, audioSource: false, mirror };
|
const pp: PublisherProperties = { videoSource: device.device, audioSource: false, mirror };
|
||||||
await this.openviduService.replaceTrack(VideoType.CAMERA, pp);
|
const publisher = this.participantService.getMyCameraPublisher();
|
||||||
|
await this.openviduService.replaceCameraTrack(publisher, pp);
|
||||||
|
|
||||||
if (isBackgroundApplied) {
|
if (isBackgroundApplied) {
|
||||||
const bgSelected = this.backgroundService.backgrounds.find((b) => b.id === backgroundSelected);
|
const bgSelected = this.backgroundService.backgrounds.find((b) => b.id === backgroundSelected);
|
||||||
|
|
|
@ -252,7 +252,8 @@ export class StreamComponent implements OnInit {
|
||||||
publishAudio: !this.participantService.isMyCameraActive(),
|
publishAudio: !this.participantService.isMyCameraActive(),
|
||||||
mirror: false
|
mirror: false
|
||||||
};
|
};
|
||||||
await this.openviduService.replaceTrack(VideoType.SCREEN, properties);
|
const publisher = this.participantService.getMyScreenPublisher();
|
||||||
|
await this.openviduService.replaceScreenTrack(publisher, properties);
|
||||||
}
|
}
|
||||||
|
|
||||||
private checkVideoEnlarged() {
|
private checkVideoEnlarged() {
|
||||||
|
|
|
@ -411,45 +411,49 @@ export class OpenViduService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
|
* @param cameraPublisher
|
||||||
|
* @param props
|
||||||
*/
|
*/
|
||||||
async replaceTrack(videoType: VideoType, props: PublisherProperties) {
|
async replaceCameraTrack(cameraPublisher: Publisher, props: PublisherProperties) {
|
||||||
const participantService = this.injector.get(ParticipantService);
|
const isReplacingAudio = !!props.audioSource;
|
||||||
const screenPublisher = participantService.getMyScreenPublisher();
|
const isReplacingVideo = !!props.videoSource;
|
||||||
const cameraPublisher = participantService.getMyCameraPublisher();
|
let mediaStream: MediaStream | undefined;
|
||||||
|
let track: MediaStreamTrack | undefined;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
this.log.d(`Replacing ${videoType} track`, props);
|
if (isReplacingVideo || isReplacingAudio) {
|
||||||
|
mediaStream = await this.createMediaStream(props);
|
||||||
|
}
|
||||||
|
|
||||||
if (videoType === VideoType.CAMERA) {
|
if (isReplacingVideo) {
|
||||||
let mediaStream: MediaStream;
|
track = mediaStream?.getVideoTracks()[0];
|
||||||
const isReplacingAudio = !!props.audioSource;
|
} else if (isReplacingAudio) {
|
||||||
const isReplacingVideo = !!props.videoSource;
|
track = mediaStream?.getAudioTracks()[0];
|
||||||
|
}
|
||||||
|
|
||||||
if (isReplacingVideo) {
|
if (track) {
|
||||||
mediaStream = await this.createMediaStream(props);
|
await cameraPublisher.replaceTrack(track);
|
||||||
// Replace video track
|
|
||||||
const videoTrack: MediaStreamTrack = mediaStream.getVideoTracks()[0];
|
|
||||||
await cameraPublisher.replaceTrack(videoTrack);
|
|
||||||
} else if (isReplacingAudio) {
|
|
||||||
mediaStream = await this.createMediaStream(props);
|
|
||||||
// Replace audio track
|
|
||||||
const audioTrack: MediaStreamTrack = mediaStream.getAudioTracks()[0];
|
|
||||||
await cameraPublisher.replaceTrack(audioTrack);
|
|
||||||
}
|
|
||||||
} else if (videoType === VideoType.SCREEN) {
|
|
||||||
try {
|
|
||||||
let newScreenMediaStream = await this.OVScreen.getUserMedia(props);
|
|
||||||
screenPublisher.stream.getMediaStream().getVideoTracks()[0].stop();
|
|
||||||
await screenPublisher.replaceTrack(newScreenMediaStream.getVideoTracks()[0]);
|
|
||||||
} catch (error) {
|
|
||||||
this.log.w('Cannot create the new MediaStream', error);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.log.e('Error replacing track ', error);
|
this.log.e('Error replacing track ', error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @internal
|
||||||
|
* @param screenPublisher
|
||||||
|
* @param props
|
||||||
|
*/
|
||||||
|
async replaceScreenTrack(screenPublisher: Publisher, props: PublisherProperties) {
|
||||||
|
try {
|
||||||
|
let newScreenMediaStream = await this.OVScreen.getUserMedia(props);
|
||||||
|
screenPublisher.stream.getMediaStream().getVideoTracks()[0].stop();
|
||||||
|
await screenPublisher.replaceTrack(newScreenMediaStream.getVideoTracks()[0]);
|
||||||
|
} catch (error) {
|
||||||
|
this.log.w('Cannot create the new MediaStream', error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
* Subscribe all `CAMERA` stream types to speech-to-text
|
* Subscribe all `CAMERA` stream types to speech-to-text
|
||||||
|
|
Loading…
Reference in New Issue