openvidu-browser: fixes for Publishers subscribed to remote

pull/419/head
pabloFuente 2020-03-28 12:22:05 +01:00
parent c111ed20af
commit 3e5853227b
3 changed files with 24 additions and 7 deletions

View File

@ -117,7 +117,8 @@ export class Publisher extends StreamManager {
*/ */
publishAudio(value: boolean): void { publishAudio(value: boolean): void {
if (this.stream.audioActive !== value) { if (this.stream.audioActive !== value) {
this.stream.getMediaStream().getAudioTracks().forEach((track) => { const affectedMediaStream: MediaStream = this.stream.displayMyRemote() ? this.stream.localMediaStreamWhenSubscribedToRemote : this.stream.getMediaStream();
affectedMediaStream.getAudioTracks().forEach((track) => {
track.enabled = value; track.enabled = value;
}); });
if (!!this.session && !!this.stream.streamId) { if (!!this.session && !!this.stream.streamId) {
@ -163,7 +164,8 @@ export class Publisher extends StreamManager {
*/ */
publishVideo(value: boolean): void { publishVideo(value: boolean): void {
if (this.stream.videoActive !== value) { if (this.stream.videoActive !== value) {
this.stream.getMediaStream().getVideoTracks().forEach((track) => { const affectedMediaStream: MediaStream = this.stream.displayMyRemote() ? this.stream.localMediaStreamWhenSubscribedToRemote : this.stream.getMediaStream();
affectedMediaStream.getVideoTracks().forEach((track) => {
track.enabled = value; track.enabled = value;
}); });
if (!!this.session && !!this.stream.streamId) { if (!!this.session && !!this.stream.streamId) {
@ -305,15 +307,16 @@ export class Publisher extends StreamManager {
reject(new Error('Unknown track kind ' + track.kind)); reject(new Error('Unknown track kind ' + track.kind));
} }
(<any>sender).replaceTrack(track).then(() => { (<any>sender).replaceTrack(track).then(() => {
const mediaStream: MediaStream = this.stream.displayMyRemote() ? this.stream.localMediaStreamWhenSubscribedToRemote : this.stream.getMediaStream();
let removedTrack: MediaStreamTrack; let removedTrack: MediaStreamTrack;
if (track.kind === 'video') { if (track.kind === 'video') {
removedTrack = this.stream.getMediaStream().getVideoTracks()[0]; removedTrack = mediaStream.getVideoTracks()[0];
} else { } else {
removedTrack = this.stream.getMediaStream().getAudioTracks()[0]; removedTrack = mediaStream.getAudioTracks()[0];
} }
this.stream.getMediaStream().removeTrack(removedTrack); mediaStream.removeTrack(removedTrack);
removedTrack.stop(); removedTrack.stop();
this.stream.getMediaStream().addTrack(track); mediaStream.addTrack(track);
resolve(); resolve();
}).catch(error => { }).catch(error => {
reject(error); reject(error);

View File

@ -941,7 +941,6 @@ export class Session implements EventDispatcher {
candidate: msg.candidate, candidate: msg.candidate,
component: msg.component, component: msg.component,
foundation: msg.foundation, foundation: msg.foundation,
ip: msg.ip,
port: msg.port, port: msg.port,
priority: msg.priority, priority: msg.priority,
protocol: msg.protocol, protocol: msg.protocol,

View File

@ -195,6 +195,10 @@ export class Stream implements EventDispatcher {
* @hidden * @hidden
*/ */
harkOptions; harkOptions;
/**
* @hidden
*/
localMediaStreamWhenSubscribedToRemote: MediaStream;
/** /**
@ -495,6 +499,16 @@ export class Stream implements EventDispatcher {
}); });
delete this.mediaStream; delete this.mediaStream;
} }
// If subscribeToRemote local MediaStream must be stopped
if (this.localMediaStreamWhenSubscribedToRemote) {
this.localMediaStreamWhenSubscribedToRemote.getAudioTracks().forEach((track) => {
track.stop();
});
this.localMediaStreamWhenSubscribedToRemote.getVideoTracks().forEach((track) => {
track.stop();
});
delete this.localMediaStreamWhenSubscribedToRemote;
}
if (!!this.speechEvent) { if (!!this.speechEvent) {
if (!!this.speechEvent.stop) { if (!!this.speechEvent.stop) {
this.speechEvent.stop(); this.speechEvent.stop();
@ -863,6 +877,7 @@ export class Stream implements EventDispatcher {
this.isLocalStreamPublished = true; this.isLocalStreamPublished = true;
this.publishedOnce = true; this.publishedOnce = true;
if (this.displayMyRemote()) { if (this.displayMyRemote()) {
this.localMediaStreamWhenSubscribedToRemote = this.mediaStream;
this.remotePeerSuccessfullyEstablished(); this.remotePeerSuccessfullyEstablished();
} }
if (reconnect) { if (reconnect) {