浏览代码

Resolves some module dependancies by replaces them with events.

master
hristoterezov 10 年前
父节点
当前提交
af50bd5b94

+ 1
- 0
app.js 查看文件

15
 
15
 
16
     UI.start();
16
     UI.start();
17
     statistics.start();
17
     statistics.start();
18
+    connectionquality.init();
18
     
19
     
19
     // Set default desktop sharing method
20
     // Set default desktop sharing method
20
     desktopsharing.init();
21
     desktopsharing.init();

+ 7
- 6
index.html 查看文件

23
     <script src="service/RTC/StreamEventTypes.js?v=2"></script>
23
     <script src="service/RTC/StreamEventTypes.js?v=2"></script>
24
     <script src="service/RTC/MediaStreamTypes.js?v=1"></script>
24
     <script src="service/RTC/MediaStreamTypes.js?v=1"></script>
25
     <script src="service/xmpp/XMPPEvents.js?v=1"></script>
25
     <script src="service/xmpp/XMPPEvents.js?v=1"></script>
26
+    <script src="service/connectionquality/CQEvents.js?v=1"></script>
26
     <script src="service/UI/UIEvents.js?v=1"></script>
27
     <script src="service/UI/UIEvents.js?v=1"></script>
27
     <script src="service/desktopsharing/DesktopSharingEventTypes.js?v=1"></script>
28
     <script src="service/desktopsharing/DesktopSharingEventTypes.js?v=1"></script>
28
     <script src="libs/modules/simulcast.bundle.js?v=5"></script>
29
     <script src="libs/modules/simulcast.bundle.js?v=5"></script>
29
-    <script src="libs/modules/connectionquality.bundle.js?v=2"></script>
30
-    <script src="libs/modules/UI.bundle.js?v=11"></script>
31
-    <script src="libs/modules/statistics.bundle.js?v=4"></script>
32
-    <script src="libs/modules/RTC.bundle.js?v=6"></script>
30
+    <script src="libs/modules/connectionquality.bundle.js?v=3"></script>
31
+    <script src="libs/modules/UI.bundle.js?v=12"></script>
32
+    <script src="libs/modules/statistics.bundle.js?v=5"></script>
33
+    <script src="libs/modules/RTC.bundle.js?v=7"></script>
33
     <script src="libs/modules/desktopsharing.bundle.js?v=3"></script><!-- desktop sharing -->
34
     <script src="libs/modules/desktopsharing.bundle.js?v=3"></script><!-- desktop sharing -->
34
-    <script src="libs/modules/xmpp.bundle.js?v=6"></script>
35
-    <script src="libs/modules/keyboardshortcut.bundle.js?v=1"></script>
35
+    <script src="libs/modules/xmpp.bundle.js?v=7"></script>
36
+    <script src="libs/modules/keyboardshortcut.bundle.js?v=2"></script>
36
     <script src="app.js?v=30"></script><!-- application logic -->
37
     <script src="app.js?v=30"></script><!-- application logic -->
37
     <script src="libs/modules/API.bundle.js?v=2"></script>
38
     <script src="libs/modules/API.bundle.js?v=2"></script>
38
 
39
 

+ 12
- 0
libs/modules/API.bundle.js 查看文件

47
     participantLeft: false
47
     participantLeft: false
48
 };
48
 };
49
 
49
 
