refactoring

This commit is contained in:
isymchych 2015-12-14 17:40:30 +02:00
parent 2af591f6d9
commit 4f91ac01fd
6 changed files with 57 additions and 76 deletions

View File

@ -14,11 +14,11 @@ import UIUtil from "./util/UIUtil";
import UIEvents from "../../service/UI/UIEvents"; import UIEvents from "../../service/UI/UIEvents";
import VideoLayout from "./videolayout/VideoLayout"; import VideoLayout from "./videolayout/VideoLayout";
import SettingsMenu from "./side_pannels/settings/SettingsMenu";
var Prezi = require("./prezi/Prezi"); var Prezi = require("./prezi/Prezi");
var Etherpad = require("./etherpad/Etherpad"); var Etherpad = require("./etherpad/Etherpad");
var EventEmitter = require("events"); var EventEmitter = require("events");
var SettingsMenu = require("./side_pannels/settings/SettingsMenu");
var Settings = require("./../settings/Settings"); var Settings = require("./../settings/Settings");
UI.messageHandler = require("./util/MessageHandler"); UI.messageHandler = require("./util/MessageHandler");
var messageHandler = UI.messageHandler; var messageHandler = UI.messageHandler;
@ -255,6 +255,7 @@ UI.start = function () {
registerListeners(); registerListeners();
VideoLayout.init(eventEmitter); VideoLayout.init(eventEmitter);
ContactList.init(eventEmitter);
bindEvents(); bindEvents();
setupPrezi(); setupPrezi();
@ -355,6 +356,8 @@ function initEtherpad(name) {
} }
UI.addUser = function (id, displayName) { UI.addUser = function (id, displayName) {
ContactList.addContact(id);
messageHandler.notify( messageHandler.notify(
displayName,'notify.somebody', 'connected', 'notify.connected' displayName,'notify.somebody', 'connected', 'notify.connected'
); );
@ -367,22 +370,21 @@ UI.addUser = function (id, displayName) {
UI.setUserAvatar(id, displayName); UI.setUserAvatar(id, displayName);
// Add Peer's container // Add Peer's container
VideoLayout.ensurePeerContainerExists(id); VideoLayout.addParticipantContainer(id);
}; };
UI.removeUser = function (id, displayName) { UI.removeUser = function (id, displayName) {
console.log('left.muc', id); ContactList.removeContact(id);
messageHandler.notify(displayName,'notify.somebody',
'disconnected', messageHandler.notify(
'notify.disconnected'); displayName,'notify.somebody', 'disconnected', 'notify.disconnected'
if (!config.startAudioMuted || );
config.startAudioMuted > APP.conference.membersCount) {
if (!config.startAudioMuted || config.startAudioMuted > APP.conference.membersCount) {
UIUtil.playSoundNotification('userLeft'); UIUtil.playSoundNotification('userLeft');
} }
ContactList.removeContact(id); VideoLayout.removeParticipantContainer(id);
VideoLayout.participantLeft(id);
}; };
function onMucPresenceStatus(jid, info) { function onMucPresenceStatus(jid, info) {

View File

@ -1,8 +1,9 @@
/* global $, APP */ /* global $, APP */
import Avatar from '../../avatar/Avatar'; import Avatar from '../../avatar/Avatar';
import UIEvents from '../../../../service/UI/UIEvents';
var numberOfContacts = 0; let numberOfContacts = 0;
var notificationInterval; let notificationInterval;
/** /**
* Updates the number of participants in the contact list button and sets * Updates the number of participants in the contact list button and sets
@ -30,7 +31,7 @@ function updateNumberOfParticipants(delta) {
* @return {object} the newly created avatar element * @return {object} the newly created avatar element
*/ */
function createAvatar(jid) { function createAvatar(jid) {
var avatar = document.createElement('img'); let avatar = document.createElement('img');
avatar.className = "icon-avatar avatar"; avatar.className = "icon-avatar avatar";
avatar.src = Avatar.getContactListUrl(jid); avatar.src = Avatar.getContactListUrl(jid);
@ -43,7 +44,7 @@ function createAvatar(jid) {
* @param displayName the display name to set * @param displayName the display name to set
*/ */
function createDisplayNameParagraph(key, displayName) { function createDisplayNameParagraph(key, displayName) {
var p = document.createElement('p'); let p = document.createElement('p');
if (displayName) { if (displayName) {
p.innerText = displayName; p.innerText = displayName;
} else if(key) { } else if(key) {
@ -76,39 +77,32 @@ function contactElExists (id) {
* Contact list. * Contact list.
*/ */
var ContactList = { var ContactList = {
init (emitter) {
this.emitter = emitter;
},
/** /**
* Indicates if the chat is currently visible. * Indicates if the chat is currently visible.
* *
* @return <tt>true</tt> if the chat is currently visible, <tt>false</tt> - * @return <tt>true</tt> if the chat is currently visible, <tt>false</tt> -
* otherwise * otherwise
*/ */
isVisible: function () { isVisible () {
return $('#contactlist').is(":visible"); return $('#contactlist').is(":visible");
}, },
/**
* Adds a contact for the given id if such doesn't yet exist.
*
*/
ensureAddContact: function (id) {
if (!contactElExists(id)) {
ContactList.addContact(id);
}
},
/** /**
* Adds a contact for the given id. * Adds a contact for the given id.
* *
*/ */
addContact: function (id) { addContact (id) {
var contactlist = $('#contacts'); let contactlist = $('#contacts');
var newContact = document.createElement('li'); let newContact = document.createElement('li');
newContact.id = id; newContact.id = id;
newContact.className = "clickable"; newContact.className = "clickable";
newContact.onclick = function (event) { newContact.onclick = (event) => {
if (event.currentTarget.className === "clickable") { if (event.currentTarget.className === "clickable") {
$(ContactList).trigger('contactclicked', [id]); this.emitter.emit(UIEvents.CONTACT_CLICKED, id);
} }
}; };
@ -127,7 +121,7 @@ var ContactList = {
* Removes a contact for the given id. * Removes a contact for the given id.
* *
*/ */
removeContact: function (id) { removeContact (id) {
let contact = getContactEl(id); let contact = getContactEl(id);
if (contact.length > 0) { if (contact.length > 0) {
@ -136,15 +130,14 @@ var ContactList = {
} }
}, },
setVisualNotification: function (show, stopGlowingIn) { setVisualNotification (show, stopGlowingIn) {
var glower = $('#contactListButton'); let glower = $('#contactListButton');
if (show && !notificationInterval) { if (show && !notificationInterval) {
notificationInterval = window.setInterval(function () { notificationInterval = window.setInterval(function () {
glower.toggleClass('active glowing'); glower.toggleClass('active glowing');
}, 800); }, 800);
} } else if (!show && notificationInterval) {
else if (!show && notificationInterval) {
stopGlowing(glower); stopGlowing(glower);
} }
if (stopGlowingIn) { if (stopGlowingIn) {
@ -154,28 +147,28 @@ var ContactList = {
} }
}, },
setClickable: function (id, isClickable) { setClickable (id, isClickable) {
getContactEl(id).toggleClass('clickable', isClickable); getContactEl(id).toggleClass('clickable', isClickable);
}, },
onDisplayNameChange: function (id, displayName) { onDisplayNameChange (id, displayName) {
if (id === 'localVideoContainer') { if (id === 'localVideoContainer') {
id = APP.conference.localId; id = APP.conference.localId;
} }
var contactName = $(`#contacts #${id}>p`); let contactName = $(`#contacts #${id}>p`);
if (displayName) { if (displayName) {
contactName.html(displayName); contactName.html(displayName);
} }
}, },
changeUserAvatar: function (id, contactListUrl) { changeUserAvatar (id, contactListUrl) {
// set the avatar in the contact list // set the avatar in the contact list
var contact = $(`#${id}>img`); let contact = $(`#${id}>img`);
if (contact.length > 0) { if (contact.length > 0) {
contact.attr('src', contactListUrl); contact.attr('src', contactListUrl);
} }
} }
}; };
module.exports = ContactList; export default ContactList;

View File

@ -21,7 +21,7 @@ function generateLanguagesSelectBox() {
} }
var SettingsMenu = { const SettingsMenu = {
init: function (emitter) { init: function (emitter) {
this.emitter = emitter; this.emitter = emitter;
@ -97,5 +97,4 @@ var SettingsMenu = {
} }
}; };
export default SettingsMenu;
module.exports = SettingsMenu;

View File

@ -365,7 +365,8 @@ ConnectionIndicator.prototype.updateResolution = function (resolution) {
*/ */
ConnectionIndicator.prototype.updatePopoverData = function () { ConnectionIndicator.prototype.updatePopoverData = function () {
this.popover.updateContent( this.popover.updateContent(
"<div class=\"connection_info\">" + this.generateText() + "</div>"); `<div class="connection_info">${this.generateText()}</div>`
);
APP.translation.translateElement($(".connection_info")); APP.translation.translateElement($(".connection_info"));
}; };

View File

@ -2,7 +2,6 @@
/* jshint -W101 */ /* jshint -W101 */
import AudioLevels from "../audio_levels/AudioLevels"; import AudioLevels from "../audio_levels/AudioLevels";
import ContactList from "../side_pannels/contactlist/ContactList";
import UIEvents from "../../../service/UI/UIEvents"; import UIEvents from "../../../service/UI/UIEvents";
import UIUtil from "../util/UIUtil"; import UIUtil from "../util/UIUtil";
@ -36,19 +35,15 @@ var focusedVideoResourceJid = null;
/** /**
* On contact list item clicked. * On contact list item clicked.
*/ */
$(ContactList).bind('contactclicked', function(event, id) { function onContactClicked (id) {
if (!id) {
return;
}
if (APP.conference.isLocalId(id)) { if (APP.conference.isLocalId(id)) {
$("#localVideoContainer").click(); $("#localVideoContainer").click();
return; return;
} }
var remoteVideo = remoteVideos[id]; let remoteVideo = remoteVideos[id];
if (remoteVideo && remoteVideo.selectVideoElement().length) { if (remoteVideo && remoteVideo.selectVideoElement().length) {
var videoThumb = remoteVideo.selectVideoElement()[0]; let videoThumb = remoteVideo.selectVideoElement()[0];
// It is not always the case that a videoThumb exists (if there is // It is not always the case that a videoThumb exists (if there is
// no actual video). // no actual video).
if (RTC.getVideoSrc(videoThumb)) { if (RTC.getVideoSrc(videoThumb)) {
@ -72,7 +67,7 @@ $(ContactList).bind('contactclicked', function(event, id) {
eventEmitter.emit(UIEvents.PINNED_ENDPOINT, id); eventEmitter.emit(UIEvents.PINNED_ENDPOINT, id);
} }
} }
}); }
/** /**
* Returns the corresponding resource id to the given peer container * Returns the corresponding resource id to the given peer container
@ -106,6 +101,7 @@ var VideoLayout = {
VideoLayout.resizeLargeVideoContainer(); VideoLayout.resizeLargeVideoContainer();
emitter.addListener(UIEvents.CONTACT_CLICKED, onContactClicked);
}, },
isInLastN (resource) { isInLastN (resource) {
@ -242,7 +238,6 @@ var VideoLayout = {
onRemoteStreamAdded (stream) { onRemoteStreamAdded (stream) {
let id = stream.getParticipantId(); let id = stream.getParticipantId();
VideoLayout.ensurePeerContainerExists(id);
remoteVideos[id].addRemoteStreamElement(stream); remoteVideos[id].addRemoteStreamElement(stream);
}, },
@ -340,13 +335,7 @@ var VideoLayout = {
* @return Returns <tt>true</tt> if the peer container exists, * @return Returns <tt>true</tt> if the peer container exists,
* <tt>false</tt> - otherwise * <tt>false</tt> - otherwise
*/ */
ensurePeerContainerExists (id) { addParticipantContainer (id) {
ContactList.ensureAddContact(id);
if (remoteVideos[id]) {
return;
}
let remoteVideo = new RemoteVideo(id, VideoLayout, eventEmitter); let remoteVideo = new RemoteVideo(id, VideoLayout, eventEmitter);
remoteVideos[id] = remoteVideo; remoteVideos[id] = remoteVideo;
@ -534,7 +523,6 @@ var VideoLayout = {
if (resourceJid === APP.xmpp.myResource()) { if (resourceJid === APP.xmpp.myResource()) {
localVideoThumbnail.showAudioIndicator(isMuted); localVideoThumbnail.showAudioIndicator(isMuted);
} else { } else {
VideoLayout.ensurePeerContainerExists(jid);
remoteVideos[resourceJid].showAudioIndicator(isMuted); remoteVideos[resourceJid].showAudioIndicator(isMuted);
if (APP.xmpp.isModerator()) { if (APP.xmpp.isModerator()) {
remoteVideos[resourceJid].updateRemoteVideoMenu(isMuted); remoteVideos[resourceJid].updateRemoteVideoMenu(isMuted);
@ -555,7 +543,6 @@ var VideoLayout = {
} else { } else {
var resource = Strophe.getResourceFromJid(jid); var resource = Strophe.getResourceFromJid(jid);
VideoLayout.ensurePeerContainerExists(jid);
var remoteVideo = remoteVideos[resource]; var remoteVideo = remoteVideos[resource];
remoteVideo.showVideoIndicator(value); remoteVideo.showVideoIndicator(value);
@ -575,7 +562,6 @@ var VideoLayout = {
APP.conference.isLocalId(id)) { APP.conference.isLocalId(id)) {
localVideoThumbnail.setDisplayName(displayName); localVideoThumbnail.setDisplayName(displayName);
} else { } else {
VideoLayout.ensurePeerContainerExists(id);
remoteVideos[id].setDisplayName(displayName, status); remoteVideos[id].setDisplayName(displayName, status);
} }
}, },
@ -801,23 +787,22 @@ var VideoLayout = {
/** /**
* Updates remote stats. * Updates remote stats.
* @param jid the jid associated with the stats * @param id the id associated with the stats
* @param percent the connection quality percent * @param percent the connection quality percent
* @param object the stats data * @param object the stats data
*/ */
updateConnectionStats (jid, percent, object) { updateConnectionStats (id, percent, object) {
var resourceJid = Strophe.getResourceFromJid(jid); if (remoteVideos[id]) {
remoteVideos[id].updateStatsIndicator(percent, object);
if (remoteVideos[resourceJid]) }
remoteVideos[resourceJid].updateStatsIndicator(percent, object);
}, },
/** /**
* Hides the connection indicator * Hides the connection indicator
* @param jid * @param id
*/ */
hideConnectionIndicator (jid) { hideConnectionIndicator (id) {
remoteVideos[Strophe.getResourceFromJid(jid)].hideConnectionIndicator(); remoteVideos[id].hideConnectionIndicator();
}, },
/** /**
@ -830,7 +815,7 @@ var VideoLayout = {
localVideoThumbnail.hideIndicator(); localVideoThumbnail.hideIndicator();
}, },
participantLeft (id) { removeParticipantContainer (id) {
// Unlock large video // Unlock large video
if (focusedVideoResourceJid === id) { if (focusedVideoResourceJid === id) {
console.info("Focused video owner has left the conference"); console.info("Focused video owner has left the conference");

View File

@ -32,6 +32,7 @@ export default {
TOGGLE_SETTINGS: "UI.toggle_settings", TOGGLE_SETTINGS: "UI.toggle_settings",
TOGGLE_CONTACT_LIST: "UI.toggle_contact_list", TOGGLE_CONTACT_LIST: "UI.toggle_contact_list",
TOGGLE_FILM_STRIP: "UI.toggle_film_strip", TOGGLE_FILM_STRIP: "UI.toggle_film_strip",
CONTACT_CLICKED: "UI.contact_clicked",
HANGUP: "UI.hangup", HANGUP: "UI.hangup",
LOGOUT: "UI.logout", LOGOUT: "UI.logout",
RECORDING_TOGGLE: "UI.recording_toggle", RECORDING_TOGGLE: "UI.recording_toggle",