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.

contact_list.js 8.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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. if (ContactList.isVisible()) {
  84. videospace.animate({right: chatSize[0],
  85. width: videospaceWidth,
  86. height: videospaceHeight},
  87. {queue: false,
  88. duration: 500});
  89. $('#remoteVideos').animate({height: thumbnailsHeight},
  90. {queue: false,
  91. duration: 500});
  92. $('#remoteVideos>span').animate({height: thumbnailsHeight,
  93. width: thumbnailsWidth},
  94. {queue: false,
  95. duration: 500,
  96. complete: function() {
  97. $(document).trigger(
  98. "remotevideo.resized",
  99. [thumbnailsWidth,
  100. thumbnailsHeight]);
  101. }});
  102. $('#largeVideoContainer').animate({ width: videospaceWidth,
  103. height: videospaceHeight},
  104. {queue: false,
  105. duration: 500
  106. });
  107. $('#largeVideo').animate({ width: videoWidth,
  108. height: videoHeight,
  109. top: verticalIndent,
  110. bottom: verticalIndent,
  111. left: horizontalIndent,
  112. right: horizontalIndent},
  113. { queue: false,
  114. duration: 500
  115. });
  116. $('#contactlist').hide("slide", { direction: "right",
  117. queue: false,
  118. duration: 500});
  119. }
  120. else {
  121. // Undock the toolbar when the chat is shown and if we're in a
  122. // video mode.
  123. if (VideoLayout.isLargeVideoVisible())
  124. Toolbar.dockToolbar(false);
  125. videospace.animate({right: chatSize[0],
  126. width: videospaceWidth,
  127. height: videospaceHeight},
  128. {queue: false,
  129. duration: 500,
  130. complete: function () {
  131. contactlist.trigger('shown');
  132. }
  133. });
  134. $('#remoteVideos').animate({height: thumbnailsHeight},
  135. {queue: false,
  136. duration: 500});
  137. $('#remoteVideos>span').animate({height: thumbnailsHeight,
  138. width: thumbnailsWidth},
  139. {queue: false,
  140. duration: 500,
  141. complete: function() {
  142. $(document).trigger(
  143. "remotevideo.resized",
  144. [thumbnailsWidth, thumbnailsHeight]);
  145. }});
  146. $('#largeVideoContainer').animate({ width: videospaceWidth,
  147. height: videospaceHeight},
  148. {queue: false,
  149. duration: 500
  150. });
  151. $('#largeVideo').animate({ width: videoWidth,
  152. height: videoHeight,
  153. top: verticalIndent,
  154. bottom: verticalIndent,
  155. left: horizontalIndent,
  156. right: horizontalIndent},
  157. {queue: false,
  158. duration: 500
  159. });
  160. $('#contactlist').show("slide", { direction: "right",
  161. queue: false,
  162. duration: 500});
  163. }
  164. };
  165. /**
  166. * Creates the avatar element.
  167. *
  168. * @return the newly created avatar element
  169. */
  170. function createAvatar() {
  171. var avatar = document.createElement('i');
  172. avatar.className = "icon-avatar avatar";
  173. return avatar;
  174. };
  175. /**
  176. * Creates the display name paragraph.
  177. *
  178. * @param displayName the display name to set
  179. */
  180. function createDisplayNameParagraph(displayName) {
  181. var p = document.createElement('p');
  182. p.innerHTML = displayName;
  183. return p;
  184. };
  185. /**
  186. * Indicates that the display name has changed.
  187. */
  188. $(document).bind( 'displaynamechanged',
  189. function (event, peerJid, displayName) {
  190. if (peerJid === 'localVideoContainer')
  191. peerJid = connection.emuc.myroomjid;
  192. var resourceJid = Strophe.getResourceFromJid(peerJid);
  193. var contactName = $('#contactlist #' + resourceJid + '>p');
  194. if (contactName && displayName && displayName.length > 0)
  195. contactName.html(displayName);
  196. });
  197. return my;
  198. }(ContactList || {}));