50
+var displayName = {};
51
+
50
 /**
52
 /**
51
  * Processes commands from external applicaiton.
53
  * Processes commands from external applicaiton.
52
  * @param message the object with the command
54
  * @param message the object with the command
145
     xmpp.addListener(XMPPEvents.MUC_LEFT, function (jid) {
147
     xmpp.addListener(XMPPEvents.MUC_LEFT, function (jid) {
146
         API.triggerEvent("participantLeft", {jid: jid});
148
         API.triggerEvent("participantLeft", {jid: jid});
147
     });
149
     });
150
+    xmpp.addListener(XMPPEvents.DISPLAY_NAME_CHANGED, function (jid, newDisplayName) {
151
+        name = displayName[jid];
152
+        if(!name || name != newDisplayName) {
153
+            API.triggerEvent("displayNameChange", {jid: jid, displayname: newDisplayName});
154
+            displayName[jid] = newDisplayName;
155
+        }
156
+    });
157
+    xmpp.addListener(XMPPEvents.SENDING_CHAT_MESSAGE, function (body) {
158
+        API.triggerEvent("outgoingMessage", {"message": body});
159
+    });
148
 }
160
 }
149
 
161
 
150
 var API = {
162
 var API = {

+ 4
- 4
libs/modules/RTC.bundle.js 查看文件

508
                     videoStream.videoType = changedStreams[i].type;
508
                     videoStream.videoType = changedStreams[i].type;
509
                 }
509
                 }
510
             }
510
             }
511
-        })
511
+        });
512
+        xmpp.addListener(XMPPEvents.CALL_INCOMING, function(event) {
513
+            DataChannels.bindDataChannelListener(event.peerconnection);
514
+        });
512
         this.rtcUtils = new RTCUtils(this);
515
         this.rtcUtils = new RTCUtils(this);
513
         this.rtcUtils.obtainAudioAndVideoPermissions();
516
         this.rtcUtils.obtainAudioAndVideoPermissions();
514
     },
517
     },
515
-    onConferenceCreated: function(event) {
516
-        DataChannels.bindDataChannelListener(event.peerconnection);
517
-    },
518
     muteRemoteVideoStream: function (jid, value) {
518
     muteRemoteVideoStream: function (jid, value) {
519
         var stream;
519
         var stream;
520
 
520
 

+ 6
- 27
libs/modules/UI.bundle.js 查看文件

150
     xmpp.addListener(XMPPEvents.PASSWORD_REQUIRED, onPasswordReqiured);
150
     xmpp.addListener(XMPPEvents.PASSWORD_REQUIRED, onPasswordReqiured);
151
     xmpp.addListener(XMPPEvents.CHAT_ERROR_RECEIVED, chatAddError);
151
     xmpp.addListener(XMPPEvents.CHAT_ERROR_RECEIVED, chatAddError);
152
     xmpp.addListener(XMPPEvents.ETHERPAD, initEtherpad);
152
     xmpp.addListener(XMPPEvents.ETHERPAD, initEtherpad);
153
+    connectionquality.addListener(CQEvents.LOCALSTATS_UPDATED,
154
+        VideoLayout.updateLocalConnectionStats);
155
+    connectionquality.addListener(CQEvents.REMOTESTATS_UPDATED,
156
+        VideoLayout.updateConnectionStats);
157
+    connectionquality.addListener(CQEvents.STOP,
158
+        VideoLayout.onStatsStop);
153
 }
159
 }
154
 
160
 
155
 function bindEvents()
161
 function bindEvents()
208
 
214
 
209
     $("#welcome_page").hide();
215
     $("#welcome_page").hide();
210
 
216
 
211
-    $('body').popover({ selector: '[data-toggle=popover]',
212
-        trigger: 'click hover',
213
-        content: function() {
214
-            return this.getAttribute("content") +
215
-                keyboardshortcut.getShortcut(this.getAttribute("shortcut"));
216
-        }
217
-    });
218
     VideoLayout.resizeLargeVideoContainer();
217
     VideoLayout.resizeLargeVideoContainer();
219
     $("#videospace").mousemove(function () {
218
     $("#videospace").mousemove(function () {
220
         return ToolbarToggler.showToolbar();
219
         return ToolbarToggler.showToolbar();
484
     VideoLayout.inputDisplayNameHandler(value);
483
     VideoLayout.inputDisplayNameHandler(value);
485
 };
484
 };
486
 
485
 
487
-UI.updateLocalConnectionStats = function(percent, stats)
488
-{
489
-    VideoLayout.updateLocalConnectionStats(percent, stats);
490
-};
491
-
492
-UI.updateConnectionStats = function(jid, percent, stats)
493
-{
494
-    VideoLayout.updateConnectionStats(jid, percent, stats);
495
-};
496
-
497
-UI.onStatsStop = function () {
498
-    VideoLayout.onStatsStop();
499
-};
500
 
486
 
501
 UI.getLargeVideoState = function()
487
 UI.getLargeVideoState = function()
502
 {
488
 {
6539
      */
6525
      */
6540
     my.onDisplayNameChanged =
6526
     my.onDisplayNameChanged =
6541
                     function (jid, displayName, status) {
6527
                     function (jid, displayName, status) {
6542
-        var name = null;
6543
         if (jid === 'localVideoContainer'
6528
         if (jid === 'localVideoContainer'
6544
             || jid === xmpp.myJid()) {
6529
             || jid === xmpp.myJid()) {
6545
-            name = NicknameHandler.getNickname();
6546
             setDisplayName('localVideoContainer',
6530
             setDisplayName('localVideoContainer',
6547
                            displayName);
6531
                            displayName);
6548
         } else {
6532
         } else {
6549
             VideoLayout.ensurePeerContainerExists(jid);
6533
             VideoLayout.ensurePeerContainerExists(jid);
6550
-            name = $('#participant_' + Strophe.getResourceFromJid(jid) + "_name").text();
6551
             setDisplayName(
6534
             setDisplayName(
6552
                 'participant_' + Strophe.getResourceFromJid(jid),
6535
                 'participant_' + Strophe.getResourceFromJid(jid),
6553
                 displayName,
6536
                 displayName,
6554
                 status);
6537
                 status);
6555
         }
6538
         }
6556
 
6539
 
6557
-        if(jid === 'localVideoContainer')
6558
-            jid = xmpp.myJid();
6559
-        if(!name || name != displayName)
6560
-            API.triggerEvent("displayNameChange",{jid: jid, displayname: displayName});
6561
     };
6540
     };
6562
 
6541
 
6563
     /**
6542
     /**

+ 322
- 5
libs/modules/connectionquality.bundle.js 查看文件

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){
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
  * local stats
6
  * local stats
4
  * @type {{}}
7
  * @type {{}}
69
 
72
 
70
 
73
 
71
 var ConnectionQuality = {
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
      * Updates the local statistics
83
      * Updates the local statistics
74
      * @param data new statistics
84
      * @param data new statistics
75
      */
85
      */
76
     updateLocalStats: function (data) {
86
     updateLocalStats: function (data) {
77
         stats = data;
87
         stats = data;
78
-        UI.updateLocalConnectionStats(100 - stats.packetLoss.total, stats);
88
+        eventEmitter.emit(CQEvents.LOCALSTATS_UPDATED, 100 - stats.packetLoss.total, stats);
79
         if (sendIntervalId == null) {
89
         if (sendIntervalId == null) {
80
             startSendingStats();
90
             startSendingStats();
81
         }
91
         }
88
      */
98
      */
89
     updateRemoteStats: function (jid, data) {
99
     updateRemoteStats: function (jid, data) {
90
         if (data == null || data.packetLoss_total == null) {
100
         if (data == null || data.packetLoss_total == null) {
91
-            UI.updateConnectionStats(jid, null, null);
101
+            eventEmitter.emit(CQEvents.REMOTESTATS_UPDATED, jid, null, null);
92
             return;
102
             return;
93
         }
103
         }
94
         remoteStats[jid] = parseMUCStats(data);
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
         clearInterval(sendIntervalId);
114
         clearInterval(sendIntervalId);
105
         sendIntervalId = null;
115
         sendIntervalId = null;
106
         //notify UI about stopping statistics gathering
116
         //notify UI about stopping statistics gathering
107
-        UI.onStatsStop();
117
+        eventEmitter.emit(CQEvents.STOP);
108
     },
118
     },
109
 
119
 
110
     /**
120
     /**
112
      */
122
      */
113
     getStats: function () {
123
     getStats: function () {
114
         return stats;
124
         return stats;
125
+    },
126
+    
127
+    addListener: function (type, listener) {
128
+        eventEmitter.on(type, listener);
115
     }
129
     }
116
 
130
 
117
 };
131
 };
118
 
132
 
119
 module.exports = ConnectionQuality;
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
 },{}]},{},[1])(1)
437
 },{}]},{},[1])(1)
121
 });
438
 });

+ 8
- 0
libs/modules/keyboardshortcut.bundle.js 查看文件

63
                 }
63
                 }
64
             }
64
             }
65
         };
65
         };
66
+        var self = this;
67
+        $('body').popover({ selector: '[data-toggle=popover]',
68
+            trigger: 'click hover',
69
+            content: function() {
70
+                return this.getAttribute("content") +
71
+                    self.getShortcut(this.getAttribute("shortcut"));
72
+            }
73
+        });
66
     },
74
     },
67
     /**
75
     /**
68
      *
76
      *

+ 3
- 6
libs/modules/statistics.bundle.js 查看文件

943
         stopRemote();
943
         stopRemote();
944
     },
944
     },
945
 
945
 
946
-    onConferenceCreated: function (event) {
947
-        startRemoteStats(event.peerconnection);
948
-    },
949
-
950
     start: function () {
946
     start: function () {
951
-        this.addConnectionStatsListener(connectionquality.updateLocalStats);
952
-        this.addRemoteStatsStopListener(connectionquality.stopSendingStats);
953
         RTC.addStreamListener(onStreamCreated,
947
         RTC.addStreamListener(onStreamCreated,
954
             StreamEventTypes.EVENT_TYPE_LOCAL_CREATED);
948
             StreamEventTypes.EVENT_TYPE_LOCAL_CREATED);
955
         xmpp.addListener(XMPPEvents.DISPOSE_CONFERENCE, onDisposeConference);
949
         xmpp.addListener(XMPPEvents.DISPOSE_CONFERENCE, onDisposeConference);
950
+        xmpp.addListener(XMPPEvents.CALL_INCOMING, function (event) {
951
+            startRemoteStats(event.peerconnection);
952
+        });
956
     }
953
     }
957
 
954
 
958
 };
955
 };

+ 6
- 9
libs/modules/xmpp.bundle.js 查看文件

3375
                 Strophe.forEachChild(stats[0], "stat", function (el) {
3375
                 Strophe.forEachChild(stats[0], "stat", function (el) {
3376
                     statsObj[el.getAttribute("name")] = el.getAttribute("value");
3376
                     statsObj[el.getAttribute("name")] = el.getAttribute("value");
3377
                 });
3377
                 });
3378
-                connectionquality.updateRemoteStats(from, statsObj);
3378
+                eventEmitter.emit(XMPPEvents.REMOTE_STATS, from, statsObj);
3379
             }
3379
             }
3380
 
3380
 
3381
             // Parse status.
3381
             // Parse status.
3524
                 msg.c('nick', {xmlns: 'http://jabber.org/protocol/nick'}).t(nickname).up().up();
3524
                 msg.c('nick', {xmlns: 'http://jabber.org/protocol/nick'}).t(nickname).up().up();
3525
             }
3525
             }
3526
             this.connection.send(msg);
3526
             this.connection.send(msg);
3527
-            API.triggerEvent("outgoingMessage", {"message": body});
3527
+            eventEmitter.emit(XMPPEvents.SENDING_CHAT_MESSAGE, body);
3528
         },
3528
         },
3529
         setSubject: function (subject) {
3529
         setSubject: function (subject) {
3530
             var msg = $msg({to: this.roomjid, type: 'groupchat'});
3530
             var msg = $msg({to: this.roomjid, type: 'groupchat'});
3824
 
3824
 
3825
             if (displayName && displayName.length > 0)
3825
             if (displayName && displayName.length > 0)
3826
             {
3826
             {
3827
-//                $(document).trigger('displaynamechanged',
3828
-//                    [jid, displayName]);
3829
                 eventEmitter.emit(XMPPEvents.DISPLAY_NAME_CHANGED, from, displayName);
3827
                 eventEmitter.emit(XMPPEvents.DISPLAY_NAME_CHANGED, from, displayName);
3830
             }
3828
             }
3831
 
3829
 
3847
 
3845
 
3848
 var JingleSession = require("./JingleSession");
3846
 var JingleSession = require("./JingleSession");
3849
 
3847
 
3850
-module.exports = function(XMPP)
3848
+module.exports = function(XMPP, eventEmitter)
3851
 {
3849
 {
3852
     function CallIncomingJingle(sid, connection) {
3850
     function CallIncomingJingle(sid, connection) {
3853
         var sess = connection.jingle.sessions[sid];
3851
         var sess = connection.jingle.sessions[sid];
3855
         // TODO: do we check activecall == null?
3853
         // TODO: do we check activecall == null?
3856
         connection.jingle.activecall = sess;
3854
         connection.jingle.activecall = sess;
3857
 
3855
 
3858
-        statistics.onConferenceCreated(sess);
3859
-        RTC.onConferenceCreated(sess);
3856
+        eventEmitter.emit(XMPPEvents.CALL_INCOMING, sess);
3860
 
3857
 
3861
         // TODO: check affiliation and/or role
3858
         // TODO: check affiliation and/or role
3862
         console.log('emuc data for', sess.peerjid, connection.emuc.members[sess.peerjid]);
3859
         console.log('emuc data for', sess.peerjid, connection.emuc.members[sess.peerjid]);
4497
 function initStrophePlugins()
4494
 function initStrophePlugins()
4498
 {
4495
 {
4499
     require("./strophe.emuc")(XMPP, eventEmitter);
4496
     require("./strophe.emuc")(XMPP, eventEmitter);
4500
-    require("./strophe.jingle")();
4497
+    require("./strophe.jingle")(XMPP, eventEmitter);
4501
     require("./strophe.moderate")(XMPP);
4498
     require("./strophe.moderate")(XMPP);
4502
     require("./strophe.util")();
4499
     require("./strophe.util")();
4503
     require("./strophe.rayo")();
4500
     require("./strophe.rayo")();
4509
         StreamEventTypes.EVENT_TYPE_LOCAL_CREATED);
4506
         StreamEventTypes.EVENT_TYPE_LOCAL_CREATED);
4510
     UI.addListener(UIEvents.NICKNAME_CHANGED, function (nickname) {
4507
     UI.addListener(UIEvents.NICKNAME_CHANGED, function (nickname) {
4511
         XMPP.addToPresence("displayName", nickname);
4508
         XMPP.addToPresence("displayName", nickname);
4512
-    })
4509
+    });
4513
 }
4510
 }
4514
 
4511
 
4515
 function setupEvents() {
4512
 function setupEvents() {

+ 12
- 0
modules/API/API.js 查看文件

46
     participantLeft: false
46
     participantLeft: false
47
 };
47
 };
48
 
48
 
49
+var displayName = {};
50
+
49
 /**
51
 /**
50
  * Processes commands from external applicaiton.
52
  * Processes commands from external applicaiton.
51
  * @param message the object with the command
53
  * @param message the object with the command
144
     xmpp.addListener(XMPPEvents.MUC_LEFT, function (jid) {
146
     xmpp.addListener(XMPPEvents.MUC_LEFT, function (jid) {
145
         API.triggerEvent("participantLeft", {jid: jid});
147
         API.triggerEvent("participantLeft", {jid: jid});
146
     });
148
     });
149
+    xmpp.addListener(XMPPEvents.DISPLAY_NAME_CHANGED, function (jid, newDisplayName) {
150
+        name = displayName[jid];
151
+        if(!name || name != newDisplayName) {
152
+            API.triggerEvent("displayNameChange", {jid: jid, displayname: newDisplayName});
153
+            displayName[jid] = newDisplayName;
154
+        }
155
+    });
156
+    xmpp.addListener(XMPPEvents.SENDING_CHAT_MESSAGE, function (body) {
157
+        API.triggerEvent("outgoingMessage", {"message": body});
158
+    });
147
 }
159
 }
148
 
160
 
149
 var API = {
161
 var API = {

+ 4
- 4
modules/RTC/RTC.js 查看文件

119
                     videoStream.videoType = changedStreams[i].type;
119
                     videoStream.videoType = changedStreams[i].type;
120
                 }
120
                 }
121
             }
121
             }
122
-        })
122
+        });
123
+        xmpp.addListener(XMPPEvents.CALL_INCOMING, function(event) {
124
+            DataChannels.bindDataChannelListener(event.peerconnection);
125
+        });
123
         this.rtcUtils = new RTCUtils(this);
126
         this.rtcUtils = new RTCUtils(this);
124
         this.rtcUtils.obtainAudioAndVideoPermissions();
127
         this.rtcUtils.obtainAudioAndVideoPermissions();
125
     },
128
     },
126
-    onConferenceCreated: function(event) {
127
-        DataChannels.bindDataChannelListener(event.peerconnection);
128
-    },
129
     muteRemoteVideoStream: function (jid, value) {
129
     muteRemoteVideoStream: function (jid, value) {
130
         var stream;
130
         var stream;
131
 
131
 

+ 6
- 20
modules/UI/UI.js 查看文件

149
     xmpp.addListener(XMPPEvents.PASSWORD_REQUIRED, onPasswordReqiured);
149
     xmpp.addListener(XMPPEvents.PASSWORD_REQUIRED, onPasswordReqiured);
150
     xmpp.addListener(XMPPEvents.CHAT_ERROR_RECEIVED, chatAddError);
150
     xmpp.addListener(XMPPEvents.CHAT_ERROR_RECEIVED, chatAddError);
151
     xmpp.addListener(XMPPEvents.ETHERPAD, initEtherpad);
151
     xmpp.addListener(XMPPEvents.ETHERPAD, initEtherpad);
152
+    connectionquality.addListener(CQEvents.LOCALSTATS_UPDATED,
153
+        VideoLayout.updateLocalConnectionStats);
154
+    connectionquality.addListener(CQEvents.REMOTESTATS_UPDATED,
155
+        VideoLayout.updateConnectionStats);
156
+    connectionquality.addListener(CQEvents.STOP,
157
+        VideoLayout.onStatsStop);
152
 }
158
 }
153
 
159
 
154
 function bindEvents()
160
 function bindEvents()
207
 
213
 
208
     $("#welcome_page").hide();
214
     $("#welcome_page").hide();
209
 
215
 
210
-    $('body').popover({ selector: '[data-toggle=popover]',
211
-        trigger: 'click hover',
212
-        content: function() {
213
-            return this.getAttribute("content") +
214
-                keyboardshortcut.getShortcut(this.getAttribute("shortcut"));
215
-        }
216
-    });
217
     VideoLayout.resizeLargeVideoContainer();
216
     VideoLayout.resizeLargeVideoContainer();
218
     $("#videospace").mousemove(function () {
217
     $("#videospace").mousemove(function () {
219
         return ToolbarToggler.showToolbar();
218
         return ToolbarToggler.showToolbar();
483
     VideoLayout.inputDisplayNameHandler(value);
482
     VideoLayout.inputDisplayNameHandler(value);
484
 };
483
 };
485
 
484
 
486
-UI.updateLocalConnectionStats = function(percent, stats)
487
-{
488
-    VideoLayout.updateLocalConnectionStats(percent, stats);
489
-};
490
-
491
-UI.updateConnectionStats = function(jid, percent, stats)
492
-{
493
-    VideoLayout.updateConnectionStats(jid, percent, stats);
494
-};
495
-
496
-UI.onStatsStop = function () {
497
-    VideoLayout.onStatsStop();
498
-};
499
 
485
 
500
 UI.getLargeVideoState = function()
486
 UI.getLargeVideoState = function()
501
 {
487
 {

+ 0
- 7
modules/UI/videolayout/VideoLayout.js 查看文件

1756
      */
1756
      */
1757
     my.onDisplayNameChanged =
1757
     my.onDisplayNameChanged =
1758
                     function (jid, displayName, status) {
1758
                     function (jid, displayName, status) {
1759
-        var name = null;
1760
         if (jid === 'localVideoContainer'
1759
         if (jid === 'localVideoContainer'
1761
             || jid === xmpp.myJid()) {
1760
             || jid === xmpp.myJid()) {
1762
-            name = NicknameHandler.getNickname();
1763
             setDisplayName('localVideoContainer',
1761
             setDisplayName('localVideoContainer',
1764
                            displayName);
1762
                            displayName);
1765
         } else {
1763
         } else {
1766
             VideoLayout.ensurePeerContainerExists(jid);
1764
             VideoLayout.ensurePeerContainerExists(jid);
1767
-            name = $('#participant_' + Strophe.getResourceFromJid(jid) + "_name").text();
1768
             setDisplayName(
1765
             setDisplayName(
1769
                 'participant_' + Strophe.getResourceFromJid(jid),
1766
                 'participant_' + Strophe.getResourceFromJid(jid),
1770
                 displayName,
1767
                 displayName,
1771
                 status);
1768
                 status);
1772
         }
1769
         }
1773
 
1770
 
1774
-        if(jid === 'localVideoContainer')
1775
-            jid = xmpp.myJid();
1776
-        if(!name || name != displayName)
1777
-            API.triggerEvent("displayNameChange",{jid: jid, displayname: displayName});
1778
     };
1771
     };
1779
 
1772
 
1780
     /**
1773
     /**

+ 19
- 5
modules/connectionquality/connectionquality.js 查看文件

1
+var EventEmitter = require("events");
2
+var eventEmitter = new EventEmitter();
3
+
1
 /**
4
 /**
2
  * local stats
5
  * local stats
3
  * @type {{}}
6
  * @type {{}}
68
 
71
 
69
 
72
 
70
 var ConnectionQuality = {
73
 var ConnectionQuality = {
74
+    init: function () {
75
+        xmpp.addListener(XMPPEvents.REMOTE_STATS, this.updateRemoteStats);
76
+        statistics.addConnectionStatsListener(this.updateLocalStats);
77
+        statistics.addRemoteStatsStopListener(this.stopSendingStats);
78
+
79
+    },
80
+
71
     /**
81
     /**
72
      * Updates the local statistics
82
      * Updates the local statistics
73
      * @param data new statistics
83
      * @param data new statistics
74
      */
84
      */
75
     updateLocalStats: function (data) {
85
     updateLocalStats: function (data) {
76
         stats = data;
86
         stats = data;
77
-        UI.updateLocalConnectionStats(100 - stats.packetLoss.total, stats);
87
+        eventEmitter.emit(CQEvents.LOCALSTATS_UPDATED, 100 - stats.packetLoss.total, stats);
78
         if (sendIntervalId == null) {
88
         if (sendIntervalId == null) {
79
             startSendingStats();
89
             startSendingStats();
80
         }
90
         }
87
      */
97
      */
88
     updateRemoteStats: function (jid, data) {
98
     updateRemoteStats: function (jid, data) {
89
         if (data == null || data.packetLoss_total == null) {
99
         if (data == null || data.packetLoss_total == null) {
90
-            UI.updateConnectionStats(jid, null, null);
100
+            eventEmitter.emit(CQEvents.REMOTESTATS_UPDATED, jid, null, null);
91
             return;
101
             return;
92
         }
102
         }
93
         remoteStats[jid] = parseMUCStats(data);
103
         remoteStats[jid] = parseMUCStats(data);
94
 
104
 
95
-        UI.updateConnectionStats(jid, 100 - data.packetLoss_total, remoteStats[jid]);
96
-
105
+        eventEmitter.emit(CQEvents.REMOTESTATS_UPDATED,
106
+            jid, 100 - data.packetLoss_total, remoteStats[jid]);
97
     },
107
     },
98
 
108
 
99
     /**
109
     /**
103
         clearInterval(sendIntervalId);
113
         clearInterval(sendIntervalId);
104
         sendIntervalId = null;
114
         sendIntervalId = null;
105
         //notify UI about stopping statistics gathering
115
         //notify UI about stopping statistics gathering
106
-        UI.onStatsStop();
116
+        eventEmitter.emit(CQEvents.STOP);
107
     },
117
     },
108
 
118
 
109
     /**
119
     /**
111
      */
121
      */
112
     getStats: function () {
122
     getStats: function () {
113
         return stats;
123
         return stats;
124
+    },
125
+    
126
+    addListener: function (type, listener) {
127
+        eventEmitter.on(type, listener);
114
     }
128
     }
115
 
129
 
116
 };
130
 };

+ 8
- 0
modules/keyboardshortcut/keyboardshortcut.js 查看文件

62
                 }
62
                 }
63
             }
63
             }
64
         };
64
         };
65
+        var self = this;
66
+        $('body').popover({ selector: '[data-toggle=popover]',
67
+            trigger: 'click hover',
68
+            content: function() {
69
+                return this.getAttribute("content") +
70
+                    self.getShortcut(this.getAttribute("shortcut"));
71
+            }
72
+        });
65
     },
73
     },
66
     /**
74
     /**
67
      *
75
      *

+ 3
- 6
modules/statistics/statistics.js 查看文件

121
         stopRemote();
121
         stopRemote();
122
     },
122
     },
123
 
123
 
124
-    onConferenceCreated: function (event) {
125
-        startRemoteStats(event.peerconnection);
126
-    },
127
-
128
     start: function () {
124
     start: function () {
129
-        this.addConnectionStatsListener(connectionquality.updateLocalStats);
130
-        this.addRemoteStatsStopListener(connectionquality.stopSendingStats);
131
         RTC.addStreamListener(onStreamCreated,
125
         RTC.addStreamListener(onStreamCreated,
132
             StreamEventTypes.EVENT_TYPE_LOCAL_CREATED);
126
             StreamEventTypes.EVENT_TYPE_LOCAL_CREATED);
133
         xmpp.addListener(XMPPEvents.DISPOSE_CONFERENCE, onDisposeConference);
127
         xmpp.addListener(XMPPEvents.DISPOSE_CONFERENCE, onDisposeConference);
128
+        xmpp.addListener(XMPPEvents.CALL_INCOMING, function (event) {
129
+            startRemoteStats(event.peerconnection);
130
+        });
134
     }
131
     }
135
 
132
 
136
 };
133
 };

+ 2
- 4
modules/xmpp/strophe.emuc.js 查看文件

149
                 Strophe.forEachChild(stats[0], "stat", function (el) {
149
                 Strophe.forEachChild(stats[0], "stat", function (el) {
150
                     statsObj[el.getAttribute("name")] = el.getAttribute("value");
150
                     statsObj[el.getAttribute("name")] = el.getAttribute("value");
151
                 });
151
                 });
152
-                connectionquality.updateRemoteStats(from, statsObj);
152
+                eventEmitter.emit(XMPPEvents.REMOTE_STATS, from, statsObj);
153
             }
153
             }
154
 
154
 
155
             // Parse status.
155
             // Parse status.
298
                 msg.c('nick', {xmlns: 'http://jabber.org/protocol/nick'}).t(nickname).up().up();
298
                 msg.c('nick', {xmlns: 'http://jabber.org/protocol/nick'}).t(nickname).up().up();
299
             }
299
             }
300
             this.connection.send(msg);
300
             this.connection.send(msg);
301
-            API.triggerEvent("outgoingMessage", {"message": body});
301
+            eventEmitter.emit(XMPPEvents.SENDING_CHAT_MESSAGE, body);
302
         },
302
         },
303
         setSubject: function (subject) {
303
         setSubject: function (subject) {
304
             var msg = $msg({to: this.roomjid, type: 'groupchat'});
304
             var msg = $msg({to: this.roomjid, type: 'groupchat'});
598
 
598
 
599
             if (displayName && displayName.length > 0)
599
             if (displayName && displayName.length > 0)
600
             {
600
             {
601
-//                $(document).trigger('displaynamechanged',
602
-//                    [jid, displayName]);
603
                 eventEmitter.emit(XMPPEvents.DISPLAY_NAME_CHANGED, from, displayName);
601
                 eventEmitter.emit(XMPPEvents.DISPLAY_NAME_CHANGED, from, displayName);
604
             }
602
             }
605
 
603
 

+ 2
- 3
modules/xmpp/strophe.jingle.js 查看文件

2
 
2
 
3
 var JingleSession = require("./JingleSession");
3
 var JingleSession = require("./JingleSession");
4
 
4
 
5
-module.exports = function(XMPP)
5
+module.exports = function(XMPP, eventEmitter)
6
 {
6
 {
7
     function CallIncomingJingle(sid, connection) {
7
     function CallIncomingJingle(sid, connection) {
8
         var sess = connection.jingle.sessions[sid];
8
         var sess = connection.jingle.sessions[sid];
10
         // TODO: do we check activecall == null?
10
         // TODO: do we check activecall == null?
11
         connection.jingle.activecall = sess;
11
         connection.jingle.activecall = sess;
12
 
12
 
13
-        statistics.onConferenceCreated(sess);
14
-        RTC.onConferenceCreated(sess);
13
+        eventEmitter.emit(XMPPEvents.CALL_INCOMING, sess);
15
 
14
 
16
         // TODO: check affiliation and/or role
15
         // TODO: check affiliation and/or role
17
         console.log('emuc data for', sess.peerjid, connection.emuc.members[sess.peerjid]);
16
         console.log('emuc data for', sess.peerjid, connection.emuc.members[sess.peerjid]);

+ 2
- 2
modules/xmpp/xmpp.js 查看文件

93
 function initStrophePlugins()
93
 function initStrophePlugins()
94
 {
94
 {
95
     require("./strophe.emuc")(XMPP, eventEmitter);
95
     require("./strophe.emuc")(XMPP, eventEmitter);
96
-    require("./strophe.jingle")();
96
+    require("./strophe.jingle")(XMPP, eventEmitter);
97
     require("./strophe.moderate")(XMPP);
97
     require("./strophe.moderate")(XMPP);
98
     require("./strophe.util")();
98
     require("./strophe.util")();
99
     require("./strophe.rayo")();
99
     require("./strophe.rayo")();
105
         StreamEventTypes.EVENT_TYPE_LOCAL_CREATED);
105
         StreamEventTypes.EVENT_TYPE_LOCAL_CREATED);
106
     UI.addListener(UIEvents.NICKNAME_CHANGED, function (nickname) {
106
     UI.addListener(UIEvents.NICKNAME_CHANGED, function (nickname) {
107
         XMPP.addToPresence("displayName", nickname);
107
         XMPP.addToPresence("displayName", nickname);
108
-    })
108
+    });
109
 }
109
 }
110
 
110
 
111
 function setupEvents() {
111
 function setupEvents() {

+ 5
- 0
service/connectionquality/CQEvents.js 查看文件

1
+var CQEvents = {
2
+    LOCALSTATS_UPDATED: "cq.localstats_updated",
3
+    REMOTESTATS_UPDATED: "cq.remotestats_updated",
4
+    STOP: "cq.stop"
5
+};

+ 1
- 0
service/xmpp/XMPPEvents.js 查看文件

17
     PRESENCE_STATUS: "xmpp.presence_status",
17
     PRESENCE_STATUS: "xmpp.presence_status",
18
     SUBJECT_CHANGED: "xmpp.subject_changed",
18
     SUBJECT_CHANGED: "xmpp.subject_changed",
19
     MESSAGE_RECEIVED: "xmpp.message_received",
19
     MESSAGE_RECEIVED: "xmpp.message_received",
20
+    SENDING_CHAT_MESSAGE: "xmpp.sending_chat_message",
20
     PASSWORD_REQUIRED: "xmpp.password_required",
21
     PASSWORD_REQUIRED: "xmpp.password_required",
21
     CHAT_ERROR_RECEIVED: "xmpp.chat_error_received",
22
     CHAT_ERROR_RECEIVED: "xmpp.chat_error_received",
22
     ETHERPAD: "xmpp.etherpad"
23
     ETHERPAD: "xmpp.etherpad"

正在加载...
取消
保存