jiti-meet/modules/UI/avatar/Avatar.js

64 lines
1.9 KiB
JavaScript
Raw Normal View History

2015-12-02 15:24:57 +00:00
/* global MD5 */
2015-01-07 14:54:03 +00:00
var users = {};
var Avatar = {
/**
* Sets the user's avatar in the settings menu(if local user), contact list
* and thumbnail
2015-12-02 15:24:57 +00:00
* @param id id of the user
* @param email email or nickname to be used as a hash
*/
2015-12-02 15:24:57 +00:00
setUserAvatar: function (id, email) {
if (email) {
if (users[id] === email) {
return;
}
2015-12-02 15:24:57 +00:00
users[id] = email;
}
2015-12-02 15:24:57 +00:00
var thumbUrl = this.getThumbUrl(id);
var contactListUrl = this.getContactListUrl(id);
2015-01-07 14:54:03 +00:00
},
/**
* Returns image URL for the avatar to be displayed on large video area
* where current active speaker is presented.
2015-12-02 15:24:57 +00:00
* @param id id of the user for whom we want to obtain avatar URL
*/
2015-12-02 15:24:57 +00:00
getActiveSpeakerUrl: function (id) {
return this.getGravatarUrl(id, 100);
},
/**
* Returns image URL for the avatar to be displayed on small video thumbnail
2015-12-02 15:24:57 +00:00
* @param id id of the user for whom we want to obtain avatar URL
*/
2015-12-02 15:24:57 +00:00
getThumbUrl: function (id) {
return this.getGravatarUrl(id, 100);
},
/**
* Returns the URL for the avatar to be displayed as contactlist item
2015-12-02 15:24:57 +00:00
* @param id id of the user for whom we want to obtain avatar URL
*/
2015-12-02 15:24:57 +00:00
getContactListUrl: function (id) {
return this.getGravatarUrl(id, 30);
},
2015-12-02 15:24:57 +00:00
getGravatarUrl: function (id, size) {
if (!id) {
console.error("Get gravatar - id is undefined");
return null;
}
2015-12-02 15:24:57 +00:00
var email = users[id];
if (!email) {
console.warn(
2015-12-02 15:24:57 +00:00
"No avatar stored yet for " + id + " - using user id as ID"
);
email = id;
}
return 'https://www.gravatar.com/avatar/' +
2015-12-02 15:24:57 +00:00
MD5.hexdigest(email.trim().toLowerCase()) +
"?d=wavatar&size=" + (size || "30");
}
2015-01-07 14:54:03 +00:00
};
2015-01-07 14:54:03 +00:00
module.exports = Avatar;