|
|
@@ -1,4 +1,7 @@
|
|
1
|
1
|
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var n;"undefined"!=typeof window?n=window:"undefined"!=typeof global?n=global:"undefined"!=typeof self&&(n=self),n.connectionquality=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
|
|
|
2
|
+var EventEmitter = require("events");
|
|
|
3
|
+var eventEmitter = new EventEmitter();
|
|
|
4
|
+
|
|
2
|
5
|
/**
|
|
3
|
6
|
* local stats
|
|
4
|
7
|
* @type {{}}
|
|
|
@@ -69,13 +72,20 @@ function parseMUCStats(stats) {
|
|
69
|
72
|
|
|
70
|
73
|
|
|
71
|
74
|
var ConnectionQuality = {
|
|
|
75
|
+ init: function () {
|
|
|
76
|
+ xmpp.addListener(XMPPEvents.REMOTE_STATS, this.updateRemoteStats);
|
|
|
77
|
+ statistics.addConnectionStatsListener(this.updateLocalStats);
|
|
|
78
|
+ statistics.addRemoteStatsStopListener(this.stopSendingStats);
|
|
|
79
|
+
|
|
|
80
|
+ },
|
|
|
81
|
+
|
|
72
|
82
|
/**
|
|
73
|
83
|
* Updates the local statistics
|
|
74
|
84
|
* @param data new statistics
|
|
75
|
85
|
*/
|
|
76
|
86
|
updateLocalStats: function (data) {
|
|
77
|
87
|
stats = data;
|
|
78
|
|
- UI.updateLocalConnectionStats(100 - stats.packetLoss.total, stats);
|
|
|
88
|
+ eventEmitter.emit(CQEvents.LOCALSTATS_UPDATED, 100 - stats.packetLoss.total, stats);
|
|
79
|
89
|
if (sendIntervalId == null) {
|
|
80
|
90
|
startSendingStats();
|
|
81
|
91
|
}
|
|
|
@@ -88,13 +98,13 @@ var ConnectionQuality = {
|
|
88
|
98
|
*/
|
|
89
|
99
|
updateRemoteStats: function (jid, data) {
|
|
90
|
100
|
if (data == null || data.packetLoss_total == null) {
|
|
91
|
|
- UI.updateConnectionStats(jid, null, null);
|
|
|
101
|
+ eventEmitter.emit(CQEvents.REMOTESTATS_UPDATED, jid, null, null);
|
|
92
|
102
|
return;
|
|
93
|
103
|
}
|
|
94
|
104
|
remoteStats[jid] = parseMUCStats(data);
|
|
95
|
105
|
|
|
96
|
|
- UI.updateConnectionStats(jid, 100 - data.packetLoss_total, remoteStats[jid]);
|
|
97
|
|
-
|
|
|
106
|
+ eventEmitter.emit(CQEvents.REMOTESTATS_UPDATED,
|
|
|
107
|
+ jid, 100 - data.packetLoss_total, remoteStats[jid]);
|
|
98
|
108
|
},
|
|
99
|
109
|
|
|
100
|
110
|
/**
|
|
|
@@ -104,7 +114,7 @@ var ConnectionQuality = {
|
|
104
|
114
|
clearInterval(sendIntervalId);
|
|
105
|
115
|
sendIntervalId = null;
|
|
106
|
116
|
//notify UI about stopping statistics gathering
|
|
107
|
|
- UI.onStatsStop();
|
|
|
117
|
+ eventEmitter.emit(CQEvents.STOP);
|
|
108
|
118
|
},
|
|
109
|
119
|
|
|
110
|
120
|
/**
|
|
|
@@ -112,10 +122,317 @@ var ConnectionQuality = {
|
|
112
|
122
|
*/
|
|
113
|
123
|
getStats: function () {
|
|
114
|
124
|
return stats;
|
|
|
125
|
+ },
|
|
|
126
|
+
|
|
|
127
|
+ addListener: function (type, listener) {
|
|
|
128
|
+ eventEmitter.on(type, listener);
|
|
115
|
129
|
}
|
|
116
|
130
|
|
|
117
|
131
|
};
|
|
118
|
132
|
|
|
119
|
133
|
module.exports = ConnectionQuality;
|
|
|
134
|
+},{"events":2}],2:[function(require,module,exports){
|
|
|
135
|
+// Copyright Joyent, Inc. and other Node contributors.
|
|
|
136
|
+//
|
|
|
137
|
+// Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
138
|
+// copy of this software and associated documentation files (the
|
|
|
139
|
+// "Software"), to deal in the Software without restriction, including
|
|
|
140
|
+// without limitation the rights to use, copy, modify, merge, publish,
|
|
|
141
|
+// distribute, sublicense, and/or sell copies of the Software, and to permit
|
|
|
142
|
+// persons to whom the Software is furnished to do so, subject to the
|
|
|
143
|
+// following conditions:
|
|
|
144
|
+//
|
|
|
145
|
+// The above copyright notice and this permission notice shall be included
|
|
|
146
|
+// in all copies or substantial portions of the Software.
|
|
|
147
|
+//
|
|
|
148
|
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
149
|
+// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
150
|
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
|
|
151
|
+// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
|
|
152
|
+// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
|
153
|
+// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
|
|
154
|
+// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
155
|
+
|
|
|
156
|
+function EventEmitter() {
|
|
|
157
|
+ this._events = this._events || {};
|
|
|
158
|
+ this._maxListeners = this._maxListeners || undefined;
|
|
|
159
|
+}
|
|
|
160
|
+module.exports = EventEmitter;
|
|
|
161
|
+
|
|
|
162
|
+// Backwards-compat with node 0.10.x
|
|
|
163
|
+EventEmitter.EventEmitter = EventEmitter;
|
|
|
164
|
+
|
|
|
165
|
+EventEmitter.prototype._events = undefined;
|
|
|
166
|
+EventEmitter.prototype._maxListeners = undefined;
|
|
|
167
|
+
|
|
|
168
|
+// By default EventEmitters will print a warning if more than 10 listeners are
|
|
|
169
|
+// added to it. This is a useful default which helps finding memory leaks.
|
|
|
170
|
+EventEmitter.defaultMaxListeners = 10;
|
|
|
171
|
+
|
|
|
172
|
+// Obviously not all Emitters should be limited to 10. This function allows
|
|
|
173
|
+// that to be increased. Set to zero for unlimited.
|
|
|
174
|
+EventEmitter.prototype.setMaxListeners = function(n) {
|
|
|
175
|
+ if (!isNumber(n) || n < 0 || isNaN(n))
|
|
|
176
|
+ throw TypeError('n must be a positive number');
|
|
|
177
|
+ this._maxListeners = n;
|
|
|
178
|
+ return this;
|
|
|
179
|
+};
|
|
|
180
|
+
|
|
|
181
|
+EventEmitter.prototype.emit = function(type) {
|
|
|
182
|
+ var er, handler, len, args, i, listeners;
|
|
|
183
|
+
|
|
|
184
|
+ if (!this._events)
|
|
|
185
|
+ this._events = {};
|
|
|
186
|
+
|
|
|
187
|
+ // If there is no 'error' event listener then throw.
|
|
|
188
|
+ if (type === 'error') {
|
|
|
189
|
+ if (!this._events.error ||
|
|
|
190
|
+ (isObject(this._events.error) && !this._events.error.length)) {
|
|
|
191
|
+ er = arguments[1];
|
|
|
192
|
+ if (er instanceof Error) {
|
|
|
193
|
+ throw er; // Unhandled 'error' event
|
|
|
194
|
+ }
|
|
|
195
|
+ throw TypeError('Uncaught, unspecified "error" event.');
|
|
|
196
|
+ }
|
|
|
197
|
+ }
|
|
|
198
|
+
|
|
|
199
|
+ handler = this._events[type];
|
|
|
200
|
+
|
|
|
201
|
+ if (isUndefined(handler))
|
|
|
202
|
+ return false;
|
|
|
203
|
+
|
|
|
204
|
+ if (isFunction(handler)) {
|
|
|
205
|
+ switch (arguments.length) {
|
|
|
206
|
+ // fast cases
|
|
|
207
|
+ case 1:
|
|
|
208
|
+ handler.call(this);
|
|
|
209
|
+ break;
|
|
|
210
|
+ case 2:
|
|
|
211
|
+ handler.call(this, arguments[1]);
|
|
|
212
|
+ break;
|
|
|
213
|
+ case 3:
|
|
|
214
|
+ handler.call(this, arguments[1], arguments[2]);
|
|
|
215
|
+ break;
|
|
|
216
|
+ // slower
|
|
|
217
|
+ default:
|
|
|
218
|
+ len = arguments.length;
|
|
|
219
|
+ args = new Array(len - 1);
|
|
|
220
|
+ for (i = 1; i < len; i++)
|
|
|
221
|
+ args[i - 1] = arguments[i];
|
|
|
222
|
+ handler.apply(this, args);
|
|
|
223
|
+ }
|
|
|
224
|
+ } else if (isObject(handler)) {
|
|
|
225
|
+ len = arguments.length;
|
|
|
226
|
+ args = new Array(len - 1);
|
|
|
227
|
+ for (i = 1; i < len; i++)
|
|
|
228
|
+ args[i - 1] = arguments[i];
|
|
|
229
|
+
|
|
|
230
|
+ listeners = handler.slice();
|
|
|
231
|
+ len = listeners.length;
|
|
|
232
|
+ for (i = 0; i < len; i++)
|
|
|
233
|
+ listeners[i].apply(this, args);
|
|
|
234
|
+ }
|
|
|
235
|
+
|
|
|
236
|
+ return true;
|
|
|
237
|
+};
|
|
|
238
|
+
|
|
|
239
|
+EventEmitter.prototype.addListener = function(type, listener) {
|
|
|
240
|
+ var m;
|
|
|
241
|
+
|
|
|
242
|
+ if (!isFunction(listener))
|
|
|
243
|
+ throw TypeError('listener must be a function');
|
|
|
244
|
+
|
|
|
245
|
+ if (!this._events)
|
|
|
246
|
+ this._events = {};
|
|
|
247
|
+
|
|
|
248
|
+ // To avoid recursion in the case that type === "newListener"! Before
|
|
|
249
|
+ // adding it to the listeners, first emit "newListener".
|
|
|
250
|
+ if (this._events.newListener)
|
|
|
251
|
+ this.emit('newListener', type,
|
|
|
252
|
+ isFunction(listener.listener) ?
|
|
|
253
|
+ listener.listener : listener);
|
|
|
254
|
+
|
|
|
255
|
+ if (!this._events[type])
|
|
|
256
|
+ // Optimize the case of one listener. Don't need the extra array object.
|
|
|
257
|
+ this._events[type] = listener;
|
|
|
258
|
+ else if (isObject(this._events[type]))
|
|
|
259
|
+ // If we've already got an array, just append.
|
|
|
260
|
+ this._events[type].push(listener);
|
|
|
261
|
+ else
|
|
|
262
|
+ // Adding the second element, need to change to array.
|
|
|
263
|
+ this._events[type] = [this._events[type], listener];
|
|
|
264
|
+
|
|
|
265
|
+ // Check for listener leak
|
|
|
266
|
+ if (isObject(this._events[type]) && !this._events[type].warned) {
|
|
|
267
|
+ var m;
|
|
|
268
|
+ if (!isUndefined(this._maxListeners)) {
|
|
|
269
|
+ m = this._maxListeners;
|
|
|
270
|
+ } else {
|
|
|
271
|
+ m = EventEmitter.defaultMaxListeners;
|
|
|
272
|
+ }
|
|
|
273
|
+
|
|
|
274
|
+ if (m && m > 0 && this._events[type].length > m) {
|
|
|
275
|
+ this._events[type].warned = true;
|
|
|
276
|
+ console.error('(node) warning: possible EventEmitter memory ' +
|
|
|
277
|
+ 'leak detected. %d listeners added. ' +
|
|
|
278
|
+ 'Use emitter.setMaxListeners() to increase limit.',
|
|
|
279
|
+ this._events[type].length);
|
|
|
280
|
+ if (typeof console.trace === 'function') {
|
|
|
281
|
+ // not supported in IE 10
|
|
|
282
|
+ console.trace();
|
|
|
283
|
+ }
|
|
|
284
|
+ }
|
|
|
285
|
+ }
|
|
|
286
|
+
|
|
|
287
|
+ return this;
|
|
|
288
|
+};
|
|
|
289
|
+
|
|
|
290
|
+EventEmitter.prototype.on = EventEmitter.prototype.addListener;
|
|
|
291
|
+
|
|
|
292
|
+EventEmitter.prototype.once = function(type, listener) {
|
|
|
293
|
+ if (!isFunction(listener))
|
|
|
294
|
+ throw TypeError('listener must be a function');
|
|
|
295
|
+
|
|
|
296
|
+ var fired = false;
|
|
|
297
|
+
|
|
|
298
|
+ function g() {
|
|
|
299
|
+ this.removeListener(type, g);
|
|
|
300
|
+
|
|
|
301
|
+ if (!fired) {
|
|
|
302
|
+ fired = true;
|
|
|
303
|
+ listener.apply(this, arguments);
|
|
|
304
|
+ }
|
|
|
305
|
+ }
|
|
|
306
|
+
|
|
|
307
|
+ g.listener = listener;
|
|
|
308
|
+ this.on(type, g);
|
|
|
309
|
+
|
|
|
310
|
+ return this;
|
|
|
311
|
+};
|
|
|
312
|
+
|
|
|
313
|
+// emits a 'removeListener' event iff the listener was removed
|
|
|
314
|
+EventEmitter.prototype.removeListener = function(type, listener) {
|
|
|
315
|
+ var list, position, length, i;
|
|
|
316
|
+
|
|
|
317
|
+ if (!isFunction(listener))
|
|
|
318
|
+ throw TypeError('listener must be a function');
|
|
|
319
|
+
|
|
|
320
|
+ if (!this._events || !this._events[type])
|
|
|
321
|
+ return this;
|
|
|
322
|
+
|
|
|
323
|
+ list = this._events[type];
|
|
|
324
|
+ length = list.length;
|
|
|
325
|
+ position = -1;
|
|
|
326
|
+
|
|
|
327
|
+ if (list === listener ||
|
|
|
328
|
+ (isFunction(list.listener) && list.listener === listener)) {
|
|
|
329
|
+ delete this._events[type];
|
|
|
330
|
+ if (this._events.removeListener)
|
|
|
331
|
+ this.emit('removeListener', type, listener);
|
|
|
332
|
+
|
|
|
333
|
+ } else if (isObject(list)) {
|
|
|
334
|
+ for (i = length; i-- > 0;) {
|
|
|
335
|
+ if (list[i] === listener ||
|
|
|
336
|
+ (list[i].listener && list[i].listener === listener)) {
|
|
|
337
|
+ position = i;
|
|
|
338
|
+ break;
|
|
|
339
|
+ }
|
|
|
340
|
+ }
|
|
|
341
|
+
|
|
|
342
|
+ if (position < 0)
|
|
|
343
|
+ return this;
|
|
|
344
|
+
|
|
|
345
|
+ if (list.length === 1) {
|
|
|
346
|
+ list.length = 0;
|
|
|
347
|
+ delete this._events[type];
|
|
|
348
|
+ } else {
|
|
|
349
|
+ list.splice(position, 1);
|
|
|
350
|
+ }
|
|
|
351
|
+
|
|
|
352
|
+ if (this._events.removeListener)
|
|
|
353
|
+ this.emit('removeListener', type, listener);
|
|
|
354
|
+ }
|
|
|
355
|
+
|
|
|
356
|
+ return this;
|
|
|
357
|
+};
|
|
|
358
|
+
|
|
|
359
|
+EventEmitter.prototype.removeAllListeners = function(type) {
|
|
|
360
|
+ var key, listeners;
|
|
|
361
|
+
|
|
|
362
|
+ if (!this._events)
|
|
|
363
|
+ return this;
|
|
|
364
|
+
|
|
|
365
|
+ // not listening for removeListener, no need to emit
|
|
|
366
|
+ if (!this._events.removeListener) {
|
|
|
367
|
+ if (arguments.length === 0)
|
|
|
368
|
+ this._events = {};
|
|
|
369
|
+ else if (this._events[type])
|
|
|
370
|
+ delete this._events[type];
|
|
|
371
|
+ return this;
|
|
|
372
|
+ }
|
|
|
373
|
+
|
|
|
374
|
+ // emit removeListener for all listeners on all events
|
|
|
375
|
+ if (arguments.length === 0) {
|
|
|
376
|
+ for (key in this._events) {
|
|
|
377
|
+ if (key === 'removeListener') continue;
|
|
|
378
|
+ this.removeAllListeners(key);
|
|
|
379
|
+ }
|
|
|
380
|
+ this.removeAllListeners('removeListener');
|
|
|
381
|
+ this._events = {};
|
|
|
382
|
+ return this;
|
|
|
383
|
+ }
|
|
|
384
|
+
|
|
|
385
|
+ listeners = this._events[type];
|
|
|
386
|
+
|
|
|
387
|
+ if (isFunction(listeners)) {
|
|
|
388
|
+ this.removeListener(type, listeners);
|
|
|
389
|
+ } else {
|
|
|
390
|
+ // LIFO order
|
|
|
391
|
+ while (listeners.length)
|
|
|
392
|
+ this.removeListener(type, listeners[listeners.length - 1]);
|
|
|
393
|
+ }
|
|
|
394
|
+ delete this._events[type];
|
|
|
395
|
+
|
|
|
396
|
+ return this;
|
|
|
397
|
+};
|
|
|
398
|
+
|
|
|
399
|
+EventEmitter.prototype.listeners = function(type) {
|
|
|
400
|
+ var ret;
|
|
|
401
|
+ if (!this._events || !this._events[type])
|
|
|
402
|
+ ret = [];
|
|
|
403
|
+ else if (isFunction(this._events[type]))
|
|
|
404
|
+ ret = [this._events[type]];
|
|
|
405
|
+ else
|
|
|
406
|
+ ret = this._events[type].slice();
|
|
|
407
|
+ return ret;
|
|
|
408
|
+};
|
|
|
409
|
+
|
|
|
410
|
+EventEmitter.listenerCount = function(emitter, type) {
|
|
|
411
|
+ var ret;
|
|
|
412
|
+ if (!emitter._events || !emitter._events[type])
|
|
|
413
|
+ ret = 0;
|
|
|
414
|
+ else if (isFunction(emitter._events[type]))
|
|
|
415
|
+ ret = 1;
|
|
|
416
|
+ else
|
|
|
417
|
+ ret = emitter._events[type].length;
|
|
|
418
|
+ return ret;
|
|
|
419
|
+};
|
|
|
420
|
+
|
|
|
421
|
+function isFunction(arg) {
|
|
|
422
|
+ return typeof arg === 'function';
|
|
|
423
|
+}
|
|
|
424
|
+
|
|
|
425
|
+function isNumber(arg) {
|
|
|
426
|
+ return typeof arg === 'number';
|
|
|
427
|
+}
|
|
|
428
|
+
|
|
|
429
|
+function isObject(arg) {
|
|
|
430
|
+ return typeof arg === 'object' && arg !== null;
|
|
|
431
|
+}
|
|
|
432
|
+
|
|
|
433
|
+function isUndefined(arg) {
|
|
|
434
|
+ return arg === void 0;
|
|
|
435
|
+}
|
|
|
436
|
+
|
|
120
|
437
|
},{}]},{},[1])(1)
|
|
121
|
438
|
});
|