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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. /**
  2. * Contact list.
  3. */
  4. var ContactList = (function (my) {
  5. var numberOfContacts = 0;
  6. var notificationInterval;
  7. /**
  8. * Indicates if the chat is currently visible.
  9. *
  10. * @return <tt>true</tt> if the chat is currently visible, <tt>false</tt> -
  11. * otherwise
  12. */
  13. my.isVisible = function () {
  14. return $('#contactlist').is(":visible");
  15. };
  16. /**
  17. * Adds a contact for the given peerJid if such doesn't yet exist.
  18. *
  19. * @param peerJid the peerJid corresponding to the contact
  20. */
  21. my.ensureAddContact = function(peerJid) {
  22. var resourceJid = Strophe.getResourceFromJid(peerJid);
  23. var contact = $('#contactlist>ul>li[id="' + resourceJid + '"]');
  24. if (!contact || contact.length <= 0)
  25. ContactList.addContact(peerJid);
  26. };
  27. /**
  28. * Adds a contact for the given peer jid.
  29. *
  30. * @param peerJid the jid of the contact to add
  31. */
  32. my.addContact = function(peerJid) {
  33. var resourceJid = Strophe.getResourceFromJid(peerJid);
  34. var contactlist = $('#contactlist>ul');
  35. var newContact = document.createElement('li');
  36. // XXX(gp) contact click event handling is now in videolayout.js. Is the
  37. // following statement (newContact.id = resourceJid) still relevant?
  38. newContact.id = resourceJid;
  39. newContact.className = "clickable";
  40. newContact.onclick = function(event) {
  41. if(event.currentTarget.className === "clickable") {
  42. $(ContactList).trigger('contactclicked', [peerJid]);
  43. }
  44. };
  45. newContact.appendChild(createAvatar());
  46. newContact.appendChild(createDisplayNameParagraph("Participant"));
  47. var clElement = contactlist.get(0);
  48. if (resourceJid === Strophe.getResourceFromJid(connection.emuc.myroomjid)
  49. && $('#contactlist>ul .title')[0].nextSibling.nextSibling)
  50. {
  51. clElement.insertBefore(newContact,
  52. $('#contactlist>ul .title')[0].nextSibling.nextSibling);
  53. }
  54. else {
  55. clElement.appendChild(newContact);
  56. }
  57. updateNumberOfParticipants(1);
  58. };
  59. /**
  60. * Removes a contact for the given peer jid.
  61. *
  62. * @param peerJid the peerJid corresponding to the contact to remove
  63. */
  64. my.removeContact = function(peerJid) {
  65. var resourceJid = Strophe.getResourceFromJid(peerJid);
  66. var contact = $('#contactlist>ul>li[id="' + resourceJid + '"]');
  67. if (contact && contact.length > 0) {
  68. var contactlist = $('#contactlist>ul');
  69. contactlist.get(0).removeChild(contact.get(0));
  70. updateNumberOfParticipants(-1);
  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. $("#toast-container").animate({right: '12px'},
  133. {queue: false,
  134. duration: 500});
  135. $('#contactlist').hide("slide", { direction: "right",
  136. queue: false,
  137. duration: 500});
  138. } else {
  139. // Undock the toolbar when the chat is shown and if we're in a
  140. // video mode.
  141. if (VideoLayout.isLargeVideoVisible())
  142. ToolbarToggler.dockToolbar(false);
  143. $("#toast-container").animate({right: '212px'},
  144. {queue: false,
  145. duration: 500});
  146. $('#contactlist').show("slide", { direction: "right",
  147. queue: false,
  148. duration: 500});
  149. //stop the glowing of the contact list icon
  150. setVisualNotification(false);
  151. }
  152. };
  153. /**
  154. * Updates the number of participants in the contact list button and sets
  155. * the glow
  156. * @param delta indicates whether a new user has joined (1) or someone has
  157. * left(-1)
  158. */
  159. function updateNumberOfParticipants(delta) {
  160. //when the user is alone we don't show the number of participants
  161. if(numberOfContacts === 0) {
  162. $("#numberOfParticipants").text('');
  163. numberOfContacts += delta;
  164. } else if(numberOfContacts !== 0 && !ContactList.isVisible()) {
  165. setVisualNotification(true);
  166. numberOfContacts += delta;
  167. $("#numberOfParticipants").text(numberOfContacts);
  168. }
  169. };
  170. /**
  171. * Creates the avatar element.
  172. *
  173. * @return the newly created avatar element
  174. */
  175. function createAvatar() {
  176. var avatar = document.createElement('i');
  177. avatar.className = "icon-avatar avatar";
  178. return avatar;
  179. }
  180. /**
  181. * Creates the display name paragraph.
  182. *
  183. * @param displayName the display name to set
  184. */
  185. function createDisplayNameParagraph(displayName) {
  186. var p = document.createElement('p');
  187. p.innerText = displayName;
  188. return p;
  189. }
  190. /**
  191. * Shows/hides a visual notification, indicating that a new user has joined
  192. * the conference.
  193. */
  194. function setVisualNotification(show, stopGlowingIn) {
  195. var glower = $('#contactListButton');
  196. function stopGlowing() {
  197. window.clearInterval(notificationInterval);
  198. notificationInterval = false;
  199. glower.removeClass('glowing');
  200. if(!ContactList.isVisible()) {
  201. glower.removeClass('active');
  202. }
  203. }
  204. if (show && !notificationInterval) {
  205. notificationInterval = window.setInterval(function () {
  206. glower.toggleClass('active glowing');
  207. }, 800);
  208. }
  209. else if (!show && notificationInterval) {
  210. stopGlowing();
  211. }
  212. if(stopGlowingIn) {
  213. setTimeout(stopGlowing, stopGlowingIn);
  214. }
  215. }
  216. /**
  217. * Indicates that the display name has changed.
  218. */
  219. $(document).bind( 'displaynamechanged',
  220. function (event, peerJid, displayName) {
  221. if (peerJid === 'localVideoContainer')
  222. peerJid = connection.emuc.myroomjid;
  223. var resourceJid = Strophe.getResourceFromJid(peerJid);
  224. var contactName = $('#contactlist #' + resourceJid + '>p');
  225. if (contactName && displayName && displayName.length > 0)
  226. contactName.text(displayName);
  227. });
  228. my.setClickable = function(resourceJid, isClickable) {
  229. var contact = $('#contactlist>ul>li[id="' + resourceJid + '"]');
  230. if(isClickable) {
  231. contact.addClass('clickable');
  232. } else {
  233. contact.removeClass('clickable');
  234. }
  235. };
  236. return my;
  237. }(ContactList || {}));