diff --git a/openvidu-browser/src/OpenVidu/Publisher.ts b/openvidu-browser/src/OpenVidu/Publisher.ts index 89db1e1b..0b4ddf13 100644 --- a/openvidu-browser/src/OpenVidu/Publisher.ts +++ b/openvidu-browser/src/OpenVidu/Publisher.ts @@ -283,10 +283,12 @@ export class Publisher extends StreamManager { // Apply PublisherProperties.publishAudio and PublisherProperties.publishVideo if (!!mediaStream.getAudioTracks()[0]) { - mediaStream.getAudioTracks()[0].enabled = !!this.stream.outboundStreamOpts.publisherProperties.publishAudio; + const enabled = (this.stream.audioActive !== undefined && this.stream.audioActive !== null) ? this.stream.audioActive : !!this.stream.outboundStreamOpts.publisherProperties.publishAudio; + mediaStream.getAudioTracks()[0].enabled = enabled; } if (!!mediaStream.getVideoTracks()[0]) { - mediaStream.getVideoTracks()[0].enabled = !!this.stream.outboundStreamOpts.publisherProperties.publishVideo; + const enabled = (this.stream.videoActive !== undefined && this.stream.videoActive !== null) ? this.stream.videoActive : !!this.stream.outboundStreamOpts.publisherProperties.publishVideo; + mediaStream.getVideoTracks()[0].enabled = enabled; } this.videoReference = document.createElement('video'); @@ -507,14 +509,6 @@ export class Publisher extends StreamManager { }); } - /** - * @hidden - */ - updateSession(session: Session): void { - this.session = session; - this.stream.session = session; - } - /** * @hidden */ diff --git a/openvidu-browser/src/OpenVidu/Session.ts b/openvidu-browser/src/OpenVidu/Session.ts index 487cfc90..b46cf097 100644 --- a/openvidu-browser/src/OpenVidu/Session.ts +++ b/openvidu-browser/src/OpenVidu/Session.ts @@ -571,6 +571,7 @@ export class Session implements EventDispatcher { * See [[EventDispatcher.once]] */ once(type: string, handler: (event: SessionDisconnectedEvent | SignalEvent | StreamEvent | ConnectionEvent | PublisherSpeakingEvent | RecordingEvent) => void): Session { + this.ee.once(type, event => { if (event) { console.info("Event '" + type + "' triggered by 'Session'", event); @@ -582,7 +583,6 @@ export class Session implements EventDispatcher { if (type === 'publisherStartSpeaking' || type === 'publisherStopSpeaking') { this.speakingEventsEnabled = true; - // If there are already available remote streams, enable hark in all of them for (const connectionId in this.remoteConnections) { const str = this.remoteConnections[connectionId].stream; diff --git a/openvidu-browser/src/OpenVidu/StreamManager.ts b/openvidu-browser/src/OpenVidu/StreamManager.ts index 14dabbf1..bc481314 100644 --- a/openvidu-browser/src/OpenVidu/StreamManager.ts +++ b/openvidu-browser/src/OpenVidu/StreamManager.ts @@ -350,19 +350,19 @@ export class StreamManager implements EventDispatcher { } } - this.videos.slice().reverse().forEach((streamManagerVideo, index, videos) => { + this.videos.forEach(streamManagerVideo => { // Remove oncanplay event listener (only OpenVidu browser one, not the user ones) streamManagerVideo.video.removeEventListener('canplay', this.canPlayListener); if (!!streamManagerVideo.targetElement) { - // Only remove videos created by OpenVidu Browser (those generated by passing a valid targetElement in OpenVidu.initPublisher and Session.subscribe - // or those created by StreamManager.createVideoElement). These are also the videos that triggered a videoElementCreated event + // Only remove from DOM videos created by OpenVidu Browser (those generated by passing a valid targetElement in OpenVidu.initPublisher + // and Session.subscribe or those created by StreamManager.createVideoElement). All this videos triggered a videoElementCreated event streamManagerVideo.video.parentNode!.removeChild(streamManagerVideo.video); this.ee.emitEvent('videoElementDestroyed', [new VideoElementEvent(streamManagerVideo.video, this, 'videoElementDestroyed')]); - this.videos.splice(videos.length - 1 - index, 1); - } else { - // Remove srcObject in all videos managed by the user - streamManagerVideo.video.srcObject = null; } + // Remove srcObject from the video + streamManagerVideo.video.srcObject = null; + // Remove from collection of videos every video managed by OpenVidu Browser + this.videos.filter(v => !v.targetElement); }); } diff --git a/openvidu-browser/src/OpenViduInternal/Events/PublisherSpeakingEvent.ts b/openvidu-browser/src/OpenViduInternal/Events/PublisherSpeakingEvent.ts index 866df4d9..9f0300b2 100644 --- a/openvidu-browser/src/OpenViduInternal/Events/PublisherSpeakingEvent.ts +++ b/openvidu-browser/src/OpenViduInternal/Events/PublisherSpeakingEvent.ts @@ -26,7 +26,7 @@ import { Session } from '../..'; * - `publisherStopSpeaking`: dispatched by [[Session]] * * More information: - * - This events will only be triggered for **remote streams that have audio tracks** + * - This events will only be triggered for **remote streams that have audio tracks** ([[Stream.hasAudio]] must be true) * - Both events share the same lifecycle. That means that you can subscribe to only one of them if you want, but if you call `Session.off('publisherStopSpeaking')`, * keep in mind that this will also internally remove any 'publisherStartSpeaking' event * - You can further configure how the events are dispatched by setting property `publisherSpeakingEventsOptions` in the call of [[OpenVidu.setAdvancedConfiguration]] diff --git a/openvidu-browser/src/OpenViduInternal/KurentoUtils/kurento-jsonrpc/clients/transports/webSocketWithReconnection.js b/openvidu-browser/src/OpenViduInternal/KurentoUtils/kurento-jsonrpc/clients/transports/webSocketWithReconnection.js index 2d419e70..7dc87096 100644 --- a/openvidu-browser/src/OpenViduInternal/KurentoUtils/kurento-jsonrpc/clients/transports/webSocketWithReconnection.js +++ b/openvidu-browser/src/OpenViduInternal/KurentoUtils/kurento-jsonrpc/clients/transports/webSocketWithReconnection.js @@ -223,7 +223,7 @@ function WebSocketWithReconnection(config) { this.reconnectWs = function() { Logger.debug("reconnectWs"); - reconnectToSameUri(MAX_RETRIES, 1, wsUri); + reconnectToSameUri(MAX_RETRIES, 1); }; this.send = function(message) {