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.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  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. newContact.id = resourceJid;
  37. newContact.className = "clickable";
  38. newContact.onclick = function(event) {
  39. if(event.currentTarget.className === "clickable") {
  40. var jid = event.currentTarget.id;
  41. var videoContainer = $("#participant_" + jid);
  42. if (videoContainer.length > 0) {
  43. videoContainer.click();
  44. } else if (jid == Strophe.getResourceFromJid(connection.emuc.myroomjid)) {
  45. $("#localVideoContainer").click();
  46. }
  47. }
  48. };
  49. newContact.appendChild(createAvatar());
  50. newContact.appendChild(createDisplayNameParagraph("Participant"));
  51. var clElement = contactlist.get(0);
  52. if (resourceJid === Strophe.getResourceFromJid(connection.emuc.myroomjid)
  53. && $('#contactlist>ul .title')[0].nextSibling.nextSibling)
  54. {
  55. clElement.insertBefore(newContact,
  56. $('#contactlist>ul .title')[0].nextSibling.nextSibling);
  57. }
  58. else {
  59. clElement.appendChild(newContact);
  60. }
  61. updateNumberOfParticipants(1);
  62. };
  63. /**
  64. * Removes a contact for the given peer jid.
  65. *
  66. * @param peerJid the peerJid corresponding to the contact to remove
  67. */
  68. my.removeContact = function(peerJid) {
  69. var resourceJid = Strophe.getResourceFromJid(peerJid);
  70. var contact = $('#contactlist>ul>li[id="' + resourceJid + '"]');
  71. if (contact && contact.length > 0) {
  72. var contactlist = $('#contactlist>ul');
  73. contactlist.get(0).removeChild(contact.get(0));
  74. updateNumberOfParticipants(-1);
  75. }
  76. };
  77. /**
  78. * Opens / closes the contact list area.
  79. */
  80. my.toggleContactList = function () {
  81. var contactlist = $('#contactlist');
  82. var videospace = $('#videospace');
  83. var chatSize = (ContactList.isVisible()) ? [0, 0] : Chat.getChatSize();
  84. var videospaceWidth = window.innerWidth - chatSize[0];
  85. var videospaceHeight = window.innerHeight;
  86. var videoSize
  87. = getVideoSize(null, null, videospaceWidth, videospaceHeight);
  88. var videoWidth = videoSize[0];
  89. var videoHeight = videoSize[1];
  90. var videoPosition = getVideoPosition(videoWidth,
  91. videoHeight,
  92. videospaceWidth,
  93. videospaceHeight);
  94. var horizontalIndent = videoPosition[0];
  95. var verticalIndent = videoPosition[1];
  96. var thumbnailSize = VideoLayout.calculateThumbnailSize(videospaceWidth);
  97. var thumbnailsWidth = thumbnailSize[0];
  98. var thumbnailsHeight = thumbnailSize[1];
  99. var completeFunction = ContactList.isVisible() ?
  100. function() {} : function () { contactlist.trigger('shown');};
  101. videospace.animate({right: chatSize[0],
  102. width: videospaceWidth,
  103. height: videospaceHeight},
  104. {queue: false,
  105. duration: 500,
  106. complete: completeFunction
  107. });
  108. $('#remoteVideos').animate({height: thumbnailsHeight},
  109. {queue: false,
  110. duration: 500});
  111. $('#remoteVideos>span').animate({height: thumbnailsHeight,
  112. width: thumbnailsWidth},
  113. {queue: false,
  114. duration: 500,
  115. complete: function() {
  116. $(document).trigger(
  117. "remotevideo.resized",
  118. [thumbnailsWidth,
  119. thumbnailsHeight]);
  120. }});
  121. $('#largeVideoContainer').animate({ width: videospaceWidth,
  122. height: videospaceHeight},
  123. {queue: false,
  124. duration: 500
  125. });
  126. $('#largeVideo').animate({ width: videoWidth,
  127. height: videoHeight,
  128. top: verticalIndent,
  129. bottom: verticalIndent,
  130. left: horizontalIndent,
  131. right: horizontalIndent},
  132. { queue: false,
  133. duration: 500
  134. });
  135. if (ContactList.isVisible()) {
  136. $('#contactlist').hide("slide", { direction: "right",
  137. queue: false,
  138. duration: 500});
  139. } else {
  140. // Undock the toolbar when the chat is shown and if we're in a
  141. // video mode.
  142. if (VideoLayout.isLargeVideoVisible())
  143. ToolbarToggler.dockToolbar(false);
  144. $('#contactlist').show("slide", { direction: "right",
  145. queue: false,
  146. duration: 500});
  147. //stop the glowing of the contact list icon
  148. setVisualNotification(false);
  149. }
  150. };
  151. /**
  152. * Updates the number of participants in the contact list button and sets
  153. * the glow
  154. * @param delta indicates whether a new user has joined (1) or someone has
  155. * left(-1)
  156. */
  157. function updateNumberOfParticipants(delta) {
  158. //when the user is alone we don't show the number of participants
  159. if(numberOfContacts === 0) {
  160. $("#numberOfParticipants").text('');
  161. numberOfContacts += delta;
  162. } else if(numberOfContacts !== 0 && !ContactList.isVisible()) {
  163. setVisualNotification(true);
  164. numberOfContacts += delta;
  165. $("#numberOfParticipants").text(numberOfContacts);
  166. }
  167. };
  168. /**
  169. * Creates the avatar element.
  170. *
  171. * @return the newly created avatar element
  172. */
  173. function createAvatar() {
  174. var avatar = document.createElement('i');
  175. avatar.className = "icon-avatar avatar";
  176. return avatar;
  177. }
  178. /**
  179. * Creates the display name paragraph.
  180. *
  181. * @param displayName the display name to set
  182. */
  183. function createDisplayNameParagraph(displayName) {
  184. var p = document.createElement('p');
  185. p.innerHTML = displayName;
  186. return p;
  187. }
  188. /**
  189. * Shows/hides a visual notification, indicating that a new user has joined
  190. * the conference.
  191. */
  192. function setVisualNotification(show, stopGlowingIn) {
  193. var glower = $('#contactListButton');
  194. function stopGlowing() {
  195. window.clearInterval(notificationInterval);
  196. notificationInterval = false;
  197. glower.removeClass('glowing');
  198. if(!ContactList.isVisible()) {
  199. glower.removeClass('active');
  200. }
  201. }
  202. if (show && !notificationInterval) {
  203. notificationInterval = window.setInterval(function () {
  204. glower.toggleClass('active glowing');
  205. }, 800);
  206. }
  207. else if (!show && notificationInterval) {
  208. stopGlowing();
  209. }
  210. if(stopGlowingIn) {
  211. setTimeout(stopGlowing, stopGlowingIn);
  212. }
  213. }
  214. /**
  215. * Indicates that the display name has changed.
  216. */
  217. $(document).bind( 'displaynamechanged',
  218. function (event, peerJid, displayName) {
  219. if (peerJid === 'localVideoContainer')
  220. peerJid = connection.emuc.myroomjid;
  221. var resourceJid = Strophe.getResourceFromJid(peerJid);
  222. var contactName = $('#contactlist #' + resourceJid + '>p');
  223. if (contactName && displayName && displayName.length > 0)
  224. contactName.html(displayName);
  225. });
  226. my.setClickable = function(resourceJid, isClickable) {
  227. var contact = $('#contactlist>ul>li[id="' + resourceJid + '"]');
  228. if(isClickable) {
  229. contact.addClass('clickable');
  230. } else {
  231. contact.removeClass('clickable');
  232. }
  233. };
  234. return my;
  235. }(ContactList || {}));