diff --git a/public/css/VideoGrid.css b/public/css/VideoGrid.css index 7c17bae4..6e3d5fa7 100644 --- a/public/css/VideoGrid.css +++ b/public/css/VideoGrid.css @@ -66,6 +66,15 @@ background: rgba(0, 0, 0, 0.4); } +.videoAvatarImage { + z-index: 7; + position: absolute; + display: none; + width: var(--vmi-wh); + height: var(--vmi-wh); + border-radius: 50%; +} + .audio { position: absolute; right: 0; @@ -106,13 +115,6 @@ background: rgba(0, 0, 0, 0.1); } -#videoMediaContainer img { - position: absolute; - display: none; - width: var(--vmi-wh); - height: var(--vmi-wh); -} - .videoMenuBar { z-index: 2; position: absolute; diff --git a/public/js/Room.js b/public/js/Room.js index c807d0a8..f17853d4 100644 --- a/public/js/Room.js +++ b/public/js/Room.js @@ -2193,7 +2193,7 @@ async function getParticipantsTable(peers) { if (rc.peer_id === peer_id) { table += ` - + ${peer_name} (me) @@ -2208,7 +2208,7 @@ async function getParticipantsTable(peers) { if (isRulesActive && isPresenter) { table += ` - + ${peer_name} @@ -2222,7 +2222,7 @@ async function getParticipantsTable(peers) { } else { table += ` - + ${peer_name} @@ -2269,7 +2269,7 @@ function refreshParticipantsCount(count, adapt = true) { } function getParticipantAvatar(peerName) { - return cfg.msgAvatar + '?name=' + peerName + '&size=32' + '&background=random&rounded=true'; + return rc.genAvatarSvg(peerName, 32); } // #################################################### diff --git a/public/js/RoomClient.js b/public/js/RoomClient.js index 89596a40..cba65151 100644 --- a/public/js/RoomClient.js +++ b/public/js/RoomClient.js @@ -14,8 +14,7 @@ */ const cfg = { - useAvatarApi: true, - msgAvatar: 'https://eu.ui-avatars.com/api', + useAvatarSvg: true, }; const html = { @@ -1859,7 +1858,7 @@ class RoomClient { ko.className = html.kickOut; } i = document.createElement('img'); - i.className = 'center'; // pulsate + i.className = 'videoAvatarImage center'; // pulsate i.id = peer_id + '__img'; p = document.createElement('p'); p.id = peer_id + '__name'; @@ -2065,17 +2064,54 @@ class RoomClient { setVideoAvatarImgName(elemId, peer_name) { let elem = this.getId(elemId); - if (cfg.useAvatarApi) { - let avatarImgSize = 250; - elem.setAttribute( - 'src', - cfg.msgAvatar + '?name=' + peer_name + '&size=' + avatarImgSize + '&background=random&rounded=true', - ); + if (cfg.useAvatarSvg) { + elem.setAttribute('src', this.genAvatarSvg(peer_name, 250)); } else { elem.setAttribute('src', image.avatar); } } + genAvatarSvg(peerName, avatarImgSize) { + const charCodeRed = peerName.charCodeAt(0); + const charCodeGreen = peerName.charCodeAt(1) || charCodeRed; + const red = Math.pow(charCodeRed, 7) % 200; + const green = Math.pow(charCodeGreen, 7) % 200; + const blue = (red + green) % 200; + const bgColor = `rgb(${red}, ${green}, ${blue})`; + const textColor = '#ffffff'; + const svg = ` + + + ${peerName.substring(0, 2).toUpperCase()} + + `; + return 'data:image/svg+xml,' + svg.replace(/#/g, '%23').replace(/"/g, "'").replace(/&/g, '&'); + } + setIsAudio(peer_id, status) { this.peer_info.peer_audio = status; let b = this.getPeerAudioBtn(peer_id); @@ -2759,7 +2795,7 @@ class RoomClient { } setMsgAvatar(avatar, peerName) { - let avatarImg = cfg.msgAvatar + '?name=' + peerName + '&size=32' + '&background=random&rounded=true'; + let avatarImg = this.genAvatarSvg(peerName, 32); avatar === 'left' ? (this.leftMsgAvatar = avatarImg) : (this.rightMsgAvatar = avatarImg); } @@ -2770,7 +2806,7 @@ class RoomClient { let message = toId == 'all' ? msg : msg + replyMsg; let msgHTML = `
-
+
${fromName}