diff --git a/openvidu-browser/package.json b/openvidu-browser/package.json index a2df896b..a2da810e 100644 --- a/openvidu-browser/package.json +++ b/openvidu-browser/package.json @@ -1,31 +1,31 @@ { "author": "OpenVidu", "dependencies": { - "@types/node": "13.13.2", - "@types/platform": "1.3.2", + "@types/node": "14.14.7", + "@types/platform": "1.3.3", "freeice": "2.2.2", "hark": "1.2.3", - "platform": "1.3.5", - "uuid": "7.0.3", + "platform": "1.3.6", + "uuid": "8.3.1", "wolfy87-eventemitter": "5.2.9" }, "description": "OpenVidu Browser", "devDependencies": { - "browserify": "16.5.1", - "grunt": "1.1.0", + "browserify": "17.0.0", + "grunt": "1.3.0", "grunt-cli": "1.3.2", "grunt-contrib-copy": "1.0.0", - "grunt-contrib-sass": "1.0.0", - "grunt-contrib-uglify": "4.0.1", + "grunt-contrib-sass": "2.0.0", + "grunt-contrib-uglify": "5.0.0", "grunt-contrib-watch": "1.1.0", "grunt-postcss": "0.9.0", "grunt-string-replace": "1.3.1", "grunt-ts": "6.0.0-beta.22", - "terser": "4.6.11", - "tsify": "4.0.1", - "tslint": "6.1.1", - "typedoc": "0.17.4", - "typescript": "3.8.3" + "terser": "5.3.8", + "tsify": "5.0.2", + "tslint": "6.1.3", + "typedoc": "0.19.2", + "typescript": "4.0.5" }, "license": "Apache-2.0", "main": "lib/index.js", diff --git a/openvidu-browser/src/OpenVidu/Connection.ts b/openvidu-browser/src/OpenVidu/Connection.ts index 72ad4e32..fe9d1e32 100644 --- a/openvidu-browser/src/OpenVidu/Connection.ts +++ b/openvidu-browser/src/OpenVidu/Connection.ts @@ -71,7 +71,7 @@ export class Connection { /** * @hidden */ - stream: Stream; + stream?: Stream; /** * @hidden @@ -132,7 +132,7 @@ export class Connection { */ sendIceCandidate(candidate: RTCIceCandidate): void { - logger.debug((!!this.stream.outboundStreamOpts ? 'Local' : 'Remote') + 'candidate for' + + logger.debug((!!this.stream!.outboundStreamOpts ? 'Local' : 'Remote') + 'candidate for' + this.connectionId, candidate); this.session.openvidu.sendRequest('onIceCandidate', { @@ -174,7 +174,7 @@ export class Connection { this.addStream(stream); }); - logger.info("Remote 'Connection' with 'connectionId' [" + this.connectionId + '] is now configured for receiving Streams with options: ', this.stream.inboundStreamOpts); + logger.info("Remote 'Connection' with 'connectionId' [" + this.connectionId + '] is now configured for receiving Streams with options: ', this.stream!.inboundStreamOpts); } /** diff --git a/openvidu-browser/src/OpenVidu/Filter.ts b/openvidu-browser/src/OpenVidu/Filter.ts index 134c56c4..a7f0f760 100644 --- a/openvidu-browser/src/OpenVidu/Filter.ts +++ b/openvidu-browser/src/OpenVidu/Filter.ts @@ -119,9 +119,9 @@ export class Filter { } else { logger.info('Filter method successfully executed on Stream ' + this.stream.streamId); const oldValue = (Object).assign({}, this.stream.filter); - this.stream.filter.lastExecMethod = { method, params: JSON.parse(stringParams) }; - this.stream.session.emitEvent('streamPropertyChanged', [new StreamPropertyChangedEvent(this.stream.session, this.stream, 'filter', this.stream.filter, oldValue, 'execFilterMethod')]); - this.stream.streamManager.emitEvent('streamPropertyChanged', [new StreamPropertyChangedEvent(this.stream.streamManager, this.stream, 'filter', this.stream.filter, oldValue, 'execFilterMethod')]); + this.stream.filter!.lastExecMethod = { method, params: JSON.parse(stringParams) }; + this.stream.session.emitEvent('streamPropertyChanged', [new StreamPropertyChangedEvent(this.stream.session, this.stream, 'filter', this.stream.filter!, oldValue, 'execFilterMethod')]); + this.stream.streamManager.emitEvent('streamPropertyChanged', [new StreamPropertyChangedEvent(this.stream.streamManager, this.stream, 'filter', this.stream.filter!, oldValue, 'execFilterMethod')]); resolve(); } } diff --git a/openvidu-browser/src/OpenVidu/LocalRecorder.ts b/openvidu-browser/src/OpenVidu/LocalRecorder.ts index d23085b1..fa18b95e 100644 --- a/openvidu-browser/src/OpenVidu/LocalRecorder.ts +++ b/openvidu-browser/src/OpenVidu/LocalRecorder.ts @@ -50,7 +50,7 @@ export class LocalRecorder { private connectionId: string; private mediaRecorder: any; private chunks: any[] = []; - private blob: Blob; + private blob?: Blob; private id: string; private videoPreviewSrc: string; private videoPreview: HTMLVideoElement; @@ -281,7 +281,7 @@ export class LocalRecorder { if (this.state !== LocalRecorderState.FINISHED) { throw (Error('Call \'LocalRecord.stop()\' before getting Blob file')); } else { - return this.blob; + return this.blob!; } } @@ -351,7 +351,7 @@ export class LocalRecorder { } const sendable = new FormData(); - sendable.append('file', this.blob, this.id + '.webm'); + sendable.append('file', this.blob!, this.id + '.webm'); http.onreadystatechange = () => { if (http.readyState === 4) { diff --git a/openvidu-browser/src/OpenVidu/Publisher.ts b/openvidu-browser/src/OpenVidu/Publisher.ts index e4afac50..26b45193 100644 --- a/openvidu-browser/src/OpenVidu/Publisher.ts +++ b/openvidu-browser/src/OpenVidu/Publisher.ts @@ -127,7 +127,7 @@ export class Publisher extends StreamManager { */ publishAudio(value: boolean): void { if (this.stream.audioActive !== value) { - 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) => { track.enabled = value; }); @@ -175,7 +175,7 @@ export class Publisher extends StreamManager { */ publishVideo(value: boolean): void { if (this.stream.videoActive !== value) { - 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.getVideoTracks().forEach((track) => { track.enabled = value; }); @@ -304,7 +304,7 @@ export class Publisher extends StreamManager { replaceTrack(track: MediaStreamTrack): Promise { const replaceMediaStreamTrack = () => { - const mediaStream: MediaStream = this.stream.displayMyRemote() ? this.stream.localMediaStreamWhenSubscribedToRemote : this.stream.getMediaStream(); + const mediaStream: MediaStream = this.stream.displayMyRemote() ? this.stream.localMediaStreamWhenSubscribedToRemote! : this.stream.getMediaStream(); let removedTrack: MediaStreamTrack; if (track.kind === 'video') { removedTrack = mediaStream.getVideoTracks()[0]; diff --git a/openvidu-browser/src/OpenVidu/Session.ts b/openvidu-browser/src/OpenVidu/Session.ts index 832f2e05..8b914619 100644 --- a/openvidu-browser/src/OpenVidu/Session.ts +++ b/openvidu-browser/src/OpenVidu/Session.ts @@ -802,12 +802,12 @@ export class Session extends EventDispatcher { .then(connection => { - const streamEvent = new StreamEvent(true, this, 'streamDestroyed', connection.stream, msg.reason); + const streamEvent = new StreamEvent(true, this, 'streamDestroyed', connection.stream!, msg.reason); this.ee.emitEvent('streamDestroyed', [streamEvent]); streamEvent.callDefaultBehavior(); // Deleting the remote stream - const streamId: string = connection.stream.streamId; + const streamId: string = connection.stream!.streamId; delete this.remoteStreamsCreated[streamId]; if (Object.keys(this.remoteStreamsCreated).length === 0) { @@ -993,9 +993,9 @@ export class Session extends EventDispatcher { }; this.getConnection(msg.senderConnectionId, 'Connection not found for connectionId ' + msg.senderConnectionId + ' owning endpoint ' + msg.endpointName + '. Ice candidate will be ignored: ' + candidate) .then(connection => { - const stream = connection.stream; + const stream: Stream = connection.stream!; stream.getWebRtcPeer().addIceCandidate(candidate).catch(error => { - logger.error('Error adding candidate for ' + stream.streamId + logger.error('Error adding candidate for ' + stream!.streamId + ' stream of endpoint ' + msg.endpointName + ': ' + error); }); }) @@ -1077,8 +1077,8 @@ export class Session extends EventDispatcher { this.getConnection(connectionId, 'No connection found for connectionId ' + connectionId) .then(connection => { logger.info('Filter event dispatched'); - const stream: Stream = connection.stream; - stream.filter.handlers[response.eventType](new FilterEvent(stream.filter, response.eventType, response.data)); + const stream: Stream = connection.stream!; + stream.filter!.handlers[response.eventType](new FilterEvent(stream.filter!, response.eventType, response.data)); }); } diff --git a/openvidu-browser/src/OpenVidu/Stream.ts b/openvidu-browser/src/OpenVidu/Stream.ts index 45702ba8..c7ae1765 100644 --- a/openvidu-browser/src/OpenVidu/Stream.ts +++ b/openvidu-browser/src/OpenVidu/Stream.ts @@ -139,10 +139,10 @@ export class Stream extends EventDispatcher { * [[Filter.execMethod]] and remove it with [[Stream.removeFilter]]. Be aware that the client calling this methods must have the * necessary permissions: the token owned by the client must have been initialized with the appropriated `allowedFilters` array. */ - filter: Filter; + filter?: Filter; protected webRtcPeer: WebRtcPeer; - protected mediaStream: MediaStream; + protected mediaStream?: MediaStream; private webRtcStats: WebRtcStats; private isSubscribeToRemote = false; @@ -206,7 +206,7 @@ export class Stream extends EventDispatcher { /** * @hidden */ - localMediaStreamWhenSubscribedToRemote: MediaStream; + localMediaStreamWhenSubscribedToRemote?: MediaStream; /** @@ -265,7 +265,7 @@ export class Stream extends EventDispatcher { } this.ee.on('mediastream-updated', () => { - this.streamManager.updateMediaStream(this.mediaStream); + this.streamManager.updateMediaStream(this.mediaStream!); logger.debug('Video srcObject [' + this.mediaStream + '] updated in stream [' + this.streamId + ']'); }); } @@ -326,7 +326,7 @@ export class Stream extends EventDispatcher { } } else { logger.info('Filter successfully applied on Stream ' + this.streamId); - const oldValue: Filter = this.filter; + const oldValue: Filter = this.filter!; this.filter = new Filter(type, options); this.filter.stream = this; this.session.emitEvent('streamPropertyChanged', [new StreamPropertyChangedEvent(this.session, this, 'filter', this.filter, oldValue, 'applyFilter')]); @@ -359,10 +359,10 @@ export class Stream extends EventDispatcher { } } else { logger.info('Filter successfully removed from Stream ' + this.streamId); - const oldValue = this.filter; + const oldValue = this.filter!; delete this.filter; - this.session.emitEvent('streamPropertyChanged', [new StreamPropertyChangedEvent(this.session, this, 'filter', this.filter, oldValue, 'applyFilter')]); - this.streamManager.emitEvent('streamPropertyChanged', [new StreamPropertyChangedEvent(this.streamManager, this, 'filter', this.filter, oldValue, 'applyFilter')]); + this.session.emitEvent('streamPropertyChanged', [new StreamPropertyChangedEvent(this.session, this, 'filter', this.filter!, oldValue, 'applyFilter')]); + this.streamManager.emitEvent('streamPropertyChanged', [new StreamPropertyChangedEvent(this.streamManager, this, 'filter', this.filter!, oldValue, 'applyFilter')]); resolve(); } } @@ -385,7 +385,7 @@ export class Stream extends EventDispatcher { * @returns Native MediaStream Web API object */ getMediaStream(): MediaStream { - return this.mediaStream; + return this.mediaStream!; } /* Hidden methods */ @@ -1005,7 +1005,7 @@ export class Stream extends EventDispatcher { } private initHarkEvents(): void { - if (!!this.mediaStream.getAudioTracks()[0]) { + if (!!this.mediaStream!.getAudioTracks()[0]) { // Hark events can only be set if audio track is available if (this.streamManager.remote) { // publisherStartSpeaking/publisherStopSpeaking is only defined for remote streams diff --git a/openvidu-browser/src/OpenVidu/StreamManager.ts b/openvidu-browser/src/OpenVidu/StreamManager.ts index ae4dbc26..1318b07f 100644 --- a/openvidu-browser/src/OpenVidu/StreamManager.ts +++ b/openvidu-browser/src/OpenVidu/StreamManager.ts @@ -87,7 +87,7 @@ export class StreamManager extends EventDispatcher { /** * @hidden */ - firstVideoElement: StreamManagerVideo; + firstVideoElement?: StreamManagerVideo; /** * @hidden */ diff --git a/openvidu-browser/src/OpenViduInternal/Events/SessionDisconnectedEvent.ts b/openvidu-browser/src/OpenViduInternal/Events/SessionDisconnectedEvent.ts index 050c694e..c7eff22d 100644 --- a/openvidu-browser/src/OpenViduInternal/Events/SessionDisconnectedEvent.ts +++ b/openvidu-browser/src/OpenViduInternal/Events/SessionDisconnectedEvent.ts @@ -62,12 +62,12 @@ export class SessionDisconnectedEvent extends Event { // Dispose and delete all remote Connections for (const connectionId in session.remoteConnections) { if (!!session.remoteConnections[connectionId].stream) { - session.remoteConnections[connectionId].stream.disposeWebRtcPeer(); - session.remoteConnections[connectionId].stream.disposeMediaStream(); - if (session.remoteConnections[connectionId].stream.streamManager) { - session.remoteConnections[connectionId].stream.streamManager.removeAllVideos(); + session.remoteConnections[connectionId].stream!.disposeWebRtcPeer(); + session.remoteConnections[connectionId].stream!.disposeMediaStream(); + if (session.remoteConnections[connectionId].stream!.streamManager) { + session.remoteConnections[connectionId].stream!.streamManager.removeAllVideos(); } - delete session.remoteStreamsCreated[session.remoteConnections[connectionId].stream.streamId]; + delete session.remoteStreamsCreated[session.remoteConnections[connectionId].stream!.streamId]; session.remoteConnections[connectionId].dispose(); } delete session.remoteConnections[connectionId];