You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ContactList.js 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /* global APP */
  2. import UIEvents from '../../../../service/UI/UIEvents';
  3. import ContactListView from './ContactListView';
  4. import Contact from './Contact';
  5. /**
  6. * Model for the Contact list.
  7. *
  8. * @class ContactList
  9. */
  10. class ContactList {
  11. constructor(conference) {
  12. this.conference = conference;
  13. this.contacts = [];
  14. this.roomLocked = false;
  15. ContactListView.init(this);
  16. }
  17. /**
  18. * Is locked flag.
  19. * Delegates to Invite module
  20. * TO FIX: find a better way to access the IS LOCKED state of the invite.
  21. *
  22. * @returns {Boolean}
  23. */
  24. isLocked() {
  25. return APP.conference.invite.isLocked();
  26. }
  27. /**
  28. * Adding new participant.
  29. *
  30. * @param id
  31. * @param isLocal
  32. */
  33. addContact(id, isLocal) {
  34. let isExist = this.contacts.some((el) => el.id === id);
  35. if (!isExist) {
  36. let newContact = new Contact({ id, isLocal });
  37. this.contacts.push(newContact);
  38. APP.UI.emitEvent(UIEvents.CONTACT_ADDED, { id, isLocal });
  39. }
  40. }
  41. /**
  42. * Removing participant.
  43. *
  44. * @param id
  45. * @returns {Array|*}
  46. */
  47. removeContact(id) {
  48. this.contacts = this.contacts.filter((el) => el.id !== id);
  49. APP.UI.emitEvent(UIEvents.CONTACT_REMOVED, { id });
  50. return this.contacts;
  51. }
  52. /**
  53. * Changing the display name.
  54. *
  55. * @param id
  56. * @param name
  57. */
  58. onDisplayNameChange (id, name) {
  59. if(!name)
  60. return;
  61. if (id === 'localVideoContainer') {
  62. id = APP.conference.getMyUserId();
  63. }
  64. let contacts = this.contacts.filter((el) => el.id === id);
  65. contacts.forEach((el) => {
  66. el.name = name;
  67. });
  68. APP.UI.emitEvent(UIEvents.DISPLAY_NAME_CHANGED, { id, name });
  69. }
  70. /**
  71. * Changing the avatar.
  72. *
  73. * @param id
  74. * @param avatar
  75. */
  76. changeUserAvatar (id, avatar) {
  77. let contacts = this.contacts.filter((el) => el.id === id);
  78. contacts.forEach((el) => {
  79. el.avatar = avatar;
  80. });
  81. APP.UI.emitEvent(UIEvents.USER_AVATAR_CHANGED, { id, avatar });
  82. }
  83. }
  84. export default ContactList;