From fc76aa52934043adf6c4509d1eb3f865950aff7b Mon Sep 17 00:00:00 2001 From: isymchych Date: Fri, 4 Dec 2015 16:12:57 +0200 Subject: [PATCH] handle incoming messages --- app.js | 48 +++++++++++++++++++++++++++++------------------- modules/UI/UI.js | 8 ++++---- 2 files changed, 33 insertions(+), 23 deletions(-) diff --git a/app.js b/app.js index 5b89a24db..1201d1700 100644 --- a/app.js +++ b/app.js @@ -1,4 +1,4 @@ -/* global $, JitsiMeetJS, config, Promise */ +/* global $, JitsiMeetJS, config, interfaceConfig */ /* application specific logic */ import "babel-polyfill"; @@ -90,15 +90,11 @@ function connect() { }; var listenForFailure = function (event) { - handlers[event] = function () { - // convert arguments to array - var args = Array.prototype.slice.call(arguments); - args.unshift(event); - // [event, ...params] - console.error('CONNECTION FAILED:', args); + handlers[event] = function (...args) { + console.error(`CONNECTION FAILED: ${event}`, ...args); unsubscribe(); - reject(args); + reject([event, ...args]); }; }; @@ -143,6 +139,17 @@ function initConference(connection, roomName) { } }); + function getDisplayName(id) { + if (APP.conference.isLocalId(id)) { + return APP.settings.getDisplayName(); + } + + var user = users[id]; + if (user && user.displayName) { + return user.displayName; + } + } + room.on(ConferenceEvents.USER_JOINED, function (id) { users[id] = { displayName: undefined, @@ -190,13 +197,21 @@ function initConference(connection, roomName) { }); - room.on(ConferenceEvents.CONNECTION_INTERRUPTED, function () { - APP.UI.markVideoInterrupted(true); - }); - room.on(ConferenceEvents.CONNECTION_RESTORED, function () { - APP.UI.markVideoInterrupted(false); - }); + if (!interfaceConfig.filmStripOnly) { + room.on(ConferenceEvents.CONNECTION_INTERRUPTED, function () { + APP.UI.markVideoInterrupted(true); + }); + room.on(ConferenceEvents.CONNECTION_RESTORED, function () { + APP.UI.markVideoInterrupted(false); + }); + APP.UI.addListener(UIEvents.MESSAGE_CREATED, function (message) { + room.sendTextMessage(message); + }); + room.on(ConferenceEvents.MESSAGE_RECEIVED, function (userId, text) { + APP.UI.addMessage(userId, getDisplayName(userId), text, Date.now()); + }); + } APP.connectionquality.addListener( CQEvents.LOCALSTATS_UPDATED, @@ -259,11 +274,6 @@ function initConference(connection, roomName) { }); - APP.UI.addListener(UIEvents.MESSAGE_CREATED, function (message) { - room.sendTextMessage(message); - }); - - room.on(ConferenceErrors.PASSWORD_REQUIRED, function () { // FIXME handle }); diff --git a/modules/UI/UI.js b/modules/UI/UI.js index 6146c5f0d..e95bf2225 100644 --- a/modules/UI/UI.js +++ b/modules/UI/UI.js @@ -308,10 +308,6 @@ function chatSetSubject(text) { return Chat.chatSetSubject(text); } -function updateChatConversation(from, displayName, message, stamp) { - return Chat.updateChatConversation(from, displayName, message, stamp); -} - function initEtherpad(name) { Etherpad.init(name); } @@ -689,4 +685,8 @@ UI.markVideoInterrupted = function (interrupted) { } }; +UI.addMessage = function (from, displayName, message, stamp) { + Chat.updateChatConversation(from, displayName, message, stamp); +}; + module.exports = UI;