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 7.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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.className = "clickable";
  36. newContact.onclick = function(event) {
  37. if(event.currentTarget.className === "clickable") {
  38. var jid = event.currentTarget.id;
  39. var videoContainer = $("#participant_" + jid);
  40. if (videoContainer.length > 0) {
  41. videoContainer.click();
  42. } else if (jid == Strophe.getResourceFromJid(connection.emuc.myroomjid)) {
  43. $("#localVideoContainer").click();
  44. }
  45. }
  46. };
  47. newContact.appendChild(createAvatar());
  48. newContact.appendChild(createDisplayNameParagraph("Participant"));
  49. var clElement = contactlist.get(0);
  50. if (resourceJid === Strophe.getResourceFromJid(connection.emuc.myroomjid)
  51. && $('#contactlist>ul .title')[0].nextSibling.nextSibling)
  52. {
  53. clElement.insertBefore(newContact,
  54. $('#contactlist>ul .title')[0].nextSibling.nextSibling);
  55. }
  56. else {
  57. clElement.appendChild(newContact);
  58. }
  59. };
  60. /**
  61. * Removes a contact for the given peer jid.
  62. *
  63. * @param peerJid the peerJid corresponding to the contact to remove
  64. */
  65. my.removeContact = function(peerJid) {
  66. var resourceJid = Strophe.getResourceFromJid(peerJid);
  67. var contact = $('#contactlist>ul>li[id="' + resourceJid + '"]');
  68. if (contact && contact.length > 0) {
  69. var contactlist = $('#contactlist>ul');
  70. contactlist.get(0).removeChild(contact.get(0));
  71. }
  72. };
  73. /**
  74. * Opens / closes the contact list area.
  75. */
  76. my.toggleContactList = function () {
  77. var contactlist = $('#contactlist');
  78. var videospace = $('#videospace');
  79. var chatSize = (ContactList.isVisible()) ? [0, 0] : Chat.getChatSize();
  80. var videospaceWidth = window.innerWidth - chatSize[0];
  81. var videospaceHeight = window.innerHeight;
  82. var videoSize
  83. = getVideoSize(null, null, videospaceWidth, videospaceHeight);
  84. var videoWidth = videoSize[0];
  85. var videoHeight = videoSize[1];
  86. var videoPosition = getVideoPosition(videoWidth,
  87. videoHeight,
  88. videospaceWidth,
  89. videospaceHeight);
  90. var horizontalIndent = videoPosition[0];
  91. var verticalIndent = videoPosition[1];
  92. var thumbnailSize = VideoLayout.calculateThumbnailSize(videospaceWidth);
  93. var thumbnailsWidth = thumbnailSize[0];
  94. var thumbnailsHeight = thumbnailSize[1];
  95. var completeFunction = ContactList.isVisible() ?
  96. function() {} : function () { contactlist.trigger('shown');};
  97. videospace.animate({right: chatSize[0],
  98. width: videospaceWidth,
  99. height: videospaceHeight},
  100. {queue: false,
  101. duration: 500,
  102. complete: completeFunction
  103. });
  104. $('#remoteVideos').animate({height: thumbnailsHeight},
  105. {queue: false,
  106. duration: 500});
  107. $('#remoteVideos>span').animate({height: thumbnailsHeight,
  108. width: thumbnailsWidth},
  109. {queue: false,
  110. duration: 500,
  111. complete: function() {
  112. $(document).trigger(
  113. "remotevideo.resized",
  114. [thumbnailsWidth,
  115. thumbnailsHeight]);
  116. }});
  117. $('#largeVideoContainer').animate({ width: videospaceWidth,
  118. height: videospaceHeight},
  119. {queue: false,
  120. duration: 500
  121. });
  122. $('#largeVideo').animate({ width: videoWidth,
  123. height: videoHeight,
  124. top: verticalIndent,
  125. bottom: verticalIndent,
  126. left: horizontalIndent,
  127. right: horizontalIndent},
  128. { queue: false,
  129. duration: 500
  130. });
  131. if (ContactList.isVisible()) {
  132. $('#contactlist').hide("slide", { direction: "right",
  133. queue: false,
  134. duration: 500});
  135. } else {
  136. // Undock the toolbar when the chat is shown and if we're in a
  137. // video mode.
  138. if (VideoLayout.isLargeVideoVisible())
  139. ToolbarToggler.dockToolbar(false);
  140. $('#contactlist').show("slide", { direction: "right",
  141. queue: false,
  142. duration: 500});
  143. }
  144. };
  145. /**
  146. * Creates the avatar element.
  147. *
  148. * @return the newly created avatar element
  149. */
  150. function createAvatar() {
  151. var avatar = document.createElement('i');
  152. avatar.className = "icon-avatar avatar";
  153. return avatar;
  154. };
  155. /**
  156. * Creates the display name paragraph.
  157. *
  158. * @param displayName the display name to set
  159. */
  160. function createDisplayNameParagraph(displayName) {
  161. var p = document.createElement('p');
  162. p.innerHTML = displayName;
  163. return p;
  164. };
  165. /**
  166. * Indicates that the display name has changed.
  167. */
  168. $(document).bind( 'displaynamechanged',
  169. function (event, peerJid, displayName) {
  170. if (peerJid === 'localVideoContainer')
  171. peerJid = connection.emuc.myroomjid;
  172. var resourceJid = Strophe.getResourceFromJid(peerJid);
  173. var contactName = $('#contactlist #' + resourceJid + '>p');
  174. if (contactName && displayName && displayName.length > 0)
  175. contactName.html(displayName);
  176. });
  177. my.setClickable = function(resourceJid, isClickable) {
  178. var contact = $('#contactlist>ul>li[id="' + resourceJid + '"]');
  179. if(isClickable) {
  180. contact.addClass('clickable');
  181. } else {
  182. contact.removeClass('clickable');
  183. }
  184. };
  185. return my;
  186. }(ContactList || {}));