浏览代码

handle incoming messages

j8
isymchych 10 年前
父节点
当前提交
fc76aa5293
共有 2 个文件被更改,包括 33 次插入23 次删除
  1. 29
    19
      app.js
  2. 4
    4
      modules/UI/UI.js

+ 29
- 19
app.js 查看文件

1
-/* global $, JitsiMeetJS, config, Promise */
1
+/* global $, JitsiMeetJS, config, interfaceConfig */
2
 /* application specific logic */
2
 /* application specific logic */
3
 
3
 
4
 import "babel-polyfill";
4
 import "babel-polyfill";
90
         };
90
         };
91
 
91
 
92
         var listenForFailure = function (event) {
92
         var listenForFailure = function (event) {
93
-            handlers[event] = function () {
94
-                // convert arguments to array
95
-                var args = Array.prototype.slice.call(arguments);
96
-                args.unshift(event);
97
-                // [event, ...params]
98
-                console.error('CONNECTION FAILED:', args);
93
+            handlers[event] = function (...args) {
94
+                console.error(`CONNECTION FAILED: ${event}`, ...args);
99
 
95
 
100
                 unsubscribe();
96
                 unsubscribe();
101
-                reject(args);
97
+                reject([event, ...args]);
102
             };
98
             };
103
         };
99
         };
104
 
100
 
143
         }
139
         }
144
     });
140
     });
145
 
141
 
142
+    function getDisplayName(id) {
143
+        if (APP.conference.isLocalId(id)) {
144
+            return APP.settings.getDisplayName();
145
+        }
146
+
147
+        var user = users[id];
148
+        if (user && user.displayName) {
149
+            return user.displayName;
150
+        }
151
+    }
152
+
146
     room.on(ConferenceEvents.USER_JOINED, function (id) {
153
     room.on(ConferenceEvents.USER_JOINED, function (id) {
147
         users[id] = {
154
         users[id] = {
148
             displayName: undefined,
155
             displayName: undefined,
190
     });
197
     });
191
 
198
 
192
 
199
 
193
-    room.on(ConferenceEvents.CONNECTION_INTERRUPTED, function () {
194
-        APP.UI.markVideoInterrupted(true);
195
-    });
196
-    room.on(ConferenceEvents.CONNECTION_RESTORED, function () {
197
-        APP.UI.markVideoInterrupted(false);
198
-    });
200
+    if (!interfaceConfig.filmStripOnly) {
201
+        room.on(ConferenceEvents.CONNECTION_INTERRUPTED, function () {
202
+            APP.UI.markVideoInterrupted(true);
203
+        });
204
+        room.on(ConferenceEvents.CONNECTION_RESTORED, function () {
205
+            APP.UI.markVideoInterrupted(false);
206
+        });
199
 
207
 
208
+        APP.UI.addListener(UIEvents.MESSAGE_CREATED, function (message) {
209
+            room.sendTextMessage(message);
210
+        });
211
+        room.on(ConferenceEvents.MESSAGE_RECEIVED, function (userId, text) {
212
+            APP.UI.addMessage(userId, getDisplayName(userId), text, Date.now());
213
+        });
214
+    }
200
 
215
 
201
     APP.connectionquality.addListener(
216
     APP.connectionquality.addListener(
202
         CQEvents.LOCALSTATS_UPDATED,
217
         CQEvents.LOCALSTATS_UPDATED,
259
     });
274
     });
260
 
275
 
261
 
276
 
262
-    APP.UI.addListener(UIEvents.MESSAGE_CREATED, function (message) {
263
-        room.sendTextMessage(message);
264
-    });
265
-
266
-
267
     room.on(ConferenceErrors.PASSWORD_REQUIRED, function () {
277
     room.on(ConferenceErrors.PASSWORD_REQUIRED, function () {
268
         // FIXME handle
278
         // FIXME handle
269
     });
279
     });

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

308
     return Chat.chatSetSubject(text);
308
     return Chat.chatSetSubject(text);
309
 }
309
 }
310
 
310
 
311
-function updateChatConversation(from, displayName, message, stamp) {
312
-    return Chat.updateChatConversation(from, displayName, message, stamp);
313
-}
314
-
315
 function initEtherpad(name) {
311
 function initEtherpad(name) {
316
     Etherpad.init(name);
312
     Etherpad.init(name);
317
 }
313
 }
689
     }
685
     }
690
 };
686
 };
691
 
687
 
688
+UI.addMessage = function (from, displayName, message, stamp) {
689
+    Chat.updateChatConversation(from, displayName, message, stamp);
690
+};
691
+
692
 module.exports = UI;
692
 module.exports = UI;

正在加载...
取消
保存