Browse Source

Updates callstats to queue events if lib is not inited. Report such queued events only if the lib successfully initialize. Removes deprecated fabricSetup event.

master
damencho 9 years ago
parent
commit
cbe404dfd5
4 changed files with 167 additions and 51 deletions
  1. 83
    25
      lib-jitsi-meet.js
  2. 1
    1
      lib-jitsi-meet.min.js
  3. 81
    23
      modules/statistics/CallStats.js
  4. 2
    2
      modules/statistics/statistics.js

+ 83
- 25
lib-jitsi-meet.js View File

@@ -5519,10 +5519,50 @@ var wrtcFuncNames = {
5519 5519
     getUserMedia:         "getUserMedia"
5520 5520
 };
5521 5521
 
5522
+/**
5523
+ * @const
5524
+ * @see http://www.callstats.io/api/#enumeration-of-fabricevent
5525
+ */
5526
+var fabricEvent = {
5527
+    fabricSetupFailed:"fabricSetupFailed",
5528
+    fabricHold:"fabricHold",
5529
+    fabricResume:"fabricResume",
5530
+    audioMute:"audioMute",
5531
+    audioUnmute:"audioUnmute",
5532
+    videoPause:"videoPause",
5533
+    videoResume:"videoResume",
5534
+    fabricUsageEvent:"fabricUsageEvent",
5535
+    fabricStats:"fabricStats",
5536
+    fabricTerminated:"fabricTerminated"
5537
+};
5538
+
5522 5539
 var callStats = null;
5523 5540
 
5524 5541
 function initCallback (err, msg) {
5525 5542
     logger.log("CallStats Status: err=" + err + " msg=" + msg);
5543
+
5544
+    // there is no lib, nothing to report to
5545
+    if (err !== 'success')
5546
+        return;
5547
+
5548
+    // notify callstats about failures if there were any
5549
+    if (CallStats.reportsQueue.length) {
5550
+        CallStats.reportsQueue.forEach(function (report) {
5551
+            if (report.type === reportType.ERROR)
5552
+            {
5553
+                var error = report.data;
5554
+                CallStats._reportError.call(this, error.type, error.error,
5555
+                    error.pc);
5556
+            }
5557
+            else if (report.type === reportType.EVENT)
5558
+            {
5559
+                var data = report.data;
5560
+                callStats.sendFabricEvent(
5561
+                    this.peerconnection, data.event, this.confID);
5562
+            }
5563
+        }, this);
5564
+        CallStats.reportsQueue.length = 0;
5565
+    }
5526 5566
 }
5527 5567
 
5528 5568
 /**
@@ -5572,7 +5612,7 @@ var CallStats = _try_catch(function(jingleSession, Settings, options) {
5572 5612
         callStats.initialize(options.callStatsID,
5573 5613
             options.callStatsSecret,
5574 5614
             this.userID,
5575
-            initCallback);
5615
+            initCallback.bind(this));
5576 5616
 
5577 5617
         callStats.addNewFabric(this.peerconnection,
5578 5618
             Strophe.getResourceFromJid(jingleSession.peerjid),
@@ -5586,28 +5626,27 @@ var CallStats = _try_catch(function(jingleSession, Settings, options) {
5586 5626
         callStats = null;
5587 5627
         logger.error(e);
5588 5628
     }
5589
-    // notify callstats about failures if there were any
5590
-    if (CallStats.pendingErrors.length) {
5591
-        CallStats.pendingErrors.forEach(function (error) {
5592
-            CallStats._reportError.call(this, error.type, error.error,
5593
-                error.pc);
5594
-        }, this);
5595
-        CallStats.pendingErrors.length = 0;
5596
-    }
5597 5629
 });
5598 5630
 
5599
-// some errors may happen before CallStats init
5631
+// some errors/events may happen before CallStats init
5600 5632
 // in this case we accumulate them in this array
5601 5633
 // and send them to callstats on init
5602
-CallStats.pendingErrors = [];
5634
+CallStats.reportsQueue = [];
5635
+
5636
+/**
5637
+ * Type of pending reports, can be event or an error.
5638
+ * @type {{ERROR: string, EVENT: string}}
5639
+ */
5640
+var reportType = {
5641
+    ERROR: "error",
5642
+    EVENT: "event"
5643
+};
5603 5644
 
5604 5645
 CallStats.prototype.pcCallback = _try_catch(function (err, msg) {
5605 5646
     if (!callStats) {
5606 5647
         return;
5607 5648
     }
5608 5649
     logger.log("Monitoring status: "+ err + " msg: " + msg);
5609
-    callStats.sendFabricEvent(this.peerconnection,
5610
-        callStats.fabricEvent.fabricSetup, this.confID);
5611 5650
 });
5612 5651
 
5613 5652
 /**
@@ -5615,22 +5654,38 @@ CallStats.prototype.pcCallback = _try_catch(function (err, msg) {
5615 5654
  * @param mute {boolean} true for muted and false for not muted
5616 5655
  * @param type {String} "audio"/"video"
5617 5656
  */
5618
-CallStats.prototype.sendMuteEvent = _try_catch(function (mute, type) {
5619
-    if (!callStats) {
5620
-        return;
5621
-    }
5657
+CallStats.sendMuteEvent = _try_catch(function (mute, type, cs) {
5658
+
5622 5659
     var event = null;
5623 5660
     if (type === "video") {
5624
-        event = (mute? callStats.fabricEvent.videoPause :
5625
-            callStats.fabricEvent.videoResume);
5661
+        event = (mute? fabricEvent.videoPause : fabricEvent.videoResume);
5626 5662
     }
5627 5663
     else {
5628
-        event = (mute? callStats.fabricEvent.audioMute :
5629
-            callStats.fabricEvent.audioUnmute);
5664
+        event = (mute? fabricEvent.audioMute : fabricEvent.audioUnmute);
5630 5665
     }
5631
-    callStats.sendFabricEvent(this.peerconnection, event, this.confID);
5666
+
5667
+    CallStats._reportEvent.call(cs, event);
5632 5668
 });
5633 5669
 
5670
+/**
5671
+ * Reports an error to callstats.
5672
+ *
5673
+ * @param type the type of the error, which will be one of the wrtcFuncNames
5674
+ * @param e the error
5675
+ * @param pc the peerconnection
5676
+ * @private
5677
+ */
5678
+CallStats._reportEvent = function (event) {
5679
+    if (callStats) {
5680
+        callStats.sendFabricEvent(this.peerconnection, event, this.confID);
5681
+    } else {
5682
+        CallStats.reportsQueue.push({
5683
+                type: reportType.EVENT,
5684
+                data: {event: event}
5685
+            });
5686
+    }
5687
+};
5688
+
5634 5689
 /**
5635 5690
  * Notifies CallStats for connection setup errors
5636 5691
  */
@@ -5686,7 +5741,10 @@ CallStats._reportError = function (type, e, pc) {
5686 5741
     if (callStats) {
5687 5742
         callStats.reportError(pc, this.confID, type, e);
5688 5743
     } else {
5689
-        CallStats.pendingErrors.push({ type: type, error: e, pc: pc});
5744
+        CallStats.reportsQueue.push({
5745
+            type: reportType.ERROR,
5746
+            data: { type: type, error: e, pc: pc}
5747
+        });
5690 5748
     }
5691 5749
     // else just ignore it
5692 5750
 };
@@ -6801,8 +6859,8 @@ Statistics.prototype.sendSetupFailedEvent = function () {
6801 6859
  * @param type {String} "audio"/"video"
6802 6860
  */
6803 6861
 Statistics.prototype.sendMuteEvent = function (muted, type) {
6804
-    if(this.callStatsIntegrationEnabled && this.callstats)
6805
-        this.callstats.sendMuteEvent(muted, type);
6862
+    if(this.callStatsIntegrationEnabled)
6863
+        CallStats.sendMuteEvent(muted, type, this.callstats);
6806 6864
 }
6807 6865
 
6808 6866
 /**

+ 1
- 1
lib-jitsi-meet.min.js
File diff suppressed because it is too large
View File


+ 81
- 23
modules/statistics/CallStats.js View File

@@ -17,10 +17,50 @@ var wrtcFuncNames = {
17 17
     getUserMedia:         "getUserMedia"
18 18
 };
19 19
 
20
+/**
21
+ * @const
22
+ * @see http://www.callstats.io/api/#enumeration-of-fabricevent
23
+ */
24
+var fabricEvent = {
25
+    fabricSetupFailed:"fabricSetupFailed",
26
+    fabricHold:"fabricHold",
27
+    fabricResume:"fabricResume",
28
+    audioMute:"audioMute",
29
+    audioUnmute:"audioUnmute",
30
+    videoPause:"videoPause",
31
+    videoResume:"videoResume",
32
+    fabricUsageEvent:"fabricUsageEvent",
33
+    fabricStats:"fabricStats",
34
+    fabricTerminated:"fabricTerminated"
35
+};
36
+
20 37
 var callStats = null;
21 38
 
22 39
 function initCallback (err, msg) {
23 40
     logger.log("CallStats Status: err=" + err + " msg=" + msg);
41
+
42
+    // there is no lib, nothing to report to
43
+    if (err !== 'success')
44
+        return;
45
+
46
+    // notify callstats about failures if there were any
47
+    if (CallStats.reportsQueue.length) {
48
+        CallStats.reportsQueue.forEach(function (report) {
49
+            if (report.type === reportType.ERROR)
50
+            {
51
+                var error = report.data;
52
+                CallStats._reportError.call(this, error.type, error.error,
53
+                    error.pc);
54
+            }
55
+            else if (report.type === reportType.EVENT)
56
+            {
57
+                var data = report.data;
58
+                callStats.sendFabricEvent(
59
+                    this.peerconnection, data.event, this.confID);
60
+            }
61
+        }, this);
62
+        CallStats.reportsQueue.length = 0;
63
+    }
24 64
 }
25 65
 
26 66
 /**
@@ -70,7 +110,7 @@ var CallStats = _try_catch(function(jingleSession, Settings, options) {
70 110
         callStats.initialize(options.callStatsID,
71 111
             options.callStatsSecret,
72 112
             this.userID,
73
-            initCallback);
113
+            initCallback.bind(this));
74 114
 
75 115
         callStats.addNewFabric(this.peerconnection,
76 116
             Strophe.getResourceFromJid(jingleSession.peerjid),
@@ -84,28 +124,27 @@ var CallStats = _try_catch(function(jingleSession, Settings, options) {
84 124
         callStats = null;
85 125
         logger.error(e);
86 126
     }
87
-    // notify callstats about failures if there were any
88
-    if (CallStats.pendingErrors.length) {
89
-        CallStats.pendingErrors.forEach(function (error) {
90
-            CallStats._reportError.call(this, error.type, error.error,
91
-                error.pc);
92
-        }, this);
93
-        CallStats.pendingErrors.length = 0;
94
-    }
95 127
 });
96 128
 
97
-// some errors may happen before CallStats init
129
+// some errors/events may happen before CallStats init
98 130
 // in this case we accumulate them in this array
99 131
 // and send them to callstats on init
100
-CallStats.pendingErrors = [];
132
+CallStats.reportsQueue = [];
133
+
134
+/**
135
+ * Type of pending reports, can be event or an error.
136
+ * @type {{ERROR: string, EVENT: string}}
137
+ */
138
+var reportType = {
139
+    ERROR: "error",
140
+    EVENT: "event"
141
+};
101 142
 
102 143
 CallStats.prototype.pcCallback = _try_catch(function (err, msg) {
103 144
     if (!callStats) {
104 145
         return;
105 146
     }
106 147
     logger.log("Monitoring status: "+ err + " msg: " + msg);
107
-    callStats.sendFabricEvent(this.peerconnection,
108
-        callStats.fabricEvent.fabricSetup, this.confID);
109 148
 });
110 149
 
111 150
 /**
@@ -113,22 +152,38 @@ CallStats.prototype.pcCallback = _try_catch(function (err, msg) {
113 152
  * @param mute {boolean} true for muted and false for not muted
114 153
  * @param type {String} "audio"/"video"
115 154
  */
116
-CallStats.prototype.sendMuteEvent = _try_catch(function (mute, type) {
117
-    if (!callStats) {
118
-        return;
119
-    }
155
+CallStats.sendMuteEvent = _try_catch(function (mute, type, cs) {
156
+
120 157
     var event = null;
121 158
     if (type === "video") {
122
-        event = (mute? callStats.fabricEvent.videoPause :
123
-            callStats.fabricEvent.videoResume);
159
+        event = (mute? fabricEvent.videoPause : fabricEvent.videoResume);
124 160
     }
125 161
     else {
126
-        event = (mute? callStats.fabricEvent.audioMute :
127
-            callStats.fabricEvent.audioUnmute);
162
+        event = (mute? fabricEvent.audioMute : fabricEvent.audioUnmute);
128 163
     }
129
-    callStats.sendFabricEvent(this.peerconnection, event, this.confID);
164
+
165
+    CallStats._reportEvent.call(cs, event);
130 166
 });
131 167
 
168
+/**
169
+ * Reports an error to callstats.
170
+ *
171
+ * @param type the type of the error, which will be one of the wrtcFuncNames
172
+ * @param e the error
173
+ * @param pc the peerconnection
174
+ * @private
175
+ */
176
+CallStats._reportEvent = function (event) {
177
+    if (callStats) {
178
+        callStats.sendFabricEvent(this.peerconnection, event, this.confID);
179
+    } else {
180
+        CallStats.reportsQueue.push({
181
+                type: reportType.EVENT,
182
+                data: {event: event}
183
+            });
184
+    }
185
+};
186
+
132 187
 /**
133 188
  * Notifies CallStats for connection setup errors
134 189
  */
@@ -184,7 +239,10 @@ CallStats._reportError = function (type, e, pc) {
184 239
     if (callStats) {
185 240
         callStats.reportError(pc, this.confID, type, e);
186 241
     } else {
187
-        CallStats.pendingErrors.push({ type: type, error: e, pc: pc});
242
+        CallStats.reportsQueue.push({
243
+            type: reportType.ERROR,
244
+            data: { type: type, error: e, pc: pc}
245
+        });
188 246
     }
189 247
     // else just ignore it
190 248
 };

+ 2
- 2
modules/statistics/statistics.js View File

@@ -182,8 +182,8 @@ Statistics.prototype.sendSetupFailedEvent = function () {
182 182
  * @param type {String} "audio"/"video"
183 183
  */
184 184
 Statistics.prototype.sendMuteEvent = function (muted, type) {
185
-    if(this.callStatsIntegrationEnabled && this.callstats)
186
-        this.callstats.sendMuteEvent(muted, type);
185
+    if(this.callStatsIntegrationEnabled)
186
+        CallStats.sendMuteEvent(muted, type, this.callstats);
187 187
 }
188 188
 
189 189
 /**

Loading…
Cancel
Save