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

79 lines
2.4 KiB
JavaScript
Raw Normal View History

/* global Strophe, APP, MD5, config, interfaceConfig */
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 dominant 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
*/
getDominantSpeakerUrl: function (id) {
2015-12-02 15:24:57 +00:00
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;
}
// Default to using gravatar.
var urlPref = 'https://www.gravatar.com/avatar/';
var urlSuf = "?d=wavatar&size=" + (size || "30");
// If we have a real email we will use it for the gravatar and we'll
// use the pre-configured URL if any. Otherwise, it's a random avatar.
2015-12-02 15:24:57 +00:00
var email = users[id];
if (email && email.indexOf('@')) {
id = email;
if (interfaceConfig.RANDOM_AVATAR_URL_PREFIX) {
urlPref = interfaceConfig.RANDOM_AVATAR_URL_PREFIX;
urlSuf = interfaceConfig.RANDOM_AVATAR_URL_SUFFIX;
}
}
if (!config.disableThirdPartyRequests) {
return urlPref +
2015-12-07 20:41:35 +00:00
MD5.hexdigest(id.trim().toLowerCase()) +
urlSuf;
2015-12-07 20:41:35 +00:00
} else {
return 'images/avatar2.png';
}
}
2015-01-07 14:54:03 +00:00
};
2015-12-07 20:41:35 +00:00
module.exports = Avatar;