Browse Source

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 years ago
parent
commit
6dea107bcd

+ 9
- 19
conference.js View File

@@ -31,14 +31,16 @@ import EventEmitter from 'events';
31 31
 import {
32 32
     AVATAR_ID_COMMAND,
33 33
     AVATAR_URL_COMMAND,
34
+    EMAIL_COMMAND,
34 35
     authStatusChanged,
36
+    commonUserJoinedHandling,
37
+    commonUserLeftHandling,
35 38
     conferenceFailed,
36 39
     conferenceJoined,
37 40
     conferenceLeft,
38 41
     conferenceWillJoin,
39 42
     conferenceWillLeave,
40 43
     dataChannelOpened,
41
-    EMAIL_COMMAND,
42 44
     lockStateChanged,
43 45
     onStartMutedPolicyChanged,
44 46
     p2pStatusChanged,
@@ -75,14 +77,10 @@ import {
75 77
     getAvatarURLByParticipantId,
76 78
     getLocalParticipant,
77 79
     getParticipantById,
78
-    hiddenParticipantJoined,
79
-    hiddenParticipantLeft,
80 80
     localParticipantConnectionStatusChanged,
81 81
     localParticipantRoleChanged,
82 82
     MAX_DISPLAY_NAME_LENGTH,
83 83
     participantConnectionStatusChanged,
84
-    participantJoined,
85
-    participantLeft,
86 84
     participantPresenceChanged,
87 85
     participantRoleChanged,
88 86
     participantUpdated
@@ -1694,22 +1692,14 @@ export default {
1694 1692
         room.on(JitsiConferenceEvents.PARTCIPANT_FEATURES_CHANGED,
1695 1693
             user => APP.UI.onUserFeaturesChanged(user));
1696 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 1698
             if (user.isHidden()) {
1700
-                APP.store.dispatch(hiddenParticipantJoined(id, displayName));
1701
-
1702 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 1704
             logger.log(`USER ${id} connnected:`, user);
1715 1705
             APP.API.notifyUserJoined(id, {
@@ -1724,13 +1714,13 @@ export default {
1724 1714
         });
1725 1715
 
1726 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 1721
                 return;
1731 1722
             }
1732 1723
 
1733
-            APP.store.dispatch(participantLeft(id, room));
1734 1724
             logger.log(`USER ${id} LEFT:`, user);
1735 1725
             APP.API.notifyUserLeft(id);
1736 1726
             APP.UI.messageHandler.participantNotification(

+ 4
- 12
react/features/base/conference/actions.js View File

@@ -13,8 +13,6 @@ import {
13 13
     MAX_DISPLAY_NAME_LENGTH,
14 14
     dominantSpeakerChanged,
15 15
     participantConnectionStatusChanged,
16
-    participantJoined,
17
-    participantLeft,
18 16
     participantPresenceChanged,
19 17
     participantRoleChanged,
20 18
     participantUpdated
@@ -52,6 +50,8 @@ import {
52 50
 } from './constants';
53 51
 import {
54 52
     _addLocalTracksToConference,
53
+    commonUserJoinedHandling,
54
+    commonUserLeftHandling,
55 55
     getCurrentConference,
56 56
     sendLocalParticipant
57 57
 } from './functions';
@@ -143,18 +143,10 @@ function _addConferenceListeners(conference, dispatch) {
143 143
 
144 144
     conference.on(
145 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 147
     conference.on(
155 148
         JitsiConferenceEvents.USER_LEFT,
156
-        (id, user) => !user.isHidden()
157
-            && dispatch(participantLeft(id, conference)));
149
+        (id, user) => commonUserLeftHandling({ dispatch }, conference, user));
158 150
     conference.on(
159 151
         JitsiConferenceEvents.USER_ROLE_CHANGED,
160 152
         (...args) => dispatch(participantRoleChanged(...args)));

+ 63
- 1
react/features/base/conference/functions.js View File

@@ -1,7 +1,13 @@
1 1
 // @flow
2 2
 
3 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 11
 import { toState } from '../redux';
6 12
 
7 13
 import {
@@ -44,6 +50,62 @@ export function _addLocalTracksToConference(
44 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 110
  * Evaluates a specific predicate for each {@link JitsiConference} known to the
49 111
  * redux state features/base/conference while it returns {@code true}.

Loading…
Cancel
Save