2015-07-28 18:22:11 +00:00
|
|
|
/* global config, $, APP, Strophe, callstats */
|
2015-10-04 21:13:28 +00:00
|
|
|
|
|
|
|
var Settings = require('../settings/Settings');
|
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;
|
|
|
|
|
2015-11-05 16:53:15 +00:00
|
|
|
// getUserMedia calls happen before CallStats init
|
|
|
|
// so if there are any getUserMedia errors, we store them in this array
|
|
|
|
// and send them to callstats on init
|
|
|
|
var pendingUserMediaErrors = [];
|
|
|
|
|
2015-06-26 12:32:40 +00:00
|
|
|
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;
|
|
|
|
|
2015-11-06 11:19:45 +00:00
|
|
|
this.userID = Settings.getCallStatsUserName();
|
2015-10-04 21:13:28 +00:00
|
|
|
|
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));
|
2015-11-05 16:53:15 +00:00
|
|
|
|
|
|
|
// notify callstats about getUserMedia failures if there were any
|
|
|
|
if (pendingUserMediaErrors.length) {
|
|
|
|
pendingUserMediaErrors.forEach(this.sendGetUserMediaFailed, this);
|
|
|
|
pendingUserMediaErrors.length = 0;
|
|
|
|
}
|
2015-06-26 12:32:40 +00:00
|
|
|
},
|
|
|
|
pcCallback: function (err, msg) {
|
2015-11-05 16:53:15 +00:00
|
|
|
if (!callStats) {
|
2015-06-26 12:32:40 +00:00
|
|
|
return;
|
2015-11-05 16:53:15 +00:00
|
|
|
}
|
2015-06-26 12:32:40 +00:00
|
|
|
console.log("Monitoring status: "+ err + " msg: " + msg);
|
|
|
|
callStats.sendFabricEvent(this.peerconnection,
|
|
|
|
callStats.fabricEvent.fabricSetup, this.confID);
|
|
|
|
},
|
|
|
|
sendMuteEvent: function (mute, type) {
|
2015-11-05 16:53:15 +00:00
|
|
|
if (!callStats) {
|
2015-06-26 12:32:40 +00:00
|
|
|
return;
|
2015-11-05 16:53:15 +00:00
|
|
|
}
|
2015-06-26 12:32:40 +00:00
|
|
|
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);
|
2015-11-05 17:27:26 +00:00
|
|
|
},
|
2015-11-05 16:53:15 +00:00
|
|
|
|
|
|
|
/**
|
2015-11-05 17:27:26 +00:00
|
|
|
* Sends the given feedback through CallStats.
|
|
|
|
*
|
|
|
|
* @param overallFeedback an integer between 1 and 5 indicating the
|
|
|
|
* user feedback
|
|
|
|
* @param detailedFeedback detailed feedback from the user. Not yet used
|
|
|
|
*/
|
|
|
|
sendFeedback: function(overallFeedback, detailedFeedback) {
|
|
|
|
if(!callStats) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var feedbackString = '{"userID":"' + this.userID + '"' +
|
|
|
|
', "overall":' + overallFeedback +
|
|
|
|
', "comment": "' + detailedFeedback + '"}';
|
2015-06-26 12:32:40 +00:00
|
|
|
|
2015-11-05 17:27:26 +00:00
|
|
|
var feedbackJSON = JSON.parse(feedbackString);
|
2015-11-06 17:47:40 +00:00
|
|
|
|
2015-11-05 17:27:26 +00:00
|
|
|
callStats.sendUserFeedback(
|
|
|
|
this.confID, feedbackJSON);
|
2015-11-05 16:53:15 +00:00
|
|
|
},
|
|
|
|
|
2015-11-05 18:30:30 +00:00
|
|
|
/**
|
|
|
|
* Notifies CallStats that getUserMedia failed.
|
|
|
|
*
|
|
|
|
* @param {Error} e error to send
|
|
|
|
*/
|
2015-11-05 16:53:15 +00:00
|
|
|
sendGetUserMediaFailed: function (e) {
|
|
|
|
if(!callStats) {
|
|
|
|
pendingUserMediaErrors.push(e);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
callStats.reportError(this.peerconnection, this.confID,
|
|
|
|
callStats.webRTCFunctions.getUserMedia, e);
|
|
|
|
},
|
|
|
|
|
2015-11-05 18:30:30 +00:00
|
|
|
/**
|
|
|
|
* Notifies CallStats that peer connection failed to create offer.
|
|
|
|
*
|
|
|
|
* @param {Error} e error to send
|
|
|
|
*/
|
2015-11-05 16:53:15 +00:00
|
|
|
sendCreateOfferFailed: function (e) {
|
|
|
|
if(!callStats) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
callStats.reportError(this.peerconnection, this.confID,
|
|
|
|
callStats.webRTCFunctions.createOffer, e);
|
|
|
|
},
|
|
|
|
|
2015-11-05 18:30:30 +00:00
|
|
|
/**
|
|
|
|
* Notifies CallStats that peer connection failed to create answer.
|
|
|
|
*
|
|
|
|
* @param {Error} e error to send
|
|
|
|
*/
|
2015-11-05 16:53:15 +00:00
|
|
|
sendCreateAnswerFailed: function (e) {
|
|
|
|
if(!callStats) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
callStats.reportError(this.peerconnection, this.confID,
|
|
|
|
callStats.webRTCFunctions.createAnswer, e);
|
|
|
|
},
|
|
|
|
|
2015-11-05 18:30:30 +00:00
|
|
|
/**
|
|
|
|
* Notifies CallStats that peer connection failed to set local description.
|
|
|
|
*
|
|
|
|
* @param {Error} e error to send
|
|
|
|
*/
|
2015-11-05 16:53:15 +00:00
|
|
|
sendSetLocalDescFailed: function (e) {
|
|
|
|
if(!callStats) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
callStats.reportError(this.peerconnection, this.confID,
|
|
|
|
callStats.webRTCFunctions.setLocalDescription, e);
|
|
|
|
},
|
|
|
|
|
2015-11-05 18:30:30 +00:00
|
|
|
/**
|
|
|
|
* Notifies CallStats that peer connection failed to set remote description.
|
|
|
|
*
|
|
|
|
* @param {Error} e error to send
|
|
|
|
*/
|
2015-11-05 16:53:15 +00:00
|
|
|
sendSetRemoteDescFailed: function (e) {
|
|
|
|
if(!callStats) {
|
|
|
|
return;
|
|
|
|
}
|
2015-11-05 18:30:30 +00:00
|
|
|
callStats.reportError(
|
|
|
|
this.peerconnection, this.confID,
|
|
|
|
callStats.webRTCFunctions.setRemoteDescription, e);
|
2015-11-05 16:53:15 +00:00
|
|
|
},
|
|
|
|
|
2015-11-05 18:30:30 +00:00
|
|
|
/**
|
|
|
|
* Notifies CallStats that peer connection failed to add ICE candidate.
|
|
|
|
*
|
|
|
|
* @param {Error} e error to send
|
|
|
|
*/
|
2015-11-05 16:53:15 +00:00
|
|
|
sendAddIceCandidateFailed: function (e) {
|
|
|
|
if(!callStats) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
callStats.reportError(this.peerconnection, this.confID,
|
|
|
|
callStats.webRTCFunctions.addIceCandidate, e);
|
2015-11-05 17:27:26 +00:00
|
|
|
}
|
2015-06-26 12:32:40 +00:00
|
|
|
};
|
2015-11-05 18:30:30 +00:00
|
|
|
module.exports = CallStats;
|