選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

Avatar.js 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /* global MD5 */
  2. var users = {};
  3. var Avatar = {
  4. /**
  5. * Sets the user's avatar in the settings menu(if local user), contact list
  6. * and thumbnail
  7. * @param id id of the user
  8. * @param email email or nickname to be used as a hash
  9. */
  10. setUserAvatar: function (id, email) {
  11. if (email) {
  12. if (users[id] === email) {
  13. return;
  14. }
  15. users[id] = email;
  16. }
  17. var thumbUrl = this.getThumbUrl(id);
  18. var contactListUrl = this.getContactListUrl(id);
  19. },
  20. /**
  21. * Returns image URL for the avatar to be displayed on large video area
  22. * where current active speaker is presented.
  23. * @param id id of the user for whom we want to obtain avatar URL
  24. */
  25. getActiveSpeakerUrl: function (id) {
  26. return this.getGravatarUrl(id, 100);
  27. },
  28. /**
  29. * Returns image URL for the avatar to be displayed on small video thumbnail
  30. * @param id id of the user for whom we want to obtain avatar URL
  31. */
  32. getThumbUrl: function (id) {
  33. return this.getGravatarUrl(id, 100);
  34. },
  35. /**
  36. * Returns the URL for the avatar to be displayed as contactlist item
  37. * @param id id of the user for whom we want to obtain avatar URL
  38. */
  39. getContactListUrl: function (id) {
  40. return this.getGravatarUrl(id, 30);
  41. },
  42. getGravatarUrl: function (id, size) {
  43. if (!id) {
  44. console.error("Get gravatar - id is undefined");
  45. return null;
  46. }
  47. var email = users[id];
  48. if (!email) {
  49. console.warn(
  50. "No avatar stored yet for " + id + " - using user id as ID"
  51. );
  52. email = id;
  53. }
  54. return 'https://www.gravatar.com/avatar/' +
  55. MD5.hexdigest(email.trim().toLowerCase()) +
  56. "?d=wavatar&size=" + (size || "30");
  57. }
  58. };
  59. module.exports = Avatar;