Pārlūkot izejas kodu

[RN] fix(Avatar): Match the implementation for web

j8
hristoterezov 8 gadus atpakaļ
vecāks
revīzija
d74e43ddcc

+ 10
- 7
conference.js Parādīt failu

@@ -21,9 +21,12 @@ import analytics from './modules/analytics/analytics';
21 21
 import EventEmitter from "events";
22 22
 
23 23
 import {
24
-    conferenceJoined,
24
+    AVATAR_ID_COMMAND,
25
+    AVATAR_URL_COMMAND,
25 26
     conferenceFailed,
26
-    conferenceLeft
27
+    conferenceJoined,
28
+    conferenceLeft,
29
+    EMAIL_COMMAND
27 30
 } from './react/features/base/conference';
28 31
 import {
29 32
     isFatalJitsiConnectionError
@@ -67,12 +70,12 @@ import {VIDEO_CONTAINER_TYPE} from "./modules/UI/videolayout/VideoContainer";
67 70
  * Known custom conference commands.
68 71
  */
69 72
 const commands = {
70
-    EMAIL: "email",
71
-    AVATAR_URL: "avatar-url",
72
-    AVATAR_ID: "avatar-id",
73
+    AVATAR_ID: AVATAR_ID_COMMAND,
74
+    AVATAR_URL: AVATAR_URL_COMMAND,
75
+    CUSTOM_ROLE: "custom-role",
76
+    EMAIL: EMAIL_COMMAND,
73 77
     ETHERPAD: "etherpad",
74
-    SHARED_VIDEO: "shared-video",
75
-    CUSTOM_ROLE: "custom-role"
78
+    SHARED_VIDEO: "shared-video"
76 79
 };
77 80
 
78 81
 /**

+ 2
- 8
modules/settings/Settings.js Parādīt failu

@@ -3,13 +3,7 @@ const logger = require("jitsi-meet-logger").getLogger(__filename);
3 3
 
4 4
 import UIUtil from '../UI/util/UIUtil';
5 5
 import jitsiLocalStorage from '../util/JitsiLocalStorage';
6
-
7
-function generateUniqueId() {
8
-    function _p8() {
9
-        return (Math.random().toString(16) + "000000000").substr(2, 8);
10
-    }
11
-    return _p8() + _p8() + _p8() + _p8();
12
-}
6
+import { randomHexString } from '../../react/features/base/util';
13 7
 
14 8
 let avatarUrl = '';
15 9
 
@@ -17,7 +11,7 @@ let email = UIUtil.unescapeHtml(jitsiLocalStorage.getItem("email") || '');
17 11
 let avatarId = UIUtil.unescapeHtml(jitsiLocalStorage.getItem("avatarId") || '');
18 12
 if (!avatarId) {
19 13
     // if there is no avatar id, we generate a unique one and use it forever
20
-    avatarId = generateUniqueId();
14
+    avatarId = randomHexString(32);
21 15
     jitsiLocalStorage.setItem("avatarId", avatarId);
22 16
 }
23 17
 

+ 33
- 1
react/features/base/conference/actions.js Parādīt failu

@@ -1,7 +1,10 @@
1 1
 import { JitsiConferenceEvents } from '../lib-jitsi-meet';
2 2
 import {
3
+    changeParticipantAvatarID,
4
+    changeParticipantAvatarURL,
3 5
     changeParticipantEmail,
4 6
     dominantSpeakerChanged,
7
+    getLocalParticipant,
5 8
     participantJoined,
6 9
     participantLeft,
7 10
     participantRoleChanged
@@ -18,7 +21,11 @@ import {
18 21
     SET_PASSWORD,
19 22
     SET_ROOM
20 23
 } from './actionTypes';
21
-import { EMAIL_COMMAND } from './constants';
24
+import {
25
+    AVATAR_ID_COMMAND,
26
+    AVATAR_URL_COMMAND,
27
+    EMAIL_COMMAND
28
+} from './constants';
22 29
 import { _addLocalTracksToConference } from './functions';
23 30
 
24 31
 /**
@@ -69,11 +76,34 @@ function _addConferenceListeners(conference, dispatch) {
69 76
             JitsiConferenceEvents.USER_ROLE_CHANGED,
70 77
             (...args) => dispatch(participantRoleChanged(...args)));
71 78
 
79
+    conference.addCommandListener(
80
+            AVATAR_ID_COMMAND,
81
+            (data, id) => dispatch(changeParticipantAvatarID(id, data.value)));
82
+    conference.addCommandListener(
83
+            AVATAR_URL_COMMAND,
84
+            (data, id) => dispatch(changeParticipantAvatarURL(id, data.value)));
72 85
     conference.addCommandListener(
73 86
             EMAIL_COMMAND,
74 87
             (data, id) => dispatch(changeParticipantEmail(id, data.value)));
75 88
 }
76 89
 
90
+/**
91
+ * Sets the data for the local participant to the conference.
92
+ *
93
+ * @param {JitsiConference} conference - The JitsiConference instance.
94
+ * @param {Object} state - The Redux state.
95
+ * @returns {void}
96
+ */
97
+function _setLocalParticipantData(conference, state) {
98
+    const localParticipant
99
+        = getLocalParticipant(state['features/base/participants']);
100
+
101
+    conference.removeCommand(AVATAR_ID_COMMAND);
102
+    conference.sendCommand(AVATAR_ID_COMMAND, {
103
+        value: localParticipant.avatarID
104
+    });
105
+}
106
+
77 107
 /**
78 108
  * Signals that a specific conference has failed.
79 109
  *
@@ -217,6 +247,8 @@ export function createConference() {
217 247
 
218 248
         _addConferenceListeners(conference, dispatch);
219 249
 
250
+        _setLocalParticipantData(conference, state);
251
+
220 252
         conference.join(password);
221 253
     };
222 254
 }

+ 15
- 1
react/features/base/conference/constants.js Parādīt failu

@@ -1,5 +1,19 @@
1 1
 /**
2
- * The command type for updating a participant's email address.
2
+ * The command type for updating a participant's avatar ID.
3
+ *
4
+ * @type {string}
5
+ */
6
+export const AVATAR_ID_COMMAND = 'avatar-id';
7
+
8
+/**
9
+ * The command type for updating a participant's avatar URL.
10
+ *
11
+ * @type {string}
12
+ */
13
+export const AVATAR_URL_COMMAND = 'avatar-url';
14
+
15
+/**
16
+ * The command type for updating a participant's e-mail address.
3 17
  *
4 18
  * @type {string}
5 19
  */

+ 1
- 0
react/features/base/conference/index.js Parādīt failu

@@ -1,5 +1,6 @@
1 1
 export * from './actions';
2 2
 export * from './actionTypes';
3
+export * from './constants';
3 4
 export * from './functions';
4 5
 
5 6
 import './middleware';

+ 7
- 7
react/features/base/participants/components/ParticipantView.native.js Parādīt failu

@@ -10,7 +10,7 @@ import { Container } from '../../react';
10 10
 import { getTrackByMediaTypeAndParticipant } from '../../tracks';
11 11
 
12 12
 import Avatar from './Avatar';
13
-import { getParticipantById } from '../functions';
13
+import { getAvatarURL, getParticipantById } from '../functions';
14 14
 import { styles } from './styles';
15 15
 
16 16
 /**
@@ -162,14 +162,14 @@ function _toBoolean(value, undefinedValue) {
162 162
  * }}
163 163
  */
164 164
 function _mapStateToProps(state, ownProps) {
165
-    const participantId = ownProps.participantId;
166
-    const participant
167
-        = getParticipantById(
168
-            state['features/base/participants'],
169
-            participantId);
165
+    const { participantId } = ownProps;
170 166
 
171 167
     return {
172
-        _avatar: participant ? participant.avatar : undefined,
168
+        _avatar:
169
+            getAvatarURL(
170
+                getParticipantById(
171
+                    state['features/base/participants'],
172
+                    participantId)),
173 173
         _videoTrack:
174 174
             getTrackByMediaTypeAndParticipant(
175 175
                 state['features/base/tracks'],

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

@@ -44,6 +44,9 @@ export function getAvatarURL(participant) {
44 44
         // from a configured avatar service).
45 45
         if (!key) {
46 46
             key = id;
47
+            if (!key) {
48
+                return undefined;
49
+            }
47 50
         }
48 51
 
49 52
         // The deployment is allowed to choose the avatar service which is to

+ 15
- 24
react/features/base/participants/reducer.js Parādīt failu

@@ -1,4 +1,5 @@
1 1
 import { ReducerRegistry, setStateProperty } from '../redux';
2
+import { randomHexString } from '../util';
2 3
 
3 4
 import {
4 5
     DOMINANT_SPEAKER_CHANGED,
@@ -12,7 +13,6 @@ import {
12 13
     LOCAL_PARTICIPANT_DEFAULT_ID,
13 14
     PARTICIPANT_ROLE
14 15
 } from './constants';
15
-import { getAvatarURL } from './functions';
16 16
 
17 17
 /**
18 18
  * Participant object.
@@ -62,25 +62,25 @@ function _participant(state, action) {
62 62
 
63 63
     case PARTICIPANT_ID_CHANGED:
64 64
         if (state.id === action.oldValue) {
65
-            const id = action.newValue;
66
-            const newState = {
65
+            return {
67 66
                 ...state,
68
-                id
67
+                id: action.newValue
69 68
             };
70
-
71
-            if (!newState.avatar) {
72
-                newState.avatar = getAvatarURL(newState);
73
-            }
74
-
75
-            return newState;
76 69
         }
77 70
         break;
78 71
 
79 72
     case PARTICIPANT_JOINED: {
80 73
         const participant = action.participant; // eslint-disable-line no-shadow
81
-        const { avatar, dominantSpeaker, email, local, pinned, role }
74
+        const { avatarURL, dominantSpeaker, email, local, pinned, role }
82 75
             = participant;
83
-        let { id, name } = participant;
76
+        let { avatarID, id, name } = participant;
77
+
78
+        // avatarID
79
+        //
80
+        // TODO Get the avatarID of the local participant from localStorage.
81
+        if (!avatarID && local) {
82
+            avatarID = randomHexString(32);
83
+        }
84 84
 
85 85
         // id
86 86
         //
@@ -97,8 +97,9 @@ function _participant(state, action) {
97 97
             name = local ? 'me' : 'Fellow Jitster';
98 98
         }
99 99
 
100
-        const newState = {
101
-            avatar,
100
+        return {
101
+            avatarID,
102
+            avatarURL,
102 103
             dominantSpeaker: dominantSpeaker || false,
103 104
             email,
104 105
             id,
@@ -107,12 +108,6 @@ function _participant(state, action) {
107 108
             pinned: pinned || false,
108 109
             role: role || PARTICIPANT_ROLE.NONE
109 110
         };
110
-
111
-        if (!newState.avatar) {
112
-            newState.avatar = getAvatarURL(newState);
113
-        }
114
-
115
-        return newState;
116 111
     }
117 112
 
118 113
     case PARTICIPANT_UPDATED: {
@@ -130,10 +125,6 @@ function _participant(state, action) {
130 125
                 }
131 126
             }
132 127
 
133
-            if (!newState.avatar) {
134
-                newState.avatar = getAvatarURL(newState);
135
-            }
136
-
137 128
             return newState;
138 129
         }
139 130
         break;

Notiek ielāde…
Atcelt
Saglabāt