Просмотр исходного кода

feat: lobby related notifications

master
Bettenbuk Zoltan 5 лет назад
Родитель
Сommit
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,6 +885,11 @@
885 885
         "knockButton": "Ask to Join",
886 886
         "knockTitle": "Someone wants to join the meeting",
887 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 893
         "passwordField": "Enter meeting password",
889 894
         "passwordJoinButton": "Join",
890 895
         "reject": "Reject",

+ 29
- 0
react/features/lobby/functions.js Просмотреть файл

@@ -1,6 +1,23 @@
1 1
 // @flow
2 2
 
3 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 23
  * Approves (lets in) or rejects a knocking participant.
@@ -21,3 +38,15 @@ export function setKnockingParticipantApproval(getState: Function, id: string, a
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,7 +2,7 @@
2 2
 
3 3
 import { CONFERENCE_FAILED, CONFERENCE_JOINED } from '../base/conference';
4 4
 import { JitsiConferenceErrors, JitsiConferenceEvents } from '../base/lib-jitsi-meet';
5
-import { getFirstLoadableAvatarUrl } from '../base/participants';
5
+import { getFirstLoadableAvatarUrl, getParticipantDisplayName } from '../base/participants';
6 6
 import { MiddlewareRegistry, StateListenerRegistry } from '../base/redux';
7 7
 import { NOTIFICATION_TYPE, showNotification } from '../notifications';
8 8
 import { isPrejoinPageEnabled } from '../prejoin/functions';
@@ -17,6 +17,7 @@ import {
17 17
     startKnocking,
18 18
     setPasswordJoinFailed
19 19
 } from './actions';
20
+import { getKnockingParticipantById } from './functions';
20 21
 
21 22
 MiddlewareRegistry.register(store => next => action => {
22 23
     switch (action.type) {
@@ -43,7 +44,7 @@ MiddlewareRegistry.register(store => next => action => {
43 44
  */
44 45
 StateListenerRegistry.register(
45 46
     state => state['features/base/conference'].conference,
46
-    (conference, { dispatch }, previousConference) => {
47
+    (conference, { dispatch, getState }, previousConference) => {
47 48
         if (conference && !previousConference) {
48 49
             conference.on(JitsiConferenceEvents.MEMBERS_ONLY_CHANGED, enabled => {
49 50
                 dispatch(setLobbyModeEnabled(enabled));
@@ -66,6 +67,13 @@ StateListenerRegistry.register(
66 67
             conference.on(JitsiConferenceEvents.LOBBY_USER_LEFT, id => {
67 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,3 +159,43 @@ function _findLoadableAvatarForKnockingParticipant({ dispatch, getState }, { id
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
+}

Загрузка…
Отмена
Сохранить