2014-10-31 11:47:12 +00:00
|
|
|
var Avatar = (function(my) {
|
|
|
|
var users = {};
|
|
|
|
var activeSpeakerJid;
|
|
|
|
/**
|
|
|
|
* Sets the user's avatar in the settings menu(if local user), contact list
|
|
|
|
* and thumbnail
|
|
|
|
* @param jid jid of the user
|
|
|
|
* @param id email or userID to be used as a hash
|
|
|
|
*/
|
|
|
|
my.setUserAvatar = function(jid, id) {
|
|
|
|
if(id) {
|
|
|
|
if(users[jid] === id) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
users[jid] = id;
|
|
|
|
}
|
2014-12-03 09:09:12 +00:00
|
|
|
var thumbUrl = getGravatarUrl(users[jid] || jid, 100);
|
|
|
|
var contactListUrl = getGravatarUrl(users[jid] || jid);
|
2014-10-31 11:47:12 +00:00
|
|
|
var resourceJid = Strophe.getResourceFromJid(jid);
|
|
|
|
var thumbnail = $('#participant_' + resourceJid);
|
|
|
|
var avatar = $('#avatar_' + resourceJid);
|
|
|
|
|
|
|
|
// set the avatar in the settings menu if it is local user and get the
|
|
|
|
// local video container
|
|
|
|
if(jid === connection.emuc.myroomjid) {
|
2014-12-03 09:09:12 +00:00
|
|
|
$('#avatar').get(0).src = thumbUrl;
|
2014-10-31 11:47:12 +00:00
|
|
|
thumbnail = $('#localVideoContainer');
|
|
|
|
}
|
|
|
|
|
|
|
|
// set the avatar in the contact list
|
|
|
|
var contact = $('#' + resourceJid + '>img');
|
|
|
|
if(contact && contact.length > 0) {
|
2014-12-03 09:09:12 +00:00
|
|
|
contact.get(0).src = contactListUrl;
|
2014-10-31 11:47:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// set the avatar in the thumbnail
|
|
|
|
if(avatar && avatar.length > 0) {
|
2014-12-03 09:09:12 +00:00
|
|
|
avatar[0].src = thumbUrl;
|
2014-10-31 11:47:12 +00:00
|
|
|
} else {
|
|
|
|
if (thumbnail && thumbnail.length > 0) {
|
|
|
|
avatar = document.createElement('img');
|
|
|
|
avatar.id = 'avatar_' + resourceJid;
|
|
|
|
avatar.className = 'userAvatar';
|
2014-12-03 09:09:12 +00:00
|
|
|
avatar.src = thumbUrl;
|
2014-10-31 11:47:12 +00:00
|
|
|
thumbnail.append(avatar);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//if the user is the current active speaker - update the active speaker
|
|
|
|
// avatar
|
|
|
|
if(jid === activeSpeakerJid) {
|
|
|
|
Avatar.updateActiveSpeakerAvatarSrc(jid);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Hides or shows the user's avatar
|
|
|
|
* @param jid jid of the user
|
|
|
|
* @param show whether we should show the avatar or not
|
|
|
|
* video because there is no dominant speaker and no focused speaker
|
|
|
|
*/
|
|
|
|
my.showUserAvatar = function(jid, show) {
|
|
|
|
if(users[jid]) {
|
|
|
|
var resourceJid = Strophe.getResourceFromJid(jid);
|
|
|
|
var video = $('#participant_' + resourceJid + '>video');
|
|
|
|
var avatar = $('#avatar_' + resourceJid);
|
|
|
|
|
|
|
|
if(jid === connection.emuc.myroomjid) {
|
|
|
|
video = $('#localVideoWrapper>video');
|
|
|
|
}
|
|
|
|
if(show === undefined || show === null) {
|
|
|
|
show = isUserMuted(jid);
|
|
|
|
}
|
|
|
|
|
|
|
|
//if the user is the currently focused, the dominant speaker or if
|
2014-11-28 14:02:48 +00:00
|
|
|
//there is no focused and no dominant speaker and the large video is
|
|
|
|
//currently shown
|
|
|
|
if (activeSpeakerJid === jid && VideoLayout.isLargeVideoOnTop()) {
|
2014-10-31 11:47:12 +00:00
|
|
|
setVisibility($("#largeVideo"), !show);
|
2014-12-12 09:32:16 +00:00
|
|
|
setVisibility($('#activeSpeaker'), show);
|
2014-10-31 11:47:12 +00:00
|
|
|
setVisibility(avatar, false);
|
|
|
|
setVisibility(video, false);
|
|
|
|
} else {
|
|
|
|
if (video && video.length > 0) {
|
|
|
|
setVisibility(video, !show);
|
|
|
|
setVisibility(avatar, show);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Updates the src of the active speaker avatar
|
|
|
|
* @param jid of the current active speaker
|
|
|
|
*/
|
|
|
|
my.updateActiveSpeakerAvatarSrc = function(jid) {
|
|
|
|
if(!jid) {
|
2014-12-04 16:03:45 +00:00
|
|
|
jid = connection.emuc.findJidFromResource(
|
|
|
|
VideoLayout.getLargeVideoState().userResourceJid);
|
2014-10-31 11:47:12 +00:00
|
|
|
}
|
|
|
|
var avatar = $("#activeSpeakerAvatar")[0];
|
|
|
|
var url = getGravatarUrl(users[jid],
|
|
|
|
interfaceConfig.ACTIVE_SPEAKER_AVATAR_SIZE);
|
|
|
|
if(jid === activeSpeakerJid && avatar.src === url) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
activeSpeakerJid = jid;
|
|
|
|
var isMuted = isUserMuted(jid);
|
|
|
|
if(jid && isMuted !== null) {
|
|
|
|
avatar.src = url;
|
|
|
|
setVisibility($("#largeVideo"), !isMuted);
|
|
|
|
Avatar.showUserAvatar(jid, isMuted);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
function setVisibility(selector, show) {
|
|
|
|
if (selector && selector.length > 0) {
|
|
|
|
selector.css("visibility", show ? "visible" : "hidden");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function isUserMuted(jid) {
|
2014-11-27 18:28:28 +00:00
|
|
|
// XXX(gp) we may want to rename this method to something like
|
|
|
|
// isUserStreaming, for example.
|
|
|
|
if (jid && jid != connection.emuc.myroomjid) {
|
|
|
|
var resource = Strophe.getResourceFromJid(jid);
|
|
|
|
if (!VideoLayout.isInLastN(resource)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-19 13:59:08 +00:00
|
|
|
if (!RTC.remoteStreams[jid] || !RTC.remoteStreams[jid][MediaStreamType.VIDEO_TYPE]) {
|
2014-10-31 11:47:12 +00:00
|
|
|
return null;
|
|
|
|
}
|
2014-12-19 13:59:08 +00:00
|
|
|
return RTC.remoteStreams[jid][MediaStream.VIDEO_TYPE].muted;
|
2014-10-31 11:47:12 +00:00
|
|
|
}
|
|
|
|
|
2014-11-27 16:14:43 +00:00
|
|
|
function getGravatarUrl(id, size) {
|
2014-11-27 16:27:31 +00:00
|
|
|
if(id === connection.emuc.myroomjid || !id) {
|
2014-11-27 16:14:43 +00:00
|
|
|
id = SettingsMenu.getUID();
|
|
|
|
}
|
2014-10-31 11:47:12 +00:00
|
|
|
return 'https://www.gravatar.com/avatar/' +
|
2014-11-27 16:14:43 +00:00
|
|
|
MD5.hexdigest(id.trim().toLowerCase()) +
|
2014-12-12 12:18:36 +00:00
|
|
|
"?d=wavatar&size=" + (size || "30");
|
2014-10-31 11:47:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return my;
|
|
|
|
}(Avatar || {}));
|