jiti-meet/modules/UI/side_pannels/contactlist/ContactList.js

95 lines
2.2 KiB
JavaScript
Raw Normal View History

/* global APP */
import UIEvents from '../../../../service/UI/UIEvents';
import ContactListView from './ContactListView';
import Contact from './Contact';
2015-01-07 14:54:03 +00:00
/**
* Model for the Contact list.
2015-01-07 14:54:03 +00:00
*
* @class ContactList
2015-01-07 14:54:03 +00:00
*/
class ContactList {
constructor(conference) {
this.conference = conference;
this.contacts = [];
this.roomLocked = false;
2016-10-25 13:16:15 +00:00
//setup ContactList Model into ContactList View
ContactListView.setup(this);
2015-03-09 15:50:13 +00:00
}
2015-01-07 14:54:03 +00:00
/**
* Is locked flag.
* Delegates to Invite module
* TO FIX: find a better way to access the IS LOCKED state of the invite.
*
* @returns {Boolean}
*/
isLocked() {
return APP.conference.invite.isLocked();
}
/**
* Adding new participant.
*
* @param id
* @param isLocal
*/
addContact(id, isLocal) {
let isExist = this.contacts.some((el) => el.id === id);
if (!isExist) {
let newContact = new Contact({ id, isLocal });
this.contacts.push(newContact);
APP.UI.emitEvent(UIEvents.CONTACT_ADDED, { id, isLocal });
}
}
/**
* Removing participant.
*
* @param id
* @returns {Array|*}
*/
removeContact(id) {
this.contacts = this.contacts.filter((el) => el.id !== id);
APP.UI.emitEvent(UIEvents.CONTACT_REMOVED, { id });
return this.contacts;
}
/**
* Changing the display name.
*
* @param id
* @param name
*/
onDisplayNameChange (id, name) {
if(!name)
return;
2015-12-01 13:41:58 +00:00
if (id === 'localVideoContainer') {
2016-07-08 01:44:04 +00:00
id = APP.conference.getMyUserId();
2015-12-01 13:41:58 +00:00
}
let contacts = this.contacts.filter((el) => el.id === id);
contacts.forEach((el) => {
el.name = name;
});
APP.UI.emitEvent(UIEvents.DISPLAY_NAME_CHANGED, { id, name });
}
/**
* Changing the avatar.
*
* @param id
* @param avatar
*/
changeUserAvatar (id, avatar) {
let contacts = this.contacts.filter((el) => el.id === id);
contacts.forEach((el) => {
el.avatar = avatar;
});
APP.UI.emitEvent(UIEvents.USER_AVATAR_CHANGED, { id, avatar });
2015-01-07 14:54:03 +00:00
}
}
export default ContactList;