Prevents breakages of our functionality caused by side-effect callstats.io API failures.
This commit is contained in:
parent
2b570a2251
commit
9b28e64e5d
|
@ -29,44 +29,70 @@ function initCallback (err, msg) {
|
||||||
|
|
||||||
var callStatsIntegrationEnabled = config.callStatsID && config.callStatsSecret;
|
var callStatsIntegrationEnabled = config.callStatsID && config.callStatsSecret;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a function which invokes f in a try/catch block, logs any exception
|
||||||
|
* to the console, and then swallows it.
|
||||||
|
*
|
||||||
|
* @param f the function to invoke in a try/catch block
|
||||||
|
* @return a function which invokes f in a try/catch block, logs any exception
|
||||||
|
* to the console, and then swallows it
|
||||||
|
*/
|
||||||
|
function _try_catch (f) {
|
||||||
|
return function () {
|
||||||
|
try {
|
||||||
|
f.apply(this, arguments);
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
var CallStats = {
|
var CallStats = {
|
||||||
init: function (jingleSession) {
|
init: _try_catch(function (jingleSession) {
|
||||||
if(!this.isEnabled() || callStats !== null) {
|
if(!this.isEnabled() || callStats !== null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
callStats = new callstats($, io, jsSHA);
|
try {
|
||||||
|
callStats = new callstats($, io, jsSHA);
|
||||||
|
|
||||||
this.session = jingleSession;
|
this.session = jingleSession;
|
||||||
this.peerconnection = jingleSession.peerconnection.peerconnection;
|
this.peerconnection = jingleSession.peerconnection.peerconnection;
|
||||||
|
this.userID = Settings.getCallStatsUserName();
|
||||||
|
|
||||||
this.userID = Settings.getCallStatsUserName();
|
var location = window.location;
|
||||||
|
|
||||||
var location = window.location;
|
this.confID = location.hostname + location.pathname;
|
||||||
this.confID = location.hostname + location.pathname;
|
|
||||||
|
|
||||||
//userID is generated or given by the origin server
|
callStats.initialize(
|
||||||
callStats.initialize(config.callStatsID,
|
config.callStatsID, config.callStatsSecret,
|
||||||
config.callStatsSecret,
|
this.userID /* generated or given by the origin server */,
|
||||||
this.userID,
|
initCallback);
|
||||||
initCallback);
|
|
||||||
|
|
||||||
var usage = callStats.fabricUsage.multiplex;
|
var usage = callStats.fabricUsage.multiplex;
|
||||||
|
|
||||||
callStats.addNewFabric(this.peerconnection,
|
callStats.addNewFabric(
|
||||||
Strophe.getResourceFromJid(jingleSession.peerjid),
|
this.peerconnection,
|
||||||
usage,
|
Strophe.getResourceFromJid(jingleSession.peerjid),
|
||||||
this.confID,
|
usage,
|
||||||
this.pcCallback.bind(this));
|
this.confID,
|
||||||
|
this.pcCallback.bind(this));
|
||||||
// notify callstats about failures if there were any
|
} catch (e) {
|
||||||
if (pendingErrors.length) {
|
// The callstats.io API failed to initialize (e.g. because its
|
||||||
|
// download failed to succeed in general or on time). Further
|
||||||
|
// attempts to utilize it cannot possibly succeed.
|
||||||
|
callStats = null;
|
||||||
|
console.error(e);
|
||||||
|
}
|
||||||
|
// Notify callstats about pre-init failures if there were any.
|
||||||
|
if (callStats && pendingErrors.length) {
|
||||||
pendingErrors.forEach(function (error) {
|
pendingErrors.forEach(function (error) {
|
||||||
this._reportError(error.type, error.error, error.pc);
|
this._reportError(error.type, error.error, error.pc);
|
||||||
}, this);
|
}, this);
|
||||||
pendingErrors.length = 0;
|
pendingErrors.length = 0;
|
||||||
}
|
}
|
||||||
},
|
}),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if the callstats integration is enabled, otherwise returns
|
* Returns true if the callstats integration is enabled, otherwise returns
|
||||||
* false.
|
* false.
|
||||||
|
@ -77,15 +103,17 @@ var CallStats = {
|
||||||
isEnabled: function() {
|
isEnabled: function() {
|
||||||
return callStatsIntegrationEnabled;
|
return callStatsIntegrationEnabled;
|
||||||
},
|
},
|
||||||
pcCallback: function (err, msg) {
|
|
||||||
|
pcCallback: _try_catch(function (err, msg) {
|
||||||
if (!callStats) {
|
if (!callStats) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
console.log("Monitoring status: "+ err + " msg: " + msg);
|
console.log("Monitoring status: "+ err + " msg: " + msg);
|
||||||
callStats.sendFabricEvent(this.peerconnection,
|
callStats.sendFabricEvent(this.peerconnection,
|
||||||
callStats.fabricEvent.fabricSetup, this.confID);
|
callStats.fabricEvent.fabricSetup, this.confID);
|
||||||
},
|
}),
|
||||||
sendMuteEvent: function (mute, type) {
|
|
||||||
|
sendMuteEvent: _try_catch(function (mute, type) {
|
||||||
if (!callStats) {
|
if (!callStats) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -99,30 +127,32 @@ var CallStats = {
|
||||||
callStats.fabricEvent.audioUnmute);
|
callStats.fabricEvent.audioUnmute);
|
||||||
}
|
}
|
||||||
callStats.sendFabricEvent(this.peerconnection, event, this.confID);
|
callStats.sendFabricEvent(this.peerconnection, event, this.confID);
|
||||||
},
|
}),
|
||||||
sendTerminateEvent: function () {
|
|
||||||
|
sendTerminateEvent: _try_catch(function () {
|
||||||
if(!callStats) {
|
if(!callStats) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
callStats.sendFabricEvent(this.peerconnection,
|
callStats.sendFabricEvent(this.peerconnection,
|
||||||
callStats.fabricEvent.fabricTerminated, this.confID);
|
callStats.fabricEvent.fabricTerminated, this.confID);
|
||||||
},
|
}),
|
||||||
sendSetupFailedEvent: function () {
|
|
||||||
|
sendSetupFailedEvent: _try_catch(function () {
|
||||||
if(!callStats) {
|
if(!callStats) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
callStats.sendFabricEvent(this.peerconnection,
|
callStats.sendFabricEvent(this.peerconnection,
|
||||||
callStats.fabricEvent.fabricSetupFailed, this.confID);
|
callStats.fabricEvent.fabricSetupFailed, this.confID);
|
||||||
},
|
}),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends the given feedback through CallStats.
|
* Sends the given feedback through CallStats.
|
||||||
*
|
*
|
||||||
* @param overallFeedback an integer between 1 and 5 indicating the
|
* @param overallFeedback an integer between 1 and 5 indicating the
|
||||||
* user feedback
|
* user feedback
|
||||||
* @param detailedFeedback detailed feedback from the user. Not yet used
|
* @param detailedFeedback detailed feedback from the user. Not yet used
|
||||||
*/
|
*/
|
||||||
sendFeedback: function(overallFeedback, detailedFeedback) {
|
sendFeedback: _try_catch(function(overallFeedback, detailedFeedback) {
|
||||||
if(!callStats) {
|
if(!callStats) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -132,9 +162,9 @@ var CallStats = {
|
||||||
|
|
||||||
var feedbackJSON = JSON.parse(feedbackString);
|
var feedbackJSON = JSON.parse(feedbackString);
|
||||||
|
|
||||||
callStats.sendUserFeedback(
|
callStats.sendUserFeedback(this.confID, feedbackJSON);
|
||||||
this.confID, feedbackJSON);
|
}),
|
||||||
},
|
|
||||||
/**
|
/**
|
||||||
* Reports an error to callstats.
|
* Reports an error to callstats.
|
||||||
*
|
*
|
||||||
|
@ -147,11 +177,7 @@ var CallStats = {
|
||||||
if (callStats) {
|
if (callStats) {
|
||||||
callStats.reportError(pc, this.confID, type, e);
|
callStats.reportError(pc, this.confID, type, e);
|
||||||
} else if (this.isEnabled()) {
|
} else if (this.isEnabled()) {
|
||||||
pendingErrors.push({
|
pendingErrors.push({ type: type, error: e, pc: pc });
|
||||||
type: type,
|
|
||||||
error: e,
|
|
||||||
pc: pc
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
// else just ignore it
|
// else just ignore it
|
||||||
},
|
},
|
||||||
|
@ -161,9 +187,9 @@ var CallStats = {
|
||||||
*
|
*
|
||||||
* @param {Error} e error to send
|
* @param {Error} e error to send
|
||||||
*/
|
*/
|
||||||
sendGetUserMediaFailed: function (e) {
|
sendGetUserMediaFailed: _try_catch(function (e) {
|
||||||
this._reportError(wrtcFuncNames.getUserMedia, e, null);
|
this._reportError(wrtcFuncNames.getUserMedia, e, null);
|
||||||
},
|
}),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Notifies CallStats that peer connection failed to create offer.
|
* Notifies CallStats that peer connection failed to create offer.
|
||||||
|
@ -171,9 +197,9 @@ var CallStats = {
|
||||||
* @param {Error} e error to send
|
* @param {Error} e error to send
|
||||||
* @param {RTCPeerConnection} pc connection on which failure occured.
|
* @param {RTCPeerConnection} pc connection on which failure occured.
|
||||||
*/
|
*/
|
||||||
sendCreateOfferFailed: function (e, pc) {
|
sendCreateOfferFailed: _try_catch(function (e, pc) {
|
||||||
this._reportError(wrtcFuncNames.createOffer, e, pc);
|
this._reportError(wrtcFuncNames.createOffer, e, pc);
|
||||||
},
|
}),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Notifies CallStats that peer connection failed to create answer.
|
* Notifies CallStats that peer connection failed to create answer.
|
||||||
|
@ -181,9 +207,9 @@ var CallStats = {
|
||||||
* @param {Error} e error to send
|
* @param {Error} e error to send
|
||||||
* @param {RTCPeerConnection} pc connection on which failure occured.
|
* @param {RTCPeerConnection} pc connection on which failure occured.
|
||||||
*/
|
*/
|
||||||
sendCreateAnswerFailed: function (e, pc) {
|
sendCreateAnswerFailed: _try_catch(function (e, pc) {
|
||||||
this._reportError(wrtcFuncNames.createAnswer, e, pc);
|
this._reportError(wrtcFuncNames.createAnswer, e, pc);
|
||||||
},
|
}),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Notifies CallStats that peer connection failed to set local description.
|
* Notifies CallStats that peer connection failed to set local description.
|
||||||
|
@ -191,9 +217,9 @@ var CallStats = {
|
||||||
* @param {Error} e error to send
|
* @param {Error} e error to send
|
||||||
* @param {RTCPeerConnection} pc connection on which failure occured.
|
* @param {RTCPeerConnection} pc connection on which failure occured.
|
||||||
*/
|
*/
|
||||||
sendSetLocalDescFailed: function (e, pc) {
|
sendSetLocalDescFailed: _try_catch(function (e, pc) {
|
||||||
this._reportError(wrtcFuncNames.setLocalDescription, e, pc);
|
this._reportError(wrtcFuncNames.setLocalDescription, e, pc);
|
||||||
},
|
}),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Notifies CallStats that peer connection failed to set remote description.
|
* Notifies CallStats that peer connection failed to set remote description.
|
||||||
|
@ -201,9 +227,9 @@ var CallStats = {
|
||||||
* @param {Error} e error to send
|
* @param {Error} e error to send
|
||||||
* @param {RTCPeerConnection} pc connection on which failure occured.
|
* @param {RTCPeerConnection} pc connection on which failure occured.
|
||||||
*/
|
*/
|
||||||
sendSetRemoteDescFailed: function (e, pc) {
|
sendSetRemoteDescFailed: _try_catch(function (e, pc) {
|
||||||
this._reportError(wrtcFuncNames.setRemoteDescription, e, pc);
|
this._reportError(wrtcFuncNames.setRemoteDescription, e, pc);
|
||||||
},
|
}),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Notifies CallStats that peer connection failed to add ICE candidate.
|
* Notifies CallStats that peer connection failed to add ICE candidate.
|
||||||
|
@ -211,8 +237,8 @@ var CallStats = {
|
||||||
* @param {Error} e error to send
|
* @param {Error} e error to send
|
||||||
* @param {RTCPeerConnection} pc connection on which failure occured.
|
* @param {RTCPeerConnection} pc connection on which failure occured.
|
||||||
*/
|
*/
|
||||||
sendAddIceCandidateFailed: function (e, pc) {
|
sendAddIceCandidateFailed: _try_catch(function (e, pc) {
|
||||||
this._reportError(wrtcFuncNames.addIceCandidate, e, pc);
|
this._reportError(wrtcFuncNames.addIceCandidate, e, pc);
|
||||||
}
|
})
|
||||||
};
|
};
|
||||||
module.exports = CallStats;
|
module.exports = CallStats;
|
||||||
|
|
Loading…
Reference in New Issue