Browse Source

feat(breakout-rooms) add notification when joining rooms

master
Saúl Ibarra Corretgé 3 years ago
parent
commit
da0cb2b837
2 changed files with 64 additions and 18 deletions
  1. 5
    0
      lang/main.json
  2. 59
    18
      react/features/breakout-rooms/actions.js

+ 5
- 0
lang/main.json View File

@@ -54,6 +54,11 @@
54 54
             "more": "More",
55 55
             "remove": "Remove",
56 56
             "sendToBreakoutRoom": "Send participant to:"
57
+        },
58
+        "notifications": {
59
+            "joinedTitle": "Breakout Rooms",
60
+            "joined": "Joining the \"{{name}}\" breakout room",
61
+            "joinedMainRoom": "Joining the main room"
57 62
         }
58 63
     },
59 64
     "calendarSync": {

+ 59
- 18
react/features/breakout-rooms/actions.js View File

@@ -13,7 +13,11 @@ import {
13 13
 } from '../base/conference';
14 14
 import { setAudioMuted, setVideoMuted } from '../base/media';
15 15
 import { getRemoteParticipants } from '../base/participants';
16
-import { clearNotifications } from '../notifications';
16
+import {
17
+    NOTIFICATION_TIMEOUT_TYPE,
18
+    clearNotifications,
19
+    showNotification
20
+} from '../notifications';
17 21
 
18 22
 import { _RESET_BREAKOUT_ROOMS, _UPDATE_ROOM_COUNTER } from './actionTypes';
19 23
 import { FEATURE_KEY } from './constants';
@@ -155,8 +159,9 @@ export function sendParticipantToRoom(participantId: string, roomId: string) {
155 159
  * @returns {Function}
156 160
  */
157 161
 export function moveToRoom(roomId?: string) {
158
-    return (dispatch: Dispatch<any>, getState: Function) => {
159
-        let _roomId = roomId || getMainRoom(getState)?.id;
162
+    return async (dispatch: Dispatch<any>, getState: Function) => {
163
+        const mainRoomId = getMainRoom(getState)?.id;
164
+        let _roomId = roomId || mainRoomId;
160 165
 
161 166
         // Check if we got a full JID.
162 167
         // $FlowExpectedError
@@ -175,6 +180,18 @@ export function moveToRoom(roomId?: string) {
175 180
             _roomId.domain = domainParts.join('@');
176 181
         }
177 182
 
183
+        // $FlowExpectedError
184
+        const roomIdStr = _roomId?.toString();
185
+        const goToMainRoom = roomIdStr === mainRoomId;
186
+        const rooms = getBreakoutRooms(getState);
187
+        const targetRoom = rooms[roomIdStr];
188
+
189
+        if (!targetRoom) {
190
+            logger.warn(`Unknown room: ${targetRoom}`);
191
+
192
+            return;
193
+        }
194
+
178 195
         dispatch({
179 196
             type: _RESET_BREAKOUT_ROOMS
180 197
         });
@@ -185,23 +202,47 @@ export function moveToRoom(roomId?: string) {
185 202
 
186 203
             dispatch(conferenceWillLeave(conference));
187 204
 
188
-            conference.leave()
189
-                .catch(error => {
190
-                    logger.warn('JitsiConference.leave() rejected with:', error);
205
+            try {
206
+                await conference.leave();
207
+            } catch (error) {
208
+                logger.warn('JitsiConference.leave() rejected with:', error);
191 209
 
192
-                    dispatch(conferenceLeft(conference));
193
-                })
194
-                .then(() => {
195
-                    dispatch(clearNotifications());
196
-
197
-                    // dispatch(setRoom(_roomId));
198
-                    dispatch(createConference(_roomId));
199
-                    dispatch(setAudioMuted(audio.muted));
200
-                    dispatch(setVideoMuted(video.muted));
201
-                });
210
+                dispatch(conferenceLeft(conference));
211
+            }
212
+
213
+            dispatch(clearNotifications());
214
+
215
+            // dispatch(setRoom(_roomId));
216
+            dispatch(createConference(_roomId));
217
+            dispatch(setAudioMuted(audio.muted));
218
+            dispatch(setVideoMuted(video.muted));
219
+        } else {
220
+            try {
221
+                APP.conference.leaveRoom(false /* doDisconnect */);
222
+            } catch (error) {
223
+                logger.warn('APP.conference.leaveRoom() rejected with:', error);
224
+
225
+                // TODO: revisit why we don't dispatch CONFERENCE_LEFT here.
226
+            }
227
+
228
+            APP.conference.joinRoom(_roomId);
229
+        }
230
+
231
+        if (goToMainRoom) {
232
+            dispatch(showNotification({
233
+                titleKey: 'breakoutRooms.notifications.joinedTitle',
234
+                descriptionKey: 'breakoutRooms.notifications.joinedMainRoom',
235
+                concatText: true,
236
+                maxLines: 2
237
+            }, NOTIFICATION_TIMEOUT_TYPE.MEDIUM));
202 238
         } else {
203
-            APP.conference.leaveRoom(false /* doDisconnect */)
204
-                .finally(() => APP.conference.joinRoom(_roomId));
239
+            dispatch(showNotification({
240
+                titleKey: 'breakoutRooms.notifications.joinedTitle',
241
+                descriptionKey: 'breakoutRooms.notifications.joined',
242
+                descriptionArguments: { name: targetRoom.name },
243
+                concatText: true,
244
+                maxLines: 2
245
+            }, NOTIFICATION_TIMEOUT_TYPE.MEDIUM));
205 246
         }
206 247
     };
207 248
 }

Loading…
Cancel
Save