Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. /**
  2. * Contact list.
  3. */
  4. var ContactList = (function (my) {
  5. /**
  6. * Indicates if the chat is currently visible.
  7. *
  8. * @return <tt>true</tt> if the chat is currently visible, <tt>false</tt> -
  9. * otherwise
  10. */
  11. my.isVisible = function () {
  12. return $('#contactlist').is(":visible");
  13. };
  14. /**
  15. * Adds a contact for the given peerJid if such doesn't yet exist.
  16. *
  17. * @param peerJid the peerJid corresponding to the contact
  18. */
  19. my.ensureAddContact = function(peerJid) {
  20. var resourceJid = Strophe.getResourceFromJid(peerJid);
  21. var contact = $('#contactlist>ul>li[id="' + resourceJid + '"]');
  22. if (!contact || contact.length <= 0)
  23. ContactList.addContact(peerJid);
  24. };
  25. /**
  26. * Adds a contact for the given peer jid.
  27. *
  28. * @param peerJid the jid of the contact to add
  29. */
  30. my.addContact = function(peerJid) {
  31. var resourceJid = Strophe.getResourceFromJid(peerJid);
  32. var contactlist = $('#contactlist>ul');
  33. var newContact = document.createElement('li');
  34. newContact.id = resourceJid;
  35. newContact.appendChild(createAvatar());
  36. newContact.appendChild(createDisplayNameParagraph("Participant"));
  37. var clElement = contactlist.get(0);
  38. if (resourceJid === Strophe.getResourceFromJid(connection.emuc.myroomjid)
  39. && $('#contactlist>ul .title')[0].nextSibling.nextSibling)
  40. {
  41. clElement.insertBefore(newContact,
  42. $('#contactlist>ul .title')[0].nextSibling.nextSibling);
  43. }
  44. else {
  45. clElement.appendChild(newContact);
  46. }
  47. };
  48. /**
  49. * Removes a contact for the given peer jid.
  50. *
  51. * @param peerJid the peerJid corresponding to the contact to remove
  52. */
  53. my.removeContact = function(peerJid) {
  54. var resourceJid = Strophe.getResourceFromJid(peerJid);
  55. var contact = $('#contactlist>ul>li[id="' + resourceJid + '"]');
  56. if (contact && contact.length > 0) {
  57. var contactlist = $('#contactlist>ul');
  58. contactlist.get(0).removeChild(contact.get(0));
  59. }
  60. };
  61. /**
  62. * Opens / closes the contact list area.
  63. */
  64. my.toggleContactList = function () {
  65. var contactlist = $('#contactlist');
  66. var videospace = $('#videospace');
  67. var chatSize = (ContactList.isVisible()) ? [0, 0] : Chat.getChatSize();
  68. var videospaceWidth = window.innerWidth - chatSize[0];
  69. var videospaceHeight = window.innerHeight;
  70. var videoSize
  71. = getVideoSize(null, null, videospaceWidth, videospaceHeight);
  72. var videoWidth = videoSize[0];
  73. var videoHeight = videoSize[1];
  74. var videoPosition = getVideoPosition(videoWidth,
  75. videoHeight,
  76. videospaceWidth,
  77. videospaceHeight);
  78. var horizontalIndent = videoPosition[0];
  79. var verticalIndent = videoPosition[1];
  80. var thumbnailSize = VideoLayout.calculateThumbnailSize(videospaceWidth);
  81. var thumbnailsWidth = thumbnailSize[0];
  82. var thumbnailsHeight = thumbnailSize[1];
  83. var completeFunction = ContactList.isVisible() ?
  84. function() {} : function () { contactlist.trigger('shown');};
  85. videospace.animate({right: chatSize[0],
  86. width: videospaceWidth,
  87. height: videospaceHeight},
  88. {queue: false,
  89. duration: 500,
  90. complete: completeFunction
  91. });
  92. $('#remoteVideos').animate({height: thumbnailsHeight},
  93. {queue: false,
  94. duration: 500});
  95. $('#remoteVideos>span').animate({height: thumbnailsHeight,
  96. width: thumbnailsWidth},
  97. {queue: false,
  98. duration: 500,
  99. complete: function() {
  100. $(document).trigger(
  101. "remotevideo.resized",
  102. [thumbnailsWidth,
  103. thumbnailsHeight]);
  104. }});
  105. $('#largeVideoContainer').animate({ width: videospaceWidth,
  106. height: videospaceHeight},
  107. {queue: false,
  108. duration: 500
  109. });
  110. $('#largeVideo').animate({ width: videoWidth,
  111. height: videoHeight,
  112. top: verticalIndent,
  113. bottom: verticalIndent,
  114. left: horizontalIndent,
  115. right: horizontalIndent},
  116. { queue: false,
  117. duration: 500
  118. });
  119. if (ContactList.isVisible()) {
  120. $('#contactlist').hide("slide", { direction: "right",
  121. queue: false,
  122. duration: 500});
  123. } else {
  124. // Undock the toolbar when the chat is shown and if we're in a
  125. // video mode.
  126. if (VideoLayout.isLargeVideoVisible())
  127. ToolbarToggler.dockToolbar(false);
  128. $('#contactlist').show("slide", { direction: "right",
  129. queue: false,
  130. duration: 500});
  131. }
  132. };
  133. /**
  134. * Creates the avatar element.
  135. *
  136. * @return the newly created avatar element
  137. */
  138. function createAvatar() {
  139. var avatar = document.createElement('i');
  140. avatar.className = "icon-avatar avatar";
  141. return avatar;
  142. };
  143. /**
  144. * Creates the display name paragraph.
  145. *
  146. * @param displayName the display name to set
  147. */
  148. function createDisplayNameParagraph(displayName) {
  149. var p = document.createElement('p');
  150. p.innerHTML = displayName;
  151. return p;
  152. };
  153. /**
  154. * Indicates that the display name has changed.
  155. */
  156. $(document).bind( 'displaynamechanged',
  157. function (event, peerJid, displayName) {
  158. if (peerJid === 'localVideoContainer')
  159. peerJid = connection.emuc.myroomjid;
  160. var resourceJid = Strophe.getResourceFromJid(peerJid);
  161. var contactName = $('#contactlist #' + resourceJid + '>p');
  162. if (contactName && displayName && displayName.length > 0)
  163. contactName.html(displayName);
  164. });
  165. return my;
  166. }(ContactList || {}));