openvidu-browser: rename "value" to "enabled" in publishAudio/publishVideo

pull/722/head
pabloFuente 2022-04-27 12:55:20 +02:00
parent 5226b6d464
commit 6c1f77dd3a
1 changed files with 26 additions and 27 deletions

View File

@ -97,7 +97,7 @@ export class Publisher extends StreamManager {
/** /**
* Publish or unpublish the audio stream (if available). Calling this method twice in a row passing same value will have no effect * Publish or unpublish the audio stream (if available). Calling this method twice in a row passing same `enabled` value will have no effect
* *
* #### Events dispatched * #### Events dispatched
* *
@ -111,13 +111,13 @@ export class Publisher extends StreamManager {
* *
* See [[StreamPropertyChangedEvent]] to learn more. * See [[StreamPropertyChangedEvent]] to learn more.
* *
* @param value `true` to publish the audio stream, `false` to unpublish it * @param enabled `true` to publish the audio stream, `false` to unpublish it
*/ */
publishAudio(value: boolean): void { publishAudio(enabled: boolean): void {
if (this.stream.audioActive !== value) { if (this.stream.audioActive !== enabled) {
const affectedMediaStream: MediaStream = this.stream.displayMyRemote() ? this.stream.localMediaStreamWhenSubscribedToRemote! : this.stream.getMediaStream(); const affectedMediaStream: MediaStream = this.stream.displayMyRemote() ? this.stream.localMediaStreamWhenSubscribedToRemote! : this.stream.getMediaStream();
affectedMediaStream.getAudioTracks().forEach((track) => { affectedMediaStream.getAudioTracks().forEach((track) => {
track.enabled = value; track.enabled = enabled;
}); });
if (!!this.session && !!this.stream.streamId) { if (!!this.session && !!this.stream.streamId) {
this.session.openvidu.sendRequest( this.session.openvidu.sendRequest(
@ -125,31 +125,30 @@ export class Publisher extends StreamManager {
{ {
streamId: this.stream.streamId, streamId: this.stream.streamId,
property: 'audioActive', property: 'audioActive',
newValue: value, newValue: enabled,
reason: 'publishAudio' reason: 'publishAudio'
}, },
(error, response) => { (error, response) => {
if (error) { if (error) {
logger.error("Error sending 'streamPropertyChanged' event", error); logger.error("Error sending 'streamPropertyChanged' event", error);
} else { } else {
this.session.emitEvent('streamPropertyChanged', [new StreamPropertyChangedEvent(this.session, this.stream, 'audioActive', value, !value, 'publishAudio')]); this.session.emitEvent('streamPropertyChanged', [new StreamPropertyChangedEvent(this.session, this.stream, 'audioActive', enabled, !enabled, 'publishAudio')]);
this.emitEvent('streamPropertyChanged', [new StreamPropertyChangedEvent(this, this.stream, 'audioActive', value, !value, 'publishAudio')]); this.emitEvent('streamPropertyChanged', [new StreamPropertyChangedEvent(this, this.stream, 'audioActive', enabled, !enabled, 'publishAudio')]);
this.session.sendVideoData(this.stream.streamManager); this.session.sendVideoData(this.stream.streamManager);
} }
}); });
} }
this.stream.audioActive = value; this.stream.audioActive = enabled;
logger.info("'Publisher' has " + (value ? 'published' : 'unpublished') + ' its audio stream'); logger.info("'Publisher' has " + (enabled ? 'published' : 'unpublished') + ' its audio stream');
} }
} }
publishVideo(enabled: boolean): void;
publishVideo(value: boolean): void; publishVideo(enabled: false, freeResource?: boolean): void;
publishVideo(value: false, freeResource?: boolean): void; publishVideo(enabled: true, track?: MediaStreamTrack): void;
publishVideo(value: true, track?: MediaStreamTrack): void;
/** /**
* Publish or unpublish the video stream (if available). Calling this method twice in a row passing same value will have no effect * Publish or unpublish the video stream (if available). Calling this method twice in a row passing same `enabled` value will have no effect
* *
* #### Events dispatched * #### Events dispatched
* *
@ -163,25 +162,25 @@ export class Publisher extends StreamManager {
* *
* See [[StreamPropertyChangedEvent]] to learn more. * See [[StreamPropertyChangedEvent]] to learn more.
* *
* @param value `true` to publish the video stream, `false` to unpublish it * @param enabled `true` to publish the video stream, `false` to unpublish it
* @param freeResource `true` to free the hardware resource associated to the video track, `false` to keep access to it. Not freeing the resource makes the operation much more efficient, but depending on * @param freeResource `true` to free the hardware resource associated to the video track, `false` to keep access to it. Not freeing the resource makes the operation much more efficient, but depending on
* the platform two side-effects can be introduced: the video device may not be accessible by other applications and the access light of webcams may remain on. This is platform-dependent: some browsers * the platform two side-effects can be introduced: the video device may not be accessible by other applications and the access light of webcams may remain on. This is platform-dependent: some browsers
* will not present the side-effects even when not freeing the resource. openvidu-browser will try to restore the video track automatically calling [[publishVideo]] again with parameter `value` to `true`, * will not present the side-effects even when not freeing the resource. openvidu-browser will try to restore the video track automatically calling [[publishVideo]] again with parameter `enabled` to `true`,
* but if that is not possible parameter `track` can be provided to force a specific `MediaStreamTrack`. * but if that is not possible parameter `track` can be provided to force a specific `MediaStreamTrack`.
* @param track A `MediaStreamTrack` to be used when restoring the video track. This parameter can be useful if the Publisher was unpublished with parameter `freeResource` to true, and openvidu-browser is * @param track A `MediaStreamTrack` to be used when restoring the video track. This parameter can be useful if the Publisher was unpublished with parameter `freeResource` to true, and openvidu-browser is
* not able to successfully re-create the video track as it was before unpublishing. In this way previous track settings will be ignored and this track will be used instead. * not able to successfully re-create the video track as it was before unpublishing. In this way previous track settings will be ignored and this track will be used instead.
*/ */
publishVideo(value: boolean, param?: boolean | MediaStreamTrack): void { publishVideo(enabled: boolean, param?: boolean | MediaStreamTrack): void {
if (this.stream.videoActive !== value) { if (this.stream.videoActive !== enabled) {
const affectedMediaStream: MediaStream = this.stream.displayMyRemote() ? this.stream.localMediaStreamWhenSubscribedToRemote! : this.stream.getMediaStream(); const affectedMediaStream: MediaStream = this.stream.displayMyRemote() ? this.stream.localMediaStreamWhenSubscribedToRemote! : this.stream.getMediaStream();
let mustRestartMediaStream = false; let mustRestartMediaStream = false;
affectedMediaStream.getVideoTracks().forEach((track) => { affectedMediaStream.getVideoTracks().forEach((track) => {
track.enabled = value; track.enabled = enabled;
if (!value && param === true) { if (!enabled && param === true) {
track.stop(); track.stop();
} else if (value && track.readyState === 'ended') { } else if (enabled && track.readyState === 'ended') {
// Resource was freed // Resource was freed
mustRestartMediaStream = true; mustRestartMediaStream = true;
} }
@ -217,21 +216,21 @@ export class Publisher extends StreamManager {
{ {
streamId: this.stream.streamId, streamId: this.stream.streamId,
property: 'videoActive', property: 'videoActive',
newValue: value, newValue: enabled,
reason: 'publishVideo' reason: 'publishVideo'
}, },
(error, response) => { (error, response) => {
if (error) { if (error) {
logger.error("Error sending 'streamPropertyChanged' event", error); logger.error("Error sending 'streamPropertyChanged' event", error);
} else { } else {
this.session.emitEvent('streamPropertyChanged', [new StreamPropertyChangedEvent(this.session, this.stream, 'videoActive', value, !value, 'publishVideo')]); this.session.emitEvent('streamPropertyChanged', [new StreamPropertyChangedEvent(this.session, this.stream, 'videoActive', enabled, !enabled, 'publishVideo')]);
this.emitEvent('streamPropertyChanged', [new StreamPropertyChangedEvent(this, this.stream, 'videoActive', value, !value, 'publishVideo')]); this.emitEvent('streamPropertyChanged', [new StreamPropertyChangedEvent(this, this.stream, 'videoActive', enabled, !enabled, 'publishVideo')]);
this.session.sendVideoData(this.stream.streamManager); this.session.sendVideoData(this.stream.streamManager);
} }
}); });
} }
this.stream.videoActive = value; this.stream.videoActive = enabled;
logger.info("'Publisher' has " + (value ? 'published' : 'unpublished') + ' its video stream'); logger.info("'Publisher' has " + (enabled ? 'published' : 'unpublished') + ' its video stream');
} }
} }