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

[RN] Add ability to share the URL for a conference

j8
Saúl Ibarra Corretgé 8 лет назад
Родитель
Сommit
54bb5f1879

+ 24
- 0
react/features/share-room/actionTypes.js Просмотреть файл

@@ -0,0 +1,24 @@
1
+import { Symbol } from '../base/react';
2
+
3
+/**
4
+ * The type of (redux) action which begins the UI procedure to share the current
5
+ * conference/room URL.
6
+ *
7
+ * {
8
+ *     type: BEGIN_SHARE_ROOM,
9
+ *     roomURL: string
10
+ * }
11
+ */
12
+export const BEGIN_SHARE_ROOM = Symbol('BEGIN_SHARE_ROOM');
13
+
14
+/**
15
+ * The type of (redux) action which ends the UI procedure to share a specific
16
+ * conference/room URL.
17
+ *
18
+ * {
19
+ *     type: END_SHARE_ROOM,
20
+ *     roomURL: string,
21
+ *     shared: boolean
22
+ * }
23
+ */
24
+export const END_SHARE_ROOM = Symbol('END_SHARE_ROOM');

+ 65
- 0
react/features/share-room/actions.js Просмотреть файл

@@ -0,0 +1,65 @@
1
+/* @flow */
2
+
3
+import { BEGIN_SHARE_ROOM, END_SHARE_ROOM } from './actionTypes';
4
+
5
+/**
6
+ * Begins the UI procedure to share the URL for the current conference/room.
7
+ *
8
+ * @param {string} roomURL - The URL of the room to share.
9
+ * @public
10
+ * @returns {Function}
11
+ */
12
+export function beginShareRoom(roomURL: ?string): Function {
13
+    return (dispatch, getState) => {
14
+        if (!roomURL) {
15
+            const { conference, room } = getState()['features/base/conference'];
16
+
17
+            // eslint-disable-next-line no-param-reassign
18
+            roomURL = _getRoomURL(conference, room);
19
+        }
20
+
21
+        if (roomURL) {
22
+            dispatch({
23
+                type: BEGIN_SHARE_ROOM,
24
+                roomURL
25
+            });
26
+        }
27
+    };
28
+}
29
+
30
+/**
31
+ * Ends the UI procedure to share a specific conference/room URL.
32
+ *
33
+ * @param {string} roomURL - The URL of the conference/room which was shared.
34
+ * @param {boolean} shared - True if the URL was shared successfully; false,
35
+ * otherwise.
36
+ * @public
37
+ * @returns {{
38
+ *     type: END_SHARE_ROOM,
39
+ *     roomURL: string,
40
+ *     shared: boolean
41
+ * }}
42
+ */
43
+export function endShareRoom(roomURL: string, shared: boolean): Object {
44
+    return {
45
+        type: END_SHARE_ROOM,
46
+        roomURL,
47
+        shared
48
+    };
49
+}
50
+
51
+/**
52
+ * Gets the public URL of a conference/room.
53
+ *
54
+ * @param {JitsiConference} conference - The JitsiConference to share the URL
55
+ * of.
56
+ * @param {string} room - The name of the room to share the URL of.
57
+ * @private
58
+ * @returns {string|null}
59
+ */
60
+function _getRoomURL(conference, room) {
61
+    return (
62
+        conference
63
+            && room
64
+            && `https://${conference.connection.options.hosts.domain}/${room}`);
65
+}

+ 4
- 0
react/features/share-room/index.js Просмотреть файл

@@ -0,0 +1,4 @@
1
+export * from './actions';
2
+export * from './actionTypes';
3
+
4
+import './middleware';

+ 63
- 0
react/features/share-room/middleware.js Просмотреть файл

@@ -0,0 +1,63 @@
1
+/* @flow */
2
+
3
+import { Share } from 'react-native';
4
+
5
+import { MiddlewareRegistry } from '../base/redux';
6
+
7
+import { endShareRoom } from './actions';
8
+import { BEGIN_SHARE_ROOM } from './actionTypes';
9
+
10
+/**
11
+ * Middleware that captures room URL sharing actions and starts the sharing
12
+ * process.
13
+ *
14
+ * @param {Store} store - Redux store.
15
+ * @returns {Function}
16
+ */
17
+MiddlewareRegistry.register(store => next => action => {
18
+    switch (action.type) {
19
+    case BEGIN_SHARE_ROOM:
20
+        _shareRoom(action.roomURL, store.dispatch);
21
+        break;
22
+    }
23
+
24
+    return next(action);
25
+});
26
+
27
+/**
28
+ * Open the native sheet for sharing a specific conference/room URL.
29
+ *
30
+ * @param {string} roomURL - The URL of the conference/room to be shared.
31
+ * @param {Dispatch} dispatch - The Redux dispatch function.
32
+ * @private
33
+ * @returns {void}
34
+ */
35
+function _shareRoom(roomURL: string, dispatch: Function) {
36
+    // TODO The following display/human-readable strings were submitted for
37
+    // review before i18n was introduces in react/. However, I reviewed it
38
+    // afterwards. Translate the display/human-readable strings.
39
+    const message = `Click the following link to join the meeting: ${roomURL}`;
40
+    const title = 'Jitsi Meet Conference';
41
+    const onFulfilled
42
+        = (shared: boolean) => dispatch(endShareRoom(roomURL, shared));
43
+
44
+    Share.share(
45
+        /* content */ {
46
+            message,
47
+            title
48
+        },
49
+        /* options */ {
50
+            dialogTitle: title, // Android
51
+            subject: title // iOS
52
+        })
53
+        .then(
54
+            /* onFulfilled */ value => {
55
+                onFulfilled(value.action === Share.sharedAction);
56
+            },
57
+            /* onRejected */ reason => {
58
+                console.error(
59
+                    `Failed to share conference/room URL ${roomURL}:`,
60
+                    reason);
61
+                onFulfilled(false);
62
+            });
63
+}

+ 23
- 0
react/features/toolbox/components/Toolbox.native.js Просмотреть файл

@@ -7,6 +7,7 @@ import { MEDIA_TYPE, toggleCameraFacingMode } from '../../base/media';
7 7
 import { Container } from '../../base/react';
8 8
 import { ColorPalette } from '../../base/styles';
9 9
 import { beginRoomLockRequest } from '../../room-lock';
10
+import { beginShareRoom } from '../../share-room';
10 11
 
11 12
 import {
12 13
     abstractMapDispatchToProps,
@@ -45,6 +46,11 @@ class Toolbox extends Component {
45 46
          */
46 47
         _onRoomLock: React.PropTypes.func,
47 48
 
49
+        /**
50
+         * Begins the UI procedure to share the conference/room URL.
51
+         */
52
+        _onShareRoom: React.PropTypes.func,
53
+
48 54
         /**
49 55
          * Handler for toggle audio.
50 56
          */
@@ -211,6 +217,12 @@ class Toolbox extends Component {
211 217
                     onClick = { this.props._onToggleAudioOnly }
212 218
                     style = { style }
213 219
                     underlayColor = { underlayColor } />
220
+                <ToolbarButton
221
+                    iconName = 'link'
222
+                    iconStyle = { iconStyle }
223
+                    onClick = { this.props._onShareRoom }
224
+                    style = { style }
225
+                    underlayColor = { underlayColor } />
214 226
             </View>
215 227
         );
216 228
 
@@ -257,6 +269,17 @@ function _mapDispatchToProps(dispatch) {
257 269
             return dispatch(beginRoomLockRequest());
258 270
         },
259 271
 
272
+        /**
273
+         * Begins the UI procedure to share the conference/room URL.
274
+         *
275
+         * @private
276
+         * @returns {void} Dispatched action.
277
+         * @type {Function}
278
+         */
279
+        _onShareRoom() {
280
+            return dispatch(beginShareRoom());
281
+        },
282
+
260 283
         /**
261 284
          * Toggles the audio-only flag of the conference.
262 285
          *

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