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

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