|
@@ -1,218 +0,0 @@
|
1
|
|
-/* global config, $, APP, Strophe, callstats */
|
2
|
|
-
|
3
|
|
-var Settings = require('../settings/Settings');
|
4
|
|
-var jsSHA = require('jssha');
|
5
|
|
-var io = require('socket.io-client');
|
6
|
|
-var callStats = null;
|
7
|
|
-
|
8
|
|
-/**
|
9
|
|
- * @const
|
10
|
|
- * @see http://www.callstats.io/api/#enumeration-of-wrtcfuncnames
|
11
|
|
- */
|
12
|
|
-var wrtcFuncNames = {
|
13
|
|
- createOffer: "createOffer",
|
14
|
|
- createAnswer: "createAnswer",
|
15
|
|
- setLocalDescription: "setLocalDescription",
|
16
|
|
- setRemoteDescription: "setRemoteDescription",
|
17
|
|
- addIceCandidate: "addIceCandidate",
|
18
|
|
- getUserMedia: "getUserMedia"
|
19
|
|
-};
|
20
|
|
-
|
21
|
|
-// some errors may happen before CallStats init
|
22
|
|
-// in this case we accumulate them in this array
|
23
|
|
-// and send them to callstats on init
|
24
|
|
-var pendingErrors = [];
|
25
|
|
-
|
26
|
|
-function initCallback (err, msg) {
|
27
|
|
- console.log("CallStats Status: err=" + err + " msg=" + msg);
|
28
|
|
-}
|
29
|
|
-
|
30
|
|
-var callStatsIntegrationEnabled = config.callStatsID && config.callStatsSecret;
|
31
|
|
-
|
32
|
|
-var CallStats = {
|
33
|
|
- init: function (jingleSession) {
|
34
|
|
- if(!callStatsIntegrationEnabled || callStats !== null) {
|
35
|
|
- return;
|
36
|
|
- }
|
37
|
|
-
|
38
|
|
- callStats = new callstats($, io, jsSHA);
|
39
|
|
-
|
40
|
|
- this.session = jingleSession;
|
41
|
|
- this.peerconnection = jingleSession.peerconnection.peerconnection;
|
42
|
|
-
|
43
|
|
- this.userID = Settings.getCallStatsUserName();
|
44
|
|
-
|
45
|
|
- var location = window.location;
|
46
|
|
- this.confID = location.hostname + location.pathname;
|
47
|
|
-
|
48
|
|
- //userID is generated or given by the origin server
|
49
|
|
- callStats.initialize(config.callStatsID,
|
50
|
|
- config.callStatsSecret,
|
51
|
|
- this.userID,
|
52
|
|
- initCallback);
|
53
|
|
-
|
54
|
|
- var usage = callStats.fabricUsage.multiplex;
|
55
|
|
-
|
56
|
|
- callStats.addNewFabric(this.peerconnection,
|
57
|
|
- Strophe.getResourceFromJid(jingleSession.peerjid),
|
58
|
|
- usage,
|
59
|
|
- this.confID,
|
60
|
|
- this.pcCallback.bind(this));
|
61
|
|
-
|
62
|
|
- // notify callstats about failures if there were any
|
63
|
|
- if (pendingErrors.length) {
|
64
|
|
- pendingErrors.forEach(function (error) {
|
65
|
|
- this._reportError(error.type, error.error, error.pc);
|
66
|
|
- }, this);
|
67
|
|
- pendingErrors.length = 0;
|
68
|
|
- }
|
69
|
|
- },
|
70
|
|
- /**
|
71
|
|
- * Returns true if the callstats integration is enabled, otherwise returns
|
72
|
|
- * false.
|
73
|
|
- *
|
74
|
|
- * @returns true if the callstats integration is enabled, otherwise returns
|
75
|
|
- * false.
|
76
|
|
- */
|
77
|
|
- isEnabled: function() {
|
78
|
|
- return callStatsIntegrationEnabled;
|
79
|
|
- },
|
80
|
|
- pcCallback: function (err, msg) {
|
81
|
|
- if (!callStats) {
|
82
|
|
- return;
|
83
|
|
- }
|
84
|
|
- console.log("Monitoring status: "+ err + " msg: " + msg);
|
85
|
|
- callStats.sendFabricEvent(this.peerconnection,
|
86
|
|
- callStats.fabricEvent.fabricSetup, this.confID);
|
87
|
|
- },
|
88
|
|
- sendMuteEvent: function (mute, type) {
|
89
|
|
- if (!callStats) {
|
90
|
|
- return;
|
91
|
|
- }
|
92
|
|
- var event = null;
|
93
|
|
- if (type === "video") {
|
94
|
|
- event = (mute? callStats.fabricEvent.videoPause :
|
95
|
|
- callStats.fabricEvent.videoResume);
|
96
|
|
- }
|
97
|
|
- else {
|
98
|
|
- event = (mute? callStats.fabricEvent.audioMute :
|
99
|
|
- callStats.fabricEvent.audioUnmute);
|
100
|
|
- }
|
101
|
|
- callStats.sendFabricEvent(this.peerconnection, event, this.confID);
|
102
|
|
- },
|
103
|
|
- sendTerminateEvent: function () {
|
104
|
|
- if(!callStats) {
|
105
|
|
- return;
|
106
|
|
- }
|
107
|
|
- callStats.sendFabricEvent(this.peerconnection,
|
108
|
|
- callStats.fabricEvent.fabricTerminated, this.confID);
|
109
|
|
- },
|
110
|
|
- sendSetupFailedEvent: function () {
|
111
|
|
- if(!callStats) {
|
112
|
|
- return;
|
113
|
|
- }
|
114
|
|
- callStats.sendFabricEvent(this.peerconnection,
|
115
|
|
- callStats.fabricEvent.fabricSetupFailed, this.confID);
|
116
|
|
- },
|
117
|
|
-
|
118
|
|
- /**
|
119
|
|
- * Sends the given feedback through CallStats.
|
120
|
|
- *
|
121
|
|
- * @param overallFeedback an integer between 1 and 5 indicating the
|
122
|
|
- * user feedback
|
123
|
|
- * @param detailedFeedback detailed feedback from the user. Not yet used
|
124
|
|
- */
|
125
|
|
- sendFeedback: function(overallFeedback, detailedFeedback) {
|
126
|
|
- if(!callStats) {
|
127
|
|
- return;
|
128
|
|
- }
|
129
|
|
- var feedbackString = '{"userID":"' + this.userID + '"' +
|
130
|
|
- ', "overall":' + overallFeedback +
|
131
|
|
- ', "comment": "' + detailedFeedback + '"}';
|
132
|
|
-
|
133
|
|
- var feedbackJSON = JSON.parse(feedbackString);
|
134
|
|
-
|
135
|
|
- callStats.sendUserFeedback(
|
136
|
|
- this.confID, feedbackJSON);
|
137
|
|
- },
|
138
|
|
- /**
|
139
|
|
- * Reports an error to callstats.
|
140
|
|
- *
|
141
|
|
- * @param type the type of the error, which will be one of the wrtcFuncNames
|
142
|
|
- * @param e the error
|
143
|
|
- * @param pc the peerconnection
|
144
|
|
- * @private
|
145
|
|
- */
|
146
|
|
- _reportError: function (type, e, pc) {
|
147
|
|
- if (callStats) {
|
148
|
|
- callStats.reportError(pc, this.confID, type, e);
|
149
|
|
- } else if (callStatsIntegrationEnabled) {
|
150
|
|
- pendingErrors.push({
|
151
|
|
- type: type,
|
152
|
|
- error: e,
|
153
|
|
- pc: pc
|
154
|
|
- });
|
155
|
|
- }
|
156
|
|
- // else just ignore it
|
157
|
|
- },
|
158
|
|
-
|
159
|
|
- /**
|
160
|
|
- * Notifies CallStats that getUserMedia failed.
|
161
|
|
- *
|
162
|
|
- * @param {Error} e error to send
|
163
|
|
- */
|
164
|
|
- sendGetUserMediaFailed: function (e) {
|
165
|
|
- this._reportError(wrtcFuncNames.getUserMedia, e, null);
|
166
|
|
- },
|
167
|
|
-
|
168
|
|
- /**
|
169
|
|
- * Notifies CallStats that peer connection failed to create offer.
|
170
|
|
- *
|
171
|
|
- * @param {Error} e error to send
|
172
|
|
- * @param {RTCPeerConnection} pc connection on which failure occured.
|
173
|
|
- */
|
174
|
|
- sendCreateOfferFailed: function (e, pc) {
|
175
|
|
- this._reportError(wrtcFuncNames.createOffer, e, pc);
|
176
|
|
- },
|
177
|
|
-
|
178
|
|
- /**
|
179
|
|
- * Notifies CallStats that peer connection failed to create answer.
|
180
|
|
- *
|
181
|
|
- * @param {Error} e error to send
|
182
|
|
- * @param {RTCPeerConnection} pc connection on which failure occured.
|
183
|
|
- */
|
184
|
|
- sendCreateAnswerFailed: function (e, pc) {
|
185
|
|
- this._reportError(wrtcFuncNames.createAnswer, e, pc);
|
186
|
|
- },
|
187
|
|
-
|
188
|
|
- /**
|
189
|
|
- * Notifies CallStats that peer connection failed to set local description.
|
190
|
|
- *
|
191
|
|
- * @param {Error} e error to send
|
192
|
|
- * @param {RTCPeerConnection} pc connection on which failure occured.
|
193
|
|
- */
|
194
|
|
- sendSetLocalDescFailed: function (e, pc) {
|
195
|
|
- this._reportError(wrtcFuncNames.setLocalDescription, e, pc);
|
196
|
|
- },
|
197
|
|
-
|
198
|
|
- /**
|
199
|
|
- * Notifies CallStats that peer connection failed to set remote description.
|
200
|
|
- *
|
201
|
|
- * @param {Error} e error to send
|
202
|
|
- * @param {RTCPeerConnection} pc connection on which failure occured.
|
203
|
|
- */
|
204
|
|
- sendSetRemoteDescFailed: function (e, pc) {
|
205
|
|
- this._reportError(wrtcFuncNames.setRemoteDescription, e, pc);
|
206
|
|
- },
|
207
|
|
-
|
208
|
|
- /**
|
209
|
|
- * Notifies CallStats that peer connection failed to add ICE candidate.
|
210
|
|
- *
|
211
|
|
- * @param {Error} e error to send
|
212
|
|
- * @param {RTCPeerConnection} pc connection on which failure occured.
|
213
|
|
- */
|
214
|
|
- sendAddIceCandidateFailed: function (e, pc) {
|
215
|
|
- this._reportError(wrtcFuncNames.addIceCandidate, e, pc);
|
216
|
|
- }
|
217
|
|
-};
|
218
|
|
-module.exports = CallStats;
|