Ver código fonte

ref: move getCurrentConferenceUrl to base/connection

Moves getCurrentConferenceUrl method to base/connection to allow reuse.
The new location is not ideal, but looks the best based on the imports
required (trying to avoid circular dependencies).
master
paweldomas 6 anos atrás
pai
commit
7684b2bf98

+ 25
- 0
react/features/base/connection/functions.js Ver arquivo

@@ -1,6 +1,31 @@
1 1
 /* @flow */
2 2
 
3 3
 import { toState } from '../redux';
4
+import { toURLString } from '../util';
5
+
6
+/**
7
+ * Figures out what's the current conference URL which is supposed to indicate what conference is currently active.
8
+ * When not currently in any conference and not trying to join any then 'undefined' is returned.
9
+ *
10
+ * @param {Object|Function} stateful - Either the whole Redux state object or the Redux store's {@code getState} method.
11
+ * @returns {string|undefined}
12
+ * @private
13
+ */
14
+export function getCurrentConferenceUrl(stateful: Function | Object) {
15
+    const state = toState(stateful);
16
+    let currentUrl;
17
+
18
+    if (isInviteURLReady(state)) {
19
+        currentUrl = toURLString(getInviteURL(state));
20
+    }
21
+
22
+    // Check if the URL doesn't end with a slash
23
+    if (currentUrl && currentUrl.substr(-1) === '/') {
24
+        currentUrl = undefined;
25
+    }
26
+
27
+    return currentUrl ? currentUrl : undefined;
28
+}
4 29
 
5 30
 /**
6 31
  * Retrieves a simplified version of the conference/location URL stripped of URL params (i.e. Query/search and hash)

+ 5
- 30
react/features/mobile/watchos/middleware.js Ver arquivo

@@ -7,14 +7,13 @@ import { appNavigate } from '../../app';
7 7
 
8 8
 import { APP_WILL_MOUNT } from '../../base/app';
9 9
 import { CONFERENCE_JOINED } from '../../base/conference';
10
-import { getInviteURL, isInviteURLReady } from '../../base/connection';
10
+import { getCurrentConferenceUrl } from '../../base/connection';
11 11
 import { setAudioMuted } from '../../base/media';
12 12
 import {
13 13
     MiddlewareRegistry,
14 14
     StateListenerRegistry,
15 15
     toState
16 16
 } from '../../base/redux';
17
-import { toURLString } from '../../base/util';
18 17
 
19 18
 import { setConferenceTimestamp, setSessionId, setWatchReachable } from './actions';
20 19
 import { CMD_HANG_UP, CMD_JOIN_CONFERENCE, CMD_SET_MUTED, MAX_RECENT_URLS } from './constants';
@@ -39,7 +38,7 @@ watchOSEnabled && StateListenerRegistry.register(
39 38
 
40 39
 // Handles the conference URL state sent to the watch
41 40
 watchOSEnabled && StateListenerRegistry.register(
42
-    /* selector */ state => _getCurrentConferenceUrl(state),
41
+    /* selector */ state => getCurrentConferenceUrl(state),
43 42
     /* listener */ (currentUrl, { dispatch, getState }) => {
44 43
         dispatch(setSessionId());
45 44
         _updateApplicationContext(getState);
@@ -101,13 +100,13 @@ function _appWillMount({ dispatch, getState }) {
101 100
 
102 101
         switch (command) {
103 102
         case CMD_HANG_UP:
104
-            if (typeof _getCurrentConferenceUrl(getState()) !== undefined) {
103
+            if (typeof getCurrentConferenceUrl(getState()) !== undefined) {
105 104
                 dispatch(appNavigate(undefined));
106 105
             }
107 106
             break;
108 107
         case CMD_JOIN_CONFERENCE: {
109 108
             const newConferenceURL = message.data;
110
-            const oldConferenceURL = _getCurrentConferenceUrl(getState());
109
+            const oldConferenceURL = getCurrentConferenceUrl(getState());
111 110
 
112 111
             if (oldConferenceURL !== newConferenceURL) {
113 112
                 dispatch(appNavigate(newConferenceURL));
@@ -124,30 +123,6 @@ function _appWillMount({ dispatch, getState }) {
124 123
     });
125 124
 }
126 125
 
127
-/**
128
- * Figures out what's the current conference URL which is supposed to indicate what conference is currently active.
129
- * When not currently in any conference and not trying to join any then the 'NULL' string value is returned.
130
- *
131
- * @param {Object|Function} stateful - Either the whole Redux state object or the Redux store's {@code getState} method.
132
- * @returns {string}
133
- * @private
134
- */
135
-function _getCurrentConferenceUrl(stateful) {
136
-    const state = toState(stateful);
137
-    let currentUrl;
138
-
139
-    if (isInviteURLReady(state)) {
140
-        currentUrl = toURLString(getInviteURL(state));
141
-    }
142
-
143
-    // Check if the URL doesn't end with a slash
144
-    if (currentUrl && currentUrl.substr(-1) === '/') {
145
-        currentUrl = undefined;
146
-    }
147
-
148
-    return currentUrl ? currentUrl : undefined;
149
-}
150
-
151 126
 /**
152 127
  * Gets the current Apple Watch session's ID. A new session is started whenever the conference URL has changed. It is
153 128
  * used to filter out outdated commands which may arrive very later if the Apple Watch loses the connectivity.
@@ -214,7 +189,7 @@ function _updateApplicationContext(stateful) {
214 189
     try {
215 190
         watch.updateApplicationContext({
216 191
             conferenceTimestamp,
217
-            conferenceURL: _getCurrentConferenceUrl(state),
192
+            conferenceURL: getCurrentConferenceUrl(state),
218 193
             micMuted: _isAudioMuted(state),
219 194
             recentURLs: _getRecentUrls(state),
220 195
             sessionID

Carregando…
Cancelar
Salvar