72 lines
1.8 KiB
JavaScript
72 lines
1.8 KiB
JavaScript
/* global require, APP */
|
|
/**
|
|
* Created by hristo on 8/4/14.
|
|
*/
|
|
var RTPStats = require("./RTPStatsCollector.js");
|
|
var EventEmitter = require("events");
|
|
var StreamEventTypes = require("../../service/RTC/StreamEventTypes.js");
|
|
var XMPPEvents = require("../../service/xmpp/XMPPEvents");
|
|
var RTCEvents = require("../../service/RTC/RTCEvents");
|
|
var StatisticsEvents = require("../../service/statistics/Events");
|
|
|
|
var eventEmitter = new EventEmitter();
|
|
|
|
var rtpStats = null;
|
|
|
|
function stopRemote() {
|
|
if (rtpStats) {
|
|
rtpStats.stop();
|
|
eventEmitter.emit(StatisticsEvents.STOP);
|
|
rtpStats = null;
|
|
}
|
|
}
|
|
|
|
function startRemoteStats (peerconnection) {
|
|
if (rtpStats) {
|
|
rtpStats.stop();
|
|
}
|
|
|
|
rtpStats = new RTPStats(peerconnection, 200, 2000, eventEmitter);
|
|
rtpStats.start();
|
|
}
|
|
|
|
function onDisposeConference(onUnload) {
|
|
stopRemote();
|
|
if (onUnload) {
|
|
eventEmitter.removeAllListeners();
|
|
}
|
|
}
|
|
|
|
export default {
|
|
/**
|
|
* Indicates that this audio level is for local jid.
|
|
* @type {string}
|
|
*/
|
|
LOCAL_JID: 'local',
|
|
|
|
addListener: function(type, listener) {
|
|
eventEmitter.on(type, listener);
|
|
},
|
|
removeListener: function (type, listener) {
|
|
eventEmitter.removeListener(type, listener);
|
|
},
|
|
stop: function () {
|
|
stopRemote();
|
|
if (eventEmitter) {
|
|
eventEmitter.removeAllListeners();
|
|
}
|
|
},
|
|
start: function () {
|
|
const xmpp = APP.conference._room.xmpp;
|
|
xmpp.addListener(
|
|
XMPPEvents.DISPOSE_CONFERENCE,
|
|
onDisposeConference
|
|
);
|
|
//FIXME: we may want to change CALL INCOMING event to
|
|
// onnegotiationneeded
|
|
xmpp.addListener(XMPPEvents.CALL_INCOMING, function (event) {
|
|
startRemoteStats(event.peerconnection);
|
|
});
|
|
}
|
|
};
|