handle incoming messages

This commit is contained in:
isymchych 2015-12-04 16:12:57 +02:00
parent ff6ec2ec6b
commit fc76aa5293
2 changed files with 33 additions and 23 deletions

36
app.js
View File

@ -1,4 +1,4 @@
/* global $, JitsiMeetJS, config, Promise */ /* global $, JitsiMeetJS, config, interfaceConfig */
/* application specific logic */ /* application specific logic */
import "babel-polyfill"; import "babel-polyfill";
@ -90,15 +90,11 @@ function connect() {
}; };
var listenForFailure = function (event) { var listenForFailure = function (event) {
handlers[event] = function () { handlers[event] = function (...args) {
// convert arguments to array console.error(`CONNECTION FAILED: ${event}`, ...args);
var args = Array.prototype.slice.call(arguments);
args.unshift(event);
// [event, ...params]
console.error('CONNECTION FAILED:', args);
unsubscribe(); 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) { room.on(ConferenceEvents.USER_JOINED, function (id) {
users[id] = { users[id] = {
displayName: undefined, displayName: undefined,
@ -190,6 +197,7 @@ function initConference(connection, roomName) {
}); });
if (!interfaceConfig.filmStripOnly) {
room.on(ConferenceEvents.CONNECTION_INTERRUPTED, function () { room.on(ConferenceEvents.CONNECTION_INTERRUPTED, function () {
APP.UI.markVideoInterrupted(true); APP.UI.markVideoInterrupted(true);
}); });
@ -197,6 +205,13 @@ function initConference(connection, roomName) {
APP.UI.markVideoInterrupted(false); 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( APP.connectionquality.addListener(
CQEvents.LOCALSTATS_UPDATED, 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 () { room.on(ConferenceErrors.PASSWORD_REQUIRED, function () {
// FIXME handle // FIXME handle
}); });

View File

@ -308,10 +308,6 @@ function chatSetSubject(text) {
return Chat.chatSetSubject(text); return Chat.chatSetSubject(text);
} }
function updateChatConversation(from, displayName, message, stamp) {
return Chat.updateChatConversation(from, displayName, message, stamp);
}
function initEtherpad(name) { function initEtherpad(name) {
Etherpad.init(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; module.exports = UI;