2015-07-28 18:22:11 +00:00
|
|
|
/* global config, $, APP, Strophe, callstats */
|
2015-08-12 19:50:42 +00:00
|
|
|
var jsSHA = require('jssha');
|
|
|
|
var io = require('socket.io-client');
|
2015-06-26 12:32:40 +00:00
|
|
|
var callStats = null;
|
|
|
|
|
|
|
|
function initCallback (err, msg) {
|
|
|
|
console.log("Initializing Status: err="+err+" msg="+msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
var CallStats = {
|
|
|
|
init: function (jingleSession) {
|
|
|
|
|
|
|
|
if(!config.callStatsID || !config.callStatsSecret || callStats !== null)
|
|
|
|
return;
|
|
|
|
|
2015-08-12 19:50:42 +00:00
|
|
|
callStats = new callstats($, io, jsSHA);
|
2015-06-26 12:32:40 +00:00
|
|
|
|
|
|
|
this.session = jingleSession;
|
|
|
|
this.peerconnection = jingleSession.peerconnection.peerconnection;
|
|
|
|
|
|
|
|
this.userID = APP.xmpp.myResource();
|
|
|
|
|
2015-07-17 19:45:30 +00:00
|
|
|
var location = window.location;
|
2015-08-12 22:01:52 +00:00
|
|
|
this.confID = location.hostname + location.pathname;
|
2015-06-26 12:32:40 +00:00
|
|
|
|
|
|
|
//userID is generated or given by the origin server
|
|
|
|
callStats.initialize(config.callStatsID,
|
|
|
|
config.callStatsSecret,
|
|
|
|
this.userID,
|
|
|
|
initCallback);
|
|
|
|
|
2015-07-22 21:37:15 +00:00
|
|
|
var usage = callStats.fabricUsage.multiplex;
|
2015-06-26 12:32:40 +00:00
|
|
|
|
|
|
|
callStats.addNewFabric(this.peerconnection,
|
|
|
|
Strophe.getResourceFromJid(jingleSession.peerjid),
|
|
|
|
usage,
|
|
|
|
this.confID,
|
|
|
|
this.pcCallback.bind(this));
|
|
|
|
},
|
|
|
|
pcCallback: function (err, msg) {
|
2015-07-28 18:22:11 +00:00
|
|
|
if (!callStats)
|
2015-06-26 12:32:40 +00:00
|
|
|
return;
|
|
|
|
console.log("Monitoring status: "+ err + " msg: " + msg);
|
|
|
|
callStats.sendFabricEvent(this.peerconnection,
|
|
|
|
callStats.fabricEvent.fabricSetup, this.confID);
|
|
|
|
},
|
|
|
|
sendMuteEvent: function (mute, type) {
|
2015-07-28 18:22:11 +00:00
|
|
|
if (!callStats)
|
2015-06-26 12:32:40 +00:00
|
|
|
return;
|
|
|
|
var event = null;
|
2015-07-28 18:22:11 +00:00
|
|
|
if (type === "video") {
|
2015-06-26 12:32:40 +00:00
|
|
|
event = (mute? callStats.fabricEvent.videoPause :
|
|
|
|
callStats.fabricEvent.videoResume);
|
|
|
|
}
|
2015-07-28 18:22:11 +00:00
|
|
|
else {
|
2015-06-26 12:32:40 +00:00
|
|
|
event = (mute? callStats.fabricEvent.audioMute :
|
|
|
|
callStats.fabricEvent.audioUnmute);
|
|
|
|
}
|
|
|
|
callStats.sendFabricEvent(this.peerconnection, event, this.confID);
|
|
|
|
},
|
|
|
|
sendTerminateEvent: function () {
|
2015-07-28 18:22:11 +00:00
|
|
|
if(!callStats) {
|
2015-06-26 12:32:40 +00:00
|
|
|
return;
|
2015-07-28 18:22:11 +00:00
|
|
|
}
|
2015-06-26 12:32:40 +00:00
|
|
|
callStats.sendFabricEvent(this.peerconnection,
|
|
|
|
callStats.fabricEvent.fabricTerminated, this.confID);
|
|
|
|
},
|
|
|
|
sendSetupFailedEvent: function () {
|
2015-07-28 18:22:11 +00:00
|
|
|
if(!callStats) {
|
2015-06-26 12:32:40 +00:00
|
|
|
return;
|
2015-07-28 18:22:11 +00:00
|
|
|
}
|
2015-06-26 12:32:40 +00:00
|
|
|
callStats.sendFabricEvent(this.peerconnection,
|
|
|
|
callStats.fabricEvent.fabricSetupFailed, this.confID);
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
module.exports = CallStats;
|