浏览代码

ref(conference.js): unify "user joined/left" handling on web and RN

Extracts methods which share the common logic. There are still some
leftovers on the web side left which are not used on RN. But this can be
a first step.
master
paweldomas 7 年前
父节点
当前提交
6dea107bcd
共有 3 个文件被更改,包括 76 次插入32 次删除
  1. 9
    19
      conference.js
  2. 4
    12
      react/features/base/conference/actions.js
  3. 63
    1
      react/features/base/conference/functions.js

+ 9
- 19
conference.js 查看文件

31
 import {
31
 import {
32
     AVATAR_ID_COMMAND,
32
     AVATAR_ID_COMMAND,
33
     AVATAR_URL_COMMAND,
33
     AVATAR_URL_COMMAND,
34
+    EMAIL_COMMAND,
34
     authStatusChanged,
35
     authStatusChanged,
36
+    commonUserJoinedHandling,
37
+    commonUserLeftHandling,
35
     conferenceFailed,
38
     conferenceFailed,
36
     conferenceJoined,
39
     conferenceJoined,
37
     conferenceLeft,
40
     conferenceLeft,
38
     conferenceWillJoin,
41
     conferenceWillJoin,
39
     conferenceWillLeave,
42
     conferenceWillLeave,
40
     dataChannelOpened,
43
     dataChannelOpened,
41
-    EMAIL_COMMAND,
42
     lockStateChanged,
44
     lockStateChanged,
43
     onStartMutedPolicyChanged,
45
     onStartMutedPolicyChanged,
44
     p2pStatusChanged,
46
     p2pStatusChanged,
75
     getAvatarURLByParticipantId,
77
     getAvatarURLByParticipantId,
76
     getLocalParticipant,
78
     getLocalParticipant,
77
     getParticipantById,
79
     getParticipantById,
78
-    hiddenParticipantJoined,
79
-    hiddenParticipantLeft,
80
     localParticipantConnectionStatusChanged,
80
     localParticipantConnectionStatusChanged,
81
     localParticipantRoleChanged,
81
     localParticipantRoleChanged,
82
     MAX_DISPLAY_NAME_LENGTH,
82
     MAX_DISPLAY_NAME_LENGTH,
83
     participantConnectionStatusChanged,
83
     participantConnectionStatusChanged,
84
-    participantJoined,
85
-    participantLeft,
86
     participantPresenceChanged,
84
     participantPresenceChanged,
87
     participantRoleChanged,
85
     participantRoleChanged,
88
     participantUpdated
86
     participantUpdated
1694
         room.on(JitsiConferenceEvents.PARTCIPANT_FEATURES_CHANGED,
1692
         room.on(JitsiConferenceEvents.PARTCIPANT_FEATURES_CHANGED,
1695
             user => APP.UI.onUserFeaturesChanged(user));
1693
             user => APP.UI.onUserFeaturesChanged(user));
1696
         room.on(JitsiConferenceEvents.USER_JOINED, (id, user) => {
1694
         room.on(JitsiConferenceEvents.USER_JOINED, (id, user) => {
1697
-            const displayName = user.getDisplayName();
1695
+            // The logic shared between RN and web.
1696
+            commonUserJoinedHandling(APP.store, room, user);
1698
 
1697
 
1699
             if (user.isHidden()) {
1698
             if (user.isHidden()) {
1700
-                APP.store.dispatch(hiddenParticipantJoined(id, displayName));
1701
-
1702
                 return;
1699
                 return;
1703
             }
1700
             }
1704
 
1701
 
1705
-            APP.store.dispatch(participantJoined({
1706
-                botType: user.getBotType(),
1707
-                conference: room,
1708
-                id,
1709
-                name: displayName,
1710
-                presence: user.getStatus(),
1711
-                role: user.getRole()
1712
-            }));
1702
+            const displayName = user.getDisplayName();
1713
 
1703
 
1714
             logger.log(`USER ${id} connnected:`, user);
1704
             logger.log(`USER ${id} connnected:`, user);
1715
             APP.API.notifyUserJoined(id, {
1705
             APP.API.notifyUserJoined(id, {
1724
         });
1714
         });
1725
 
1715
 
1726
         room.on(JitsiConferenceEvents.USER_LEFT, (id, user) => {
1716
         room.on(JitsiConferenceEvents.USER_LEFT, (id, user) => {
1727
-            if (user.isHidden()) {
1728
-                APP.store.dispatch(hiddenParticipantLeft(id));
1717
+            // The logic shared between RN and web.
1718
+            commonUserLeftHandling(APP.store, room, user);
1729
 
1719
 
1720
+            if (user.isHidden()) {
1730
                 return;
1721
                 return;
1731
             }
1722
             }
1732
 
1723
 
1733
-            APP.store.dispatch(participantLeft(id, room));
1734
             logger.log(`USER ${id} LEFT:`, user);
1724
             logger.log(`USER ${id} LEFT:`, user);
1735
             APP.API.notifyUserLeft(id);
1725
             APP.API.notifyUserLeft(id);
1736
             APP.UI.messageHandler.participantNotification(
1726
             APP.UI.messageHandler.participantNotification(

+ 4
- 12
react/features/base/conference/actions.js 查看文件

13
     MAX_DISPLAY_NAME_LENGTH,
13
     MAX_DISPLAY_NAME_LENGTH,
14
     dominantSpeakerChanged,
14
     dominantSpeakerChanged,
15
     participantConnectionStatusChanged,
15
     participantConnectionStatusChanged,
16
-    participantJoined,
17
-    participantLeft,
18
     participantPresenceChanged,
16
     participantPresenceChanged,
19
     participantRoleChanged,
17
     participantRoleChanged,
20
     participantUpdated
18
     participantUpdated
52
 } from './constants';
50
 } from './constants';
53
 import {
51
 import {
54
     _addLocalTracksToConference,
52
     _addLocalTracksToConference,
53
+    commonUserJoinedHandling,
54
+    commonUserLeftHandling,
55
     getCurrentConference,
55
     getCurrentConference,
56
     sendLocalParticipant
56
     sendLocalParticipant
57
 } from './functions';
57
 } from './functions';
143
 
143
 
144
     conference.on(
144
     conference.on(
145
         JitsiConferenceEvents.USER_JOINED,
145
         JitsiConferenceEvents.USER_JOINED,
146
-        (id, user) => !user.isHidden() && dispatch(participantJoined({
147
-            botType: user.getBotType(),
148
-            conference,
149
-            id,
150
-            name: user.getDisplayName(),
151
-            presence: user.getStatus(),
152
-            role: user.getRole()
153
-        })));
146
+        (id, user) => commonUserJoinedHandling({ dispatch }, conference, user));
154
     conference.on(
147
     conference.on(
155
         JitsiConferenceEvents.USER_LEFT,
148
         JitsiConferenceEvents.USER_LEFT,
156
-        (id, user) => !user.isHidden()
157
-            && dispatch(participantLeft(id, conference)));
149
+        (id, user) => commonUserLeftHandling({ dispatch }, conference, user));
158
     conference.on(
150
     conference.on(
159
         JitsiConferenceEvents.USER_ROLE_CHANGED,
151
         JitsiConferenceEvents.USER_ROLE_CHANGED,
160
         (...args) => dispatch(participantRoleChanged(...args)));
152
         (...args) => dispatch(participantRoleChanged(...args)));

+ 63
- 1
react/features/base/conference/functions.js 查看文件

1
 // @flow
1
 // @flow
2
 
2
 
3
 import { JitsiTrackErrors } from '../lib-jitsi-meet';
3
 import { JitsiTrackErrors } from '../lib-jitsi-meet';
4
-import { getLocalParticipant } from '../participants';
4
+import {
5
+    getLocalParticipant,
6
+    hiddenParticipantJoined,
7
+    hiddenParticipantLeft,
8
+    participantJoined,
9
+    participantLeft
10
+} from '../participants';
5
 import { toState } from '../redux';
11
 import { toState } from '../redux';
6
 
12
 
7
 import {
13
 import {
44
     return Promise.all(promises);
50
     return Promise.all(promises);
45
 }
51
 }
46
 
52
 
53
+/**
54
+ * Logic shared between web and RN which processes the {@code USER_JOINED}
55
+ * conference event and dispatches either {@link participantJoined} or
56
+ * {@link hiddenParticipantJoined}.
57
+ *
58
+ * @param {Object} store - The redux store.
59
+ * @param {JitsiMeetConference} conference - The conference for which the
60
+ * {@code USER_JOINED} event is being processed.
61
+ * @param {JitsiParticipant} user - The user who has just joined.
62
+ * @returns {void}
63
+ */
64
+export function commonUserJoinedHandling(
65
+        { dispatch }: Object,
66
+        conference: Object,
67
+        user: Object) {
68
+    const id = user.getId();
69
+    const displayName = user.getDisplayName();
70
+
71
+    if (user.isHidden()) {
72
+        dispatch(hiddenParticipantJoined(id, displayName));
73
+    } else {
74
+        dispatch(participantJoined({
75
+            botType: user.getBotType(),
76
+            conference,
77
+            id,
78
+            name: displayName,
79
+            presence: user.getStatus(),
80
+            role: user.getRole()
81
+        }));
82
+    }
83
+}
84
+
85
+/**
86
+ * Logic shared between web and RN which processes the {@code USER_LEFT}
87
+ * conference event and dispatches either {@link participantLeft} or
88
+ * {@link hiddenParticipantLeft}.
89
+ *
90
+ * @param {Object} store - The redux store.
91
+ * @param {JitsiMeetConference} conference - The conference for which the
92
+ * {@code USER_LEFT} event is being processed.
93
+ * @param {JitsiParticipant} user - The user who has just left.
94
+ * @returns {void}
95
+ */
96
+export function commonUserLeftHandling(
97
+        { dispatch }: Object,
98
+        conference: Object,
99
+        user: Object) {
100
+    const id = user.getId();
101
+
102
+    if (user.isHidden()) {
103
+        dispatch(hiddenParticipantLeft(id));
104
+    } else {
105
+        dispatch(participantLeft(id, conference));
106
+    }
107
+}
108
+
47
 /**
109
 /**
48
  * Evaluates a specific predicate for each {@link JitsiConference} known to the
110
  * Evaluates a specific predicate for each {@link JitsiConference} known to the
49
  * redux state features/base/conference while it returns {@code true}.
111
  * redux state features/base/conference while it returns {@code true}.

正在加载...
取消
保存