Added madia flow out chnage event distribution in openvidu-browser

pull/20/head
Štěpán Škorpil 2017-12-22 14:38:29 +01:00
parent 511ffb0786
commit 4086744e15
7 changed files with 67 additions and 12 deletions

View File

@ -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)!!;
}

View File

@ -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;

View File

@ -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
*/

View File

@ -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);

View File

@ -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;

View File

@ -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;

View File

@ -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 () {