Преглед изворни кода

feat: lobby related notifications

master
Bettenbuk Zoltan пре 5 година
родитељ
комит
873ede0e06
3 измењених фајлова са 84 додато и 2 уклоњено
  1. 5
    0
      lang/main.json
  2. 29
    0
      react/features/lobby/functions.js
  3. 50
    2
      react/features/lobby/middleware.js

+ 5
- 0
lang/main.json Прегледај датотеку

885
         "knockButton": "Ask to Join",
885
         "knockButton": "Ask to Join",
886
         "knockTitle": "Someone wants to join the meeting",
886
         "knockTitle": "Someone wants to join the meeting",
887
         "nameField": "Enter your name",
887
         "nameField": "Enter your name",
888
+        "notificationLobbyAccessDenied": "{{targetParticipantName}} has been rejected to join by {{originParticipantName}}",
889
+        "notificationLobbyAccessGranted": "{{targetParticipantName}} has been allowed to join by {{originParticipantName}}",
890
+        "notificationLobbyDisabled": "Lobby has been disabled by {{originParticipantName}}",
891
+        "notificationLobbyEnabled": "Lobby has been enabled by {{originParticipantName}}",
892
+        "notificationTitle": "Lobby",
888
         "passwordField": "Enter meeting password",
893
         "passwordField": "Enter meeting password",
889
         "passwordJoinButton": "Join",
894
         "passwordJoinButton": "Join",
890
         "reject": "Reject",
895
         "reject": "Reject",

+ 29
- 0
react/features/lobby/functions.js Прегледај датотеку

1
 // @flow
1
 // @flow
2
 
2
 
3
 import { getCurrentConference } from '../base/conference';
3
 import { getCurrentConference } from '../base/conference';
4
+import { toState } from '../base/redux';
5
+
6
+const JID_PATTERN = '[^@]+@[^/]+/(.+)';
7
+
8
+/**
9
+ * Returns a knocking participant by ID or JID.
10
+ *
11
+ * @param {Function | Object} stateful - The Redux state or a function that resolves to the Redux state.
12
+ * @param {string} id - The ID or JID of the participant.
13
+ * @returns {Object}
14
+ */
15
+export function getKnockingParticipantById(stateful: Function | Object, id: string): Object {
16
+    const { knockingParticipants } = toState(stateful)['features/lobby'];
17
+    const idToFind = getIdFromJid(id) || id;
18
+
19
+    return knockingParticipants.find(p => p.id === idToFind);
20
+}
4
 
21
 
5
 /**
22
 /**
6
  * Approves (lets in) or rejects a knocking participant.
23
  * Approves (lets in) or rejects a knocking participant.
21
         }
38
         }
22
     }
39
     }
23
 }
40
 }
41
+
42
+/**
43
+ * Parses an ID from a JID, if a JID is provided, undefined otherwise.
44
+ *
45
+ * @param {string} jid - The JID to get the ID from.
46
+ * @returns {?string}
47
+ */
48
+function getIdFromJid(jid: string): ?string {
49
+    const match = new RegExp(JID_PATTERN, 'g').exec(jid) || [];
50
+
51
+    return match[1];
52
+}

+ 50
- 2
react/features/lobby/middleware.js Прегледај датотеку

2
 
2
 
3
 import { CONFERENCE_FAILED, CONFERENCE_JOINED } from '../base/conference';
3
 import { CONFERENCE_FAILED, CONFERENCE_JOINED } from '../base/conference';
4
 import { JitsiConferenceErrors, JitsiConferenceEvents } from '../base/lib-jitsi-meet';
4
 import { JitsiConferenceErrors, JitsiConferenceEvents } from '../base/lib-jitsi-meet';
5
-import { getFirstLoadableAvatarUrl } from '../base/participants';
5
+import { getFirstLoadableAvatarUrl, getParticipantDisplayName } from '../base/participants';
6
 import { MiddlewareRegistry, StateListenerRegistry } from '../base/redux';
6
 import { MiddlewareRegistry, StateListenerRegistry } from '../base/redux';
7
 import { NOTIFICATION_TYPE, showNotification } from '../notifications';
7
 import { NOTIFICATION_TYPE, showNotification } from '../notifications';
8
 import { isPrejoinPageEnabled } from '../prejoin/functions';
8
 import { isPrejoinPageEnabled } from '../prejoin/functions';
17
     startKnocking,
17
     startKnocking,
18
     setPasswordJoinFailed
18
     setPasswordJoinFailed
19
 } from './actions';
19
 } from './actions';
20
+import { getKnockingParticipantById } from './functions';
20
 
21
 
21
 MiddlewareRegistry.register(store => next => action => {
22
 MiddlewareRegistry.register(store => next => action => {
22
     switch (action.type) {
23
     switch (action.type) {
43
  */
44
  */
44
 StateListenerRegistry.register(
45
 StateListenerRegistry.register(
45
     state => state['features/base/conference'].conference,
46
     state => state['features/base/conference'].conference,
46
-    (conference, { dispatch }, previousConference) => {
47
+    (conference, { dispatch, getState }, previousConference) => {
47
         if (conference && !previousConference) {
48
         if (conference && !previousConference) {
48
             conference.on(JitsiConferenceEvents.MEMBERS_ONLY_CHANGED, enabled => {
49
             conference.on(JitsiConferenceEvents.MEMBERS_ONLY_CHANGED, enabled => {
49
                 dispatch(setLobbyModeEnabled(enabled));
50
                 dispatch(setLobbyModeEnabled(enabled));
66
             conference.on(JitsiConferenceEvents.LOBBY_USER_LEFT, id => {
67
             conference.on(JitsiConferenceEvents.LOBBY_USER_LEFT, id => {
67
                 dispatch(knockingParticipantLeft(id));
68
                 dispatch(knockingParticipantLeft(id));
68
             });
69
             });
70
+
71
+            conference.on(JitsiConferenceEvents.ENDPOINT_MESSAGE_RECEIVED, (origin, sender) =>
72
+                _maybeSendLobbyNotification(origin, sender, {
73
+                    dispatch,
74
+                    getState
75
+                })
76
+            );
69
         }
77
         }
70
     });
78
     });
71
 
79
 
151
         });
159
         });
152
     }
160
     }
153
 }
161
 }
162
+
163
+/**
164
+ * Check the endpoint message that arrived through the conference and
165
+ * sends a lobby notification, if the message belongs to the feature.
166
+ *
167
+ * @param {Object} origin - The origin (initiator) of the message.
168
+ * @param {Object} message - The actual message.
169
+ * @param {Object} store - The Redux store.
170
+ * @returns {void}
171
+ */
172
+function _maybeSendLobbyNotification(origin, message, { dispatch, getState }) {
173
+    if (!origin?._id || message?.type !== 'lobby-notify') {
174
+        return;
175
+    }
176
+
177
+    const notificationProps: any = {
178
+        descriptionArguments: {
179
+            originParticipantName: getParticipantDisplayName(getState, origin._id)
180
+        },
181
+        titleKey: 'lobby.notificationTitle'
182
+    };
183
+
184
+    switch (message.event) {
185
+    case 'LOBBY-ENABLED':
186
+        notificationProps.descriptionKey = `lobby.notificationLobby${message.value ? 'En' : 'Dis'}abled`;
187
+        break;
188
+    case 'LOBBY-ACCESS-GRANTED':
189
+        notificationProps.descriptionKey = 'lobby.notificationLobbyAccessGranted';
190
+        notificationProps.descriptionArguments.targetParticipantName
191
+            = getKnockingParticipantById(getState, message.value)?.name;
192
+        break;
193
+    case 'LOBBY-ACCESS-DENIED':
194
+        notificationProps.descriptionKey = 'lobby.notificationLobbyAccessDenied';
195
+        notificationProps.descriptionArguments.targetParticipantName
196
+            = getKnockingParticipantById(getState, message.value)?.name;
197
+        break;
198
+    }
199
+
200
+    dispatch(showNotification(notificationProps, 5000));
201
+}

Loading…
Откажи
Сачувај