Pārlūkot izejas kodu

feat(branding): Add custom avatar backgrounds

master
hmuresan 3 gadus atpakaļ
vecāks
revīzija
2bac757ca6

+ 6
- 0
modules/API/API.js Parādīt failu

@@ -574,6 +574,12 @@ function initCommands() {
574 574
             });
575 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 583
         default:
578 584
             return false;
579 585
         }

+ 11
- 0
modules/API/external/external_api.js Parādīt failu

@@ -769,6 +769,17 @@ export default class JitsiMeetExternalAPI extends EventEmitter {
769 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 784
      * Returns the current livestream url.
774 785
      *

+ 17
- 2
react/features/always-on-top/AlwaysOnTop.js Parādīt failu

@@ -21,6 +21,7 @@ const TOOLBAR_TIMEOUT = 4000;
21 21
  */
22 22
 type State = {
23 23
     avatarURL: string,
24
+    customAvatarBackgrounds: Array<string>,
24 25
     displayName: string,
25 26
     formattedDisplayName: string,
26 27
     isVideoDisplayed: boolean,
@@ -48,6 +49,7 @@ export default class AlwaysOnTop extends Component<*, State> {
48 49
 
49 50
         this.state = {
50 51
             avatarURL: '',
52
+            customAvatarBackgrounds: [],
51 53
             displayName: '',
52 54
             formattedDisplayName: '',
53 55
             isVideoDisplayed: true,
@@ -178,7 +180,14 @@ export default class AlwaysOnTop extends Component<*, State> {
178 180
      * @returns {ReactElement}
179 181
      */
180 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 192
         if (isVideoDisplayed) {
184 193
             return null;
@@ -188,7 +197,7 @@ export default class AlwaysOnTop extends Component<*, State> {
188 197
             <div id = 'videoNotAvailableScreen'>
189 198
                 <div id = 'avatarContainer'>
190 199
                     <StatelessAvatar
191
-                        color = { getAvatarColor(userID) }
200
+                        color = { getAvatarColor(userID, customAvatarBackgrounds) }
192 201
                         id = 'avatar'
193 202
                         initials = { getInitials(displayName) }
194 203
                         url = { avatarURL } />)
@@ -218,6 +227,12 @@ export default class AlwaysOnTop extends Component<*, State> {
218 227
         window.addEventListener('mousemove', this._mouseMove);
219 228
 
220 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 Parādīt failu

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

+ 1
- 1
react/features/base/avatar/components/web/StatelessAvatar.js Parādīt failu

@@ -125,7 +125,7 @@ export default class StatelessAvatar extends AbstractStatelessAvatar<Props> {
125 125
         const { size } = this.props;
126 126
 
127 127
         return {
128
-            backgroundColor: color || undefined,
128
+            background: color || undefined,
129 129
             fontSize: size ? size * 0.5 : '180%',
130 130
             height: size || '100%',
131 131
             width: size || '100%'

+ 7
- 3
react/features/base/avatar/functions.js Parādīt failu

@@ -16,9 +16,13 @@ const AVATAR_OPACITY = 0.4;
16 16
  * Generates the background color of an initials based avatar.
17 17
  *
18 18
  * @param {string?} initials - The initials of the avatar.
19
+ * @param {Array<strig>} customAvatarBackgrounds - Custom avatar background values.
19 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 26
     let colorIndex = 0;
23 27
 
24 28
     if (initials) {
@@ -28,10 +32,10 @@ export function getAvatarColor(initials: ?string) {
28 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 Parādīt failu

@@ -15,6 +15,15 @@ import {
15 15
 const STORE_NAME = 'features/dynamic-branding';
16 16
 
17 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 28
      * The custom background color for the LargeVideo.
20 29
      *
@@ -112,10 +121,12 @@ ReducerRegistry.register(STORE_NAME, (state = DEFAULT_STATE, action) => {
112 121
             didPageUrl,
113 122
             inviteDomain,
114 123
             logoClickUrl,
115
-            logoImageUrl
124
+            logoImageUrl,
125
+            avatarBackgrounds
116 126
         } = action.value;
117 127
 
118 128
         return {
129
+            avatarBackgrounds,
119 130
             backgroundColor,
120 131
             backgroundImageUrl,
121 132
             defaultBranding,

Notiek ielāde…
Atcelt
Saglabāt