Browse Source

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

j8
hristoterezov 8 years ago
parent
commit
d74e43ddcc

+ 10
- 7
conference.js View File

21
 import EventEmitter from "events";
21
 import EventEmitter from "events";
22
 
22
 
23
 import {
23
 import {
24
-    conferenceJoined,
24
+    AVATAR_ID_COMMAND,
25
+    AVATAR_URL_COMMAND,
25
     conferenceFailed,
26
     conferenceFailed,
26
-    conferenceLeft
27
+    conferenceJoined,
28
+    conferenceLeft,
29
+    EMAIL_COMMAND
27
 } from './react/features/base/conference';
30
 } from './react/features/base/conference';
28
 import {
31
 import {
29
     isFatalJitsiConnectionError
32
     isFatalJitsiConnectionError
67
  * Known custom conference commands.
70
  * Known custom conference commands.
68
  */
71
  */
69
 const commands = {
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
     ETHERPAD: "etherpad",
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 View File

3
 
3
 
4
 import UIUtil from '../UI/util/UIUtil';
4
 import UIUtil from '../UI/util/UIUtil';
5
 import jitsiLocalStorage from '../util/JitsiLocalStorage';
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
 let avatarUrl = '';
8
 let avatarUrl = '';
15
 
9
 
17
 let avatarId = UIUtil.unescapeHtml(jitsiLocalStorage.getItem("avatarId") || '');
11
 let avatarId = UIUtil.unescapeHtml(jitsiLocalStorage.getItem("avatarId") || '');
18
 if (!avatarId) {
12
 if (!avatarId) {
19
     // if there is no avatar id, we generate a unique one and use it forever
13
     // if there is no avatar id, we generate a unique one and use it forever
20
-    avatarId = generateUniqueId();
14
+    avatarId = randomHexString(32);
21
     jitsiLocalStorage.setItem("avatarId", avatarId);
15
     jitsiLocalStorage.setItem("avatarId", avatarId);
22
 }
16
 }
23
 
17
 

+ 33
- 1
react/features/base/conference/actions.js View File

1
 import { JitsiConferenceEvents } from '../lib-jitsi-meet';
1
 import { JitsiConferenceEvents } from '../lib-jitsi-meet';
2
 import {
2
 import {
3
+    changeParticipantAvatarID,
4
+    changeParticipantAvatarURL,
3
     changeParticipantEmail,
5
     changeParticipantEmail,
4
     dominantSpeakerChanged,
6
     dominantSpeakerChanged,
7
+    getLocalParticipant,
5
     participantJoined,
8
     participantJoined,
6
     participantLeft,
9
     participantLeft,
7
     participantRoleChanged
10
     participantRoleChanged
18
     SET_PASSWORD,
21
     SET_PASSWORD,
19
     SET_ROOM
22
     SET_ROOM
20
 } from './actionTypes';
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
 import { _addLocalTracksToConference } from './functions';
29
 import { _addLocalTracksToConference } from './functions';
23
 
30
 
24
 /**
31
 /**
69
             JitsiConferenceEvents.USER_ROLE_CHANGED,
76
             JitsiConferenceEvents.USER_ROLE_CHANGED,
70
             (...args) => dispatch(participantRoleChanged(...args)));
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
     conference.addCommandListener(
85
     conference.addCommandListener(
73
             EMAIL_COMMAND,
86
             EMAIL_COMMAND,
74
             (data, id) => dispatch(changeParticipantEmail(id, data.value)));
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
  * Signals that a specific conference has failed.
108
  * Signals that a specific conference has failed.
79
  *
109
  *
217
 
247
 
218
         _addConferenceListeners(conference, dispatch);
248
         _addConferenceListeners(conference, dispatch);
219
 
249
 
250
+        _setLocalParticipantData(conference, state);
251
+
220
         conference.join(password);
252
         conference.join(password);
221
     };
253
     };
222
 }
254
 }

+ 15
- 1
react/features/base/conference/constants.js View File

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
  * @type {string}
18
  * @type {string}
5
  */
19
  */

+ 1
- 0
react/features/base/conference/index.js View File

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

+ 7
- 7
react/features/base/participants/components/ParticipantView.native.js View File

10
 import { getTrackByMediaTypeAndParticipant } from '../../tracks';
10
 import { getTrackByMediaTypeAndParticipant } from '../../tracks';
11
 
11
 
12
 import Avatar from './Avatar';
12
 import Avatar from './Avatar';
13
-import { getParticipantById } from '../functions';
13
+import { getAvatarURL, getParticipantById } from '../functions';
14
 import { styles } from './styles';
14
 import { styles } from './styles';
15
 
15
 
16
 /**
16
 /**
162
  * }}
162
  * }}
163
  */
163
  */
164
 function _mapStateToProps(state, ownProps) {
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
     return {
167
     return {
172
-        _avatar: participant ? participant.avatar : undefined,
168
+        _avatar:
169
+            getAvatarURL(
170
+                getParticipantById(
171
+                    state['features/base/participants'],
172
+                    participantId)),
173
         _videoTrack:
173
         _videoTrack:
174
             getTrackByMediaTypeAndParticipant(
174
             getTrackByMediaTypeAndParticipant(
175
                 state['features/base/tracks'],
175
                 state['features/base/tracks'],

+ 3
- 0
react/features/base/participants/functions.js View File

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

+ 15
- 24
react/features/base/participants/reducer.js View File

1
 import { ReducerRegistry, setStateProperty } from '../redux';
1
 import { ReducerRegistry, setStateProperty } from '../redux';
2
+import { randomHexString } from '../util';
2
 
3
 
3
 import {
4
 import {
4
     DOMINANT_SPEAKER_CHANGED,
5
     DOMINANT_SPEAKER_CHANGED,
12
     LOCAL_PARTICIPANT_DEFAULT_ID,
13
     LOCAL_PARTICIPANT_DEFAULT_ID,
13
     PARTICIPANT_ROLE
14
     PARTICIPANT_ROLE
14
 } from './constants';
15
 } from './constants';
15
-import { getAvatarURL } from './functions';
16
 
16
 
17
 /**
17
 /**
18
  * Participant object.
18
  * Participant object.
62
 
62
 
63
     case PARTICIPANT_ID_CHANGED:
63
     case PARTICIPANT_ID_CHANGED:
64
         if (state.id === action.oldValue) {
64
         if (state.id === action.oldValue) {
65
-            const id = action.newValue;
66
-            const newState = {
65
+            return {
67
                 ...state,
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
         break;
70
         break;
78
 
71
 
79
     case PARTICIPANT_JOINED: {
72
     case PARTICIPANT_JOINED: {
80
         const participant = action.participant; // eslint-disable-line no-shadow
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
             = participant;
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
         // id
85
         // id
86
         //
86
         //
97
             name = local ? 'me' : 'Fellow Jitster';
97
             name = local ? 'me' : 'Fellow Jitster';
98
         }
98
         }
99
 
99
 
100
-        const newState = {
101
-            avatar,
100
+        return {
101
+            avatarID,
102
+            avatarURL,
102
             dominantSpeaker: dominantSpeaker || false,
103
             dominantSpeaker: dominantSpeaker || false,
103
             email,
104
             email,
104
             id,
105
             id,
107
             pinned: pinned || false,
108
             pinned: pinned || false,
108
             role: role || PARTICIPANT_ROLE.NONE
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
     case PARTICIPANT_UPDATED: {
113
     case PARTICIPANT_UPDATED: {
130
                 }
125
                 }
131
             }
126
             }
132
 
127
 
133
-            if (!newState.avatar) {
134
-                newState.avatar = getAvatarURL(newState);
135
-            }
136
-
137
             return newState;
128
             return newState;
138
         }
129
         }
139
         break;
130
         break;

Loading…
Cancel
Save