Browse Source

feat(branding): Add custom avatar backgrounds

master
hmuresan 3 years ago
parent
commit
2bac757ca6

+ 6
- 0
modules/API/API.js View File

574
             });
574
             });
575
             break;
575
             break;
576
         }
576
         }
577
+        case 'get-custom-avatar-backgrounds' : {
578
+            callback({
579
+                avatarBackgrounds: APP.store.getState()['features/dynamic-branding'].avatarBackgrounds
580
+            });
581
+            break;
582
+        }
577
         default:
583
         default:
578
             return false;
584
             return false;
579
         }
585
         }

+ 11
- 0
modules/API/external/external_api.js View File

769
         return getCurrentDevices(this._transport);
769
         return getCurrentDevices(this._transport);
770
     }
770
     }
771
 
771
 
772
+    /**
773
+     * Returns any custom avatars backgrounds.
774
+     *
775
+     * @returns {Promise} - Resolves with the list of custom avatar backgrounds.
776
+     */
777
+    getCustomAvatarBackgrounds() {
778
+        return this._transport.sendRequest({
779
+            name: 'get-custom-avatar-backgrounds'
780
+        });
781
+    }
782
+
772
     /**
783
     /**
773
      * Returns the current livestream url.
784
      * Returns the current livestream url.
774
      *
785
      *

+ 17
- 2
react/features/always-on-top/AlwaysOnTop.js View File

21
  */
21
  */
22
 type State = {
22
 type State = {
23
     avatarURL: string,
23
     avatarURL: string,
24
+    customAvatarBackgrounds: Array<string>,
24
     displayName: string,
25
     displayName: string,
25
     formattedDisplayName: string,
26
     formattedDisplayName: string,
26
     isVideoDisplayed: boolean,
27
     isVideoDisplayed: boolean,
48
 
49
 
49
         this.state = {
50
         this.state = {
50
             avatarURL: '',
51
             avatarURL: '',
52
+            customAvatarBackgrounds: [],
51
             displayName: '',
53
             displayName: '',
52
             formattedDisplayName: '',
54
             formattedDisplayName: '',
53
             isVideoDisplayed: true,
55
             isVideoDisplayed: true,
178
      * @returns {ReactElement}
180
      * @returns {ReactElement}
179
      */
181
      */
180
     _renderVideoNotAvailableScreen() {
182
     _renderVideoNotAvailableScreen() {
181
-        const { avatarURL, displayName, formattedDisplayName, isVideoDisplayed, userID } = this.state;
183
+        const {
184
+            avatarURL,
185
+            customAvatarBackgrounds,
186
+            displayName,
187
+            formattedDisplayName,
188
+            isVideoDisplayed,
189
+            userID
190
+        } = this.state;
182
 
191
 
183
         if (isVideoDisplayed) {
192
         if (isVideoDisplayed) {
184
             return null;
193
             return null;
188
             <div id = 'videoNotAvailableScreen'>
197
             <div id = 'videoNotAvailableScreen'>
189
                 <div id = 'avatarContainer'>
198
                 <div id = 'avatarContainer'>
190
                     <StatelessAvatar
199
                     <StatelessAvatar
191
-                        color = { getAvatarColor(userID) }
200
+                        color = { getAvatarColor(userID, customAvatarBackgrounds) }
192
                         id = 'avatar'
201
                         id = 'avatar'
193
                         initials = { getInitials(displayName) }
202
                         initials = { getInitials(displayName) }
194
                         url = { avatarURL } />)
203
                         url = { avatarURL } />)
218
         window.addEventListener('mousemove', this._mouseMove);
227
         window.addEventListener('mousemove', this._mouseMove);
219
 
228
 
220
         this._hideToolbarAfterTimeout();
229
         this._hideToolbarAfterTimeout();
230
+        api.getCustomAvatarBackgrounds()
231
+            .then(res =>
232
+                this.setState({
233
+                    customAvatarBackgrounds: res.avatarBackgrounds || []
234
+                }))
235
+            .catch(console.error);
221
     }
236
     }
222
 
237
 
223
     /**
238
     /**

+ 8
- 1
react/features/base/avatar/components/Avatar.js View File

10
 
10
 
11
 export type Props = {
11
 export type Props = {
12
 
12
 
13
+    /**
14
+     * Custom avatar backgrounds from branding.
15
+     */
16
+    _customAvatarBackgrounds: Array<string>,
17
+
13
     /**
18
     /**
14
      * The string we base the initials on (this is generated from a list of precedences).
19
      * The string we base the initials on (this is generated from a list of precedences).
15
      */
20
      */
133
      */
138
      */
134
     render() {
139
     render() {
135
         const {
140
         const {
141
+            _customAvatarBackgrounds,
136
             _initialsBase,
142
             _initialsBase,
137
             _loadableAvatarUrl,
143
             _loadableAvatarUrl,
138
             className,
144
             className,
172
 
178
 
173
         if (initials) {
179
         if (initials) {
174
             if (dynamicColor) {
180
             if (dynamicColor) {
175
-                avatarProps.color = getAvatarColor(colorBase || _initialsBase);
181
+                avatarProps.color = getAvatarColor(colorBase || _initialsBase, _customAvatarBackgrounds);
176
             }
182
             }
177
 
183
 
178
             avatarProps.initials = initials;
184
             avatarProps.initials = initials;
211
     const _initialsBase = _participant?.name ?? displayName;
217
     const _initialsBase = _participant?.name ?? displayName;
212
 
218
 
213
     return {
219
     return {
220
+        _customAvatarBackgrounds: state['features/dynamic-branding'].avatarBackgrounds,
214
         _initialsBase,
221
         _initialsBase,
215
         _loadableAvatarUrl: _participant?.loadableAvatarUrl,
222
         _loadableAvatarUrl: _participant?.loadableAvatarUrl,
216
         colorBase: !colorBase && _participant ? _participant.id : colorBase
223
         colorBase: !colorBase && _participant ? _participant.id : colorBase

+ 1
- 1
react/features/base/avatar/components/web/StatelessAvatar.js View File

125
         const { size } = this.props;
125
         const { size } = this.props;
126
 
126
 
127
         return {
127
         return {
128
-            backgroundColor: color || undefined,
128
+            background: color || undefined,
129
             fontSize: size ? size * 0.5 : '180%',
129
             fontSize: size ? size * 0.5 : '180%',
130
             height: size || '100%',
130
             height: size || '100%',
131
             width: size || '100%'
131
             width: size || '100%'

+ 7
- 3
react/features/base/avatar/functions.js View File

16
  * Generates the background color of an initials based avatar.
16
  * Generates the background color of an initials based avatar.
17
  *
17
  *
18
  * @param {string?} initials - The initials of the avatar.
18
  * @param {string?} initials - The initials of the avatar.
19
+ * @param {Array<strig>} customAvatarBackgrounds - Custom avatar background values.
19
  * @returns {string}
20
  * @returns {string}
20
  */
21
  */
21
-export function getAvatarColor(initials: ?string) {
22
+export function getAvatarColor(initials: ?string, customAvatarBackgrounds: Array<string>) {
23
+    const hasCustomAvatarBackgronds = customAvatarBackgrounds && customAvatarBackgrounds.length;
24
+    const colorsBase = hasCustomAvatarBackgronds ? customAvatarBackgrounds : AVATAR_COLORS;
25
+
22
     let colorIndex = 0;
26
     let colorIndex = 0;
23
 
27
 
24
     if (initials) {
28
     if (initials) {
28
             nameHash += s.codePointAt(0);
32
             nameHash += s.codePointAt(0);
29
         }
33
         }
30
 
34
 
31
-        colorIndex = nameHash % AVATAR_COLORS.length;
35
+        colorIndex = nameHash % colorsBase.length;
32
     }
36
     }
33
 
37
 
34
-    return `rgba(${AVATAR_COLORS[colorIndex]}, ${AVATAR_OPACITY})`;
38
+    return hasCustomAvatarBackgronds ? colorsBase[colorIndex] : `rgba(${colorsBase[colorIndex]}, ${AVATAR_OPACITY})`;
35
 }
39
 }
36
 
40
 
37
 /**
41
 /**

+ 12
- 1
react/features/dynamic-branding/reducer.js View File

15
 const STORE_NAME = 'features/dynamic-branding';
15
 const STORE_NAME = 'features/dynamic-branding';
16
 
16
 
17
 const DEFAULT_STATE = {
17
 const DEFAULT_STATE = {
18
+
19
+    /**
20
+     * The pool of avatar backgrounds.
21
+     *
22
+     * @public
23
+     * @type {Array<string>}
24
+     */
25
+    avatarBackgrounds: [],
26
+
18
     /**
27
     /**
19
      * The custom background color for the LargeVideo.
28
      * The custom background color for the LargeVideo.
20
      *
29
      *
112
             didPageUrl,
121
             didPageUrl,
113
             inviteDomain,
122
             inviteDomain,
114
             logoClickUrl,
123
             logoClickUrl,
115
-            logoImageUrl
124
+            logoImageUrl,
125
+            avatarBackgrounds
116
         } = action.value;
126
         } = action.value;
117
 
127
 
118
         return {
128
         return {
129
+            avatarBackgrounds,
119
             backgroundColor,
130
             backgroundColor,
120
             backgroundImageUrl,
131
             backgroundImageUrl,
121
             defaultBranding,
132
             defaultBranding,

Loading…
Cancel
Save