Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

avatar.js 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. var Avatar = (function(my) {
  2. var users = {};
  3. var activeSpeakerJid;
  4. /**
  5. * Sets the user's avatar in the settings menu(if local user), contact list
  6. * and thumbnail
  7. * @param jid jid of the user
  8. * @param id email or userID to be used as a hash
  9. */
  10. my.setUserAvatar = function(jid, id) {
  11. if(id) {
  12. if(users[jid] === id) {
  13. return;
  14. }
  15. users[jid] = id;
  16. }
  17. var thumbUrl = getGravatarUrl(users[jid] || jid, 100);
  18. var contactListUrl = getGravatarUrl(users[jid] || jid);
  19. var resourceJid = Strophe.getResourceFromJid(jid);
  20. var thumbnail = $('#participant_' + resourceJid);
  21. var avatar = $('#avatar_' + resourceJid);
  22. // set the avatar in the settings menu if it is local user and get the
  23. // local video container
  24. if(jid === connection.emuc.myroomjid) {
  25. $('#avatar').get(0).src = thumbUrl;
  26. thumbnail = $('#localVideoContainer');
  27. }
  28. // set the avatar in the contact list
  29. var contact = $('#' + resourceJid + '>img');
  30. if(contact && contact.length > 0) {
  31. contact.get(0).src = contactListUrl;
  32. }
  33. // set the avatar in the thumbnail
  34. if(avatar && avatar.length > 0) {
  35. avatar[0].src = thumbUrl;
  36. } else {
  37. if (thumbnail && thumbnail.length > 0) {
  38. avatar = document.createElement('img');
  39. avatar.id = 'avatar_' + resourceJid;
  40. avatar.className = 'userAvatar';
  41. avatar.src = thumbUrl;
  42. thumbnail.append(avatar);
  43. }
  44. }
  45. //if the user is the current active speaker - update the active speaker
  46. // avatar
  47. if(jid === activeSpeakerJid) {
  48. Avatar.updateActiveSpeakerAvatarSrc(jid);
  49. }
  50. };
  51. /**
  52. * Hides or shows the user's avatar
  53. * @param jid jid of the user
  54. * @param show whether we should show the avatar or not
  55. * video because there is no dominant speaker and no focused speaker
  56. */
  57. my.showUserAvatar = function(jid, show) {
  58. if(users[jid]) {
  59. var resourceJid = Strophe.getResourceFromJid(jid);
  60. var video = $('#participant_' + resourceJid + '>video');
  61. var avatar = $('#avatar_' + resourceJid);
  62. if(jid === connection.emuc.myroomjid) {
  63. video = $('#localVideoWrapper>video');
  64. }
  65. if(show === undefined || show === null) {
  66. show = isUserMuted(jid);
  67. }
  68. //if the user is the currently focused, the dominant speaker or if
  69. //there is no focused and no dominant speaker and the large video is
  70. //currently shown
  71. if (activeSpeakerJid === jid && VideoLayout.isLargeVideoOnTop()) {
  72. setVisibility($("#largeVideo"), !show);
  73. setVisibility($('#activeSpeaker'), show);
  74. setVisibility(avatar, false);
  75. setVisibility(video, false);
  76. } else {
  77. if (video && video.length > 0) {
  78. setVisibility(video, !show);
  79. setVisibility(avatar, show);
  80. }
  81. }
  82. }
  83. };
  84. /**
  85. * Updates the src of the active speaker avatar
  86. * @param jid of the current active speaker
  87. */
  88. my.updateActiveSpeakerAvatarSrc = function(jid) {
  89. if(!jid) {
  90. jid = connection.emuc.findJidFromResource(
  91. VideoLayout.getLargeVideoState().userResourceJid);
  92. }
  93. var avatar = $("#activeSpeakerAvatar")[0];
  94. var url = getGravatarUrl(users[jid],
  95. interfaceConfig.ACTIVE_SPEAKER_AVATAR_SIZE);
  96. if(jid === activeSpeakerJid && avatar.src === url) {
  97. return;
  98. }
  99. activeSpeakerJid = jid;
  100. var isMuted = isUserMuted(jid);
  101. if(jid && isMuted !== null) {
  102. avatar.src = url;
  103. setVisibility($("#largeVideo"), !isMuted);
  104. Avatar.showUserAvatar(jid, isMuted);
  105. }
  106. };
  107. function setVisibility(selector, show) {
  108. if (selector && selector.length > 0) {
  109. selector.css("visibility", show ? "visible" : "hidden");
  110. }
  111. }
  112. function isUserMuted(jid) {
  113. // XXX(gp) we may want to rename this method to something like
  114. // isUserStreaming, for example.
  115. if (jid && jid != connection.emuc.myroomjid) {
  116. var resource = Strophe.getResourceFromJid(jid);
  117. if (!VideoLayout.isInLastN(resource)) {
  118. return true;
  119. }
  120. }
  121. if (!mediaStreams[jid] || !mediaStreams[jid][MediaStream.VIDEO_TYPE]) {
  122. return null;
  123. }
  124. return mediaStreams[jid][MediaStream.VIDEO_TYPE].muted;
  125. }
  126. function getGravatarUrl(id, size) {
  127. if(id === connection.emuc.myroomjid || !id) {
  128. id = SettingsMenu.getUID();
  129. }
  130. return 'https://www.gravatar.com/avatar/' +
  131. MD5.hexdigest(id.trim().toLowerCase()) +
  132. "?d=retro&size=" + (size || "30");
  133. }
  134. return my;
  135. }(Avatar || {}));