diff --git a/openvidu-browser/ts/OpenVidu/Publisher.ts b/openvidu-browser/ts/OpenVidu/Publisher.ts index fd398232..8cc67062 100644 --- a/openvidu-browser/ts/OpenVidu/Publisher.ts +++ b/openvidu-browser/ts/OpenVidu/Publisher.ts @@ -20,6 +20,8 @@ export class Publisher { stream: Stream; session: Session; //Initialized by Session.publish(Publisher) isScreenRequested: boolean = false; + flowOutAudio: boolean = false; + flowOutVideo: boolean = false; constructor(stream: Stream, parentId: string, isScreenRequested: boolean) { this.stream = stream; @@ -34,6 +36,22 @@ export class Publisher { } }); + this.stream.addEventListener('media-flow-out-changed', (event) => { + let wasFlowing = this.flowOutAudio || this.flowOutVideo; + if(event.mediaType == "AUDIO"){ + this.flowOutAudio = event.newState == "FLOWING" + } + if(event.mediaType == "VIDEO"){ + this.flowOutVideo = event.newState == "FLOWING" + } + if(wasFlowing && !this.flowOutAudio && !this.flowOutVideo){ + this.ee.emitEvent('flowStopped'); + } + if (!wasFlowing && (this.flowOutAudio || this.flowOutVideo)) { + this.ee.emitEvent('flowStarted'); + } + }); + if (document.getElementById(parentId) != null) { this.element = document.getElementById(parentId)!!; } diff --git a/openvidu-browser/ts/OpenViduInternal/OpenViduInternal.ts b/openvidu-browser/ts/OpenViduInternal/OpenViduInternal.ts index a9b15b1b..99ef623b 100644 --- a/openvidu-browser/ts/OpenViduInternal/OpenViduInternal.ts +++ b/openvidu-browser/ts/OpenViduInternal/OpenViduInternal.ts @@ -193,7 +193,9 @@ export class OpenViduInternal { sendMessage: this.onNewMessage.bind(this), iceCandidate: this.iceCandidateEvent.bind(this), mediaError: this.onMediaError.bind(this), - custonNotification: this.customNotification.bind(this) + custonNotification: this.customNotification.bind(this), + mediaFlowInChange: this.onMediaFlowInChange.bind(this), + mediaFlowOutChange: this.onMediaFlowOutChange.bind(this), } }; @@ -294,6 +296,17 @@ export class OpenViduInternal { } } + private onMediaFlowOutChange(params) { + if (this.isRoomAvailable()) { + this.session.onMediaFlowOutChange(params); + } + } + + private onMediaFlowInChange(params) { + if (this.isRoomAvailable()) { + this.session.onMediaFlowInChange(params); + } + } setRpcParams(params: any) { this.rpcParams = params; diff --git a/openvidu-browser/ts/OpenViduInternal/SessionInternal.ts b/openvidu-browser/ts/OpenViduInternal/SessionInternal.ts index 4b366771..913c9500 100644 --- a/openvidu-browser/ts/OpenViduInternal/SessionInternal.ts +++ b/openvidu-browser/ts/OpenViduInternal/SessionInternal.ts @@ -460,6 +460,21 @@ export class SessionInternal { } } + onMediaFlowInChange(params) { + console.info("Media flow in change: " + JSON.stringify(params)); + } + + onMediaFlowOutChange(params) { + console.info("Media flow out change: " + JSON.stringify(params)); + for(let streamId in this.streams){ + this.streams[streamId].onMediaFlowOutChange({ + id: params.id, + mediaType: params.mediaType, + newState: params.newState + }); + } + } + /* * forced means the user was evicted, no need to send the 'leaveRoom' request */ diff --git a/openvidu-browser/ts/OpenViduInternal/Stream.ts b/openvidu-browser/ts/OpenViduInternal/Stream.ts index 331626e7..a1cca0ae 100644 --- a/openvidu-browser/ts/OpenViduInternal/Stream.ts +++ b/openvidu-browser/ts/OpenViduInternal/Stream.ts @@ -5,14 +5,15 @@ * * stream.hasAudio(); stream.hasVideo(); stream.hasData(); */ -import { Connection } from './Connection'; -import { SessionInternal } from './SessionInternal'; -import { OpenViduInternal, Callback } from './OpenViduInternal'; -import { OpenViduError, OpenViduErrorName } from './OpenViduError'; +import {Connection} from './Connection'; +import {SessionInternal} from './SessionInternal'; +import {OpenViduInternal, Callback} from './OpenViduInternal'; +import {OpenViduError, OpenViduErrorName} from './OpenViduError'; import EventEmitter = require('wolfy87-eventemitter'); import * as kurentoUtils from '../KurentoUtils/kurento-utils-js'; import * as adapter from 'webrtc-adapter'; + declare var navigator: any; declare var RTCSessionDescription: any; @@ -235,6 +236,13 @@ export class Stream { this.ee.removeAllListeners(eventName); } + onMediaFlowOutChange(event) { + if (event.id !== this.connection.connectionId) { + return; + } + this.ee.emit('media-flow-out-changed',event); + } + showSpinner(spinnerParentId: string) { let progress = document.createElement('div'); progress.id = 'progress-' + this.streamId; @@ -378,7 +386,8 @@ export class Stream { this.accessIsDenied = true; this.accessIsAllowed = false; let errorName: OpenViduErrorName; - let errorMessage = error.toString();; + let errorMessage = error.toString(); + ; if (!this.isScreenRequested) { errorName = this.sendVideo ? OpenViduErrorName.CAMERA_ACCESS_DENIED : OpenViduErrorName.MICROPHONE_ACCESS_DENIED; } else { @@ -437,7 +446,7 @@ export class Stream { doLoopback: this.displayMyRemote() || false, audioActive: this.sendAudio, videoActive: this.sendVideo, - typeOfVideo: ((this.sendVideo) ? ((this.isScreenRequested) ? 'SCREEN' :'CAMERA') : '') + typeOfVideo: ((this.sendVideo) ? ((this.isScreenRequested) ? 'SCREEN' : 'CAMERA') : '') }, (error, response) => { if (error) { console.error("Error on publishVideo: " + JSON.stringify(error)); @@ -578,7 +587,7 @@ export class Stream { if (this.wrStream.getAudioTracks()[0] != null) { - this.speechEvent = kurentoUtils.WebRtcPeer.hark(this.wrStream, { threshold: this.room.thresholdSpeaker }); + this.speechEvent = kurentoUtils.WebRtcPeer.hark(this.wrStream, {threshold: this.room.thresholdSpeaker}); this.speechEvent.on('speaking', () => { //this.room.addParticipantSpeaking(participantId); diff --git a/openvidu-node-client/lib/OpenVidu.js b/openvidu-node-client/lib/OpenVidu.js index 8a61fb6f..5a5cdf11 100644 --- a/openvidu-node-client/lib/OpenVidu.js +++ b/openvidu-node-client/lib/OpenVidu.js @@ -1,7 +1,7 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var Session_1 = require("./Session"); -var OpenVidu = (function () { +var OpenVidu = /** @class */ (function () { function OpenVidu(urlOpenViduServer, secret) { this.urlOpenViduServer = urlOpenViduServer; this.secret = secret; diff --git a/openvidu-node-client/lib/Session.js b/openvidu-node-client/lib/Session.js index 8631339d..3b1b0b68 100644 --- a/openvidu-node-client/lib/Session.js +++ b/openvidu-node-client/lib/Session.js @@ -2,7 +2,7 @@ Object.defineProperty(exports, "__esModule", { value: true }); var OpenViduRole_1 = require("./OpenViduRole"); var https = require('https'); -var Session = (function () { +var Session = /** @class */ (function () { function Session(urlOpenViduServer, secret) { this.urlOpenViduServer = urlOpenViduServer; this.secret = secret; diff --git a/openvidu-node-client/lib/TokenOptions.js b/openvidu-node-client/lib/TokenOptions.js index 0c5bc9d1..17b187c4 100644 --- a/openvidu-node-client/lib/TokenOptions.js +++ b/openvidu-node-client/lib/TokenOptions.js @@ -1,6 +1,6 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); -var TokenOptions = (function () { +var TokenOptions = /** @class */ (function () { function TokenOptions(data, role) { this.data = data; this.role = role; @@ -17,7 +17,7 @@ var TokenOptions = (function () { }()); exports.TokenOptions = TokenOptions; (function (TokenOptions) { - var Builder = (function () { + var Builder = /** @class */ (function () { function Builder() { } Builder.prototype.build = function () {