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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. * Returns true if the current conference is locked.
  20. *
  21. * @returns {Boolean}
  22. */
  23. isLocked() {
  24. return APP.store.getState()['features/base/conference'].locked;
  25. }
  26. /**
  27. * Adding new participant.
  28. *
  29. * @param id
  30. * @param isLocal
  31. */
  32. addContact(id, isLocal) {
  33. const exists = this.contacts.some(el => el.id === id);
  34. if (!exists) {
  35. let newContact = new Contact({ id, isLocal });
  36. this.contacts.push(newContact);
  37. APP.UI.emitEvent(UIEvents.CONTACT_ADDED, { id, isLocal });
  38. }
  39. }
  40. /**
  41. * Removing participant.
  42. *
  43. * @param id
  44. * @returns {Array|*}
  45. */
  46. removeContact(id) {
  47. this.contacts = this.contacts.filter((el) => el.id !== id);
  48. APP.UI.emitEvent(UIEvents.CONTACT_REMOVED, { id });
  49. return this.contacts;
  50. }
  51. /**
  52. * Changing the display name.
  53. *
  54. * @param id
  55. * @param name
  56. */
  57. onDisplayNameChange (id, name) {
  58. if(!name)
  59. return;
  60. if (id === 'localVideoContainer') {
  61. id = APP.conference.getMyUserId();
  62. }
  63. let contacts = this.contacts.filter((el) => el.id === id);
  64. contacts.forEach((el) => {
  65. el.name = name;
  66. });
  67. APP.UI.emitEvent(UIEvents.DISPLAY_NAME_CHANGED, { id, name });
  68. }
  69. /**
  70. * Changing the avatar.
  71. *
  72. * @param id
  73. * @param avatar
  74. */
  75. changeUserAvatar (id, avatar) {
  76. let contacts = this.contacts.filter((el) => el.id === id);
  77. contacts.forEach((el) => {
  78. el.avatar = avatar;
  79. });
  80. APP.UI.emitEvent(UIEvents.USER_AVATAR_CHANGED, { id, avatar });
  81. }
  82. }
  83. export default ContactList;