浏览代码

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 年前
父节点
当前提交
7684b2bf98
共有 2 个文件被更改,包括 30 次插入30 次删除
  1. 25
    0
      react/features/base/connection/functions.js
  2. 5
    30
      react/features/mobile/watchos/middleware.js

+ 25
- 0
react/features/base/connection/functions.js 查看文件

1
 /* @flow */
1
 /* @flow */
2
 
2
 
3
 import { toState } from '../redux';
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
  * Retrieves a simplified version of the conference/location URL stripped of URL params (i.e. Query/search and hash)
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 查看文件

7
 
7
 
8
 import { APP_WILL_MOUNT } from '../../base/app';
8
 import { APP_WILL_MOUNT } from '../../base/app';
9
 import { CONFERENCE_JOINED } from '../../base/conference';
9
 import { CONFERENCE_JOINED } from '../../base/conference';
10
-import { getInviteURL, isInviteURLReady } from '../../base/connection';
10
+import { getCurrentConferenceUrl } from '../../base/connection';
11
 import { setAudioMuted } from '../../base/media';
11
 import { setAudioMuted } from '../../base/media';
12
 import {
12
 import {
13
     MiddlewareRegistry,
13
     MiddlewareRegistry,
14
     StateListenerRegistry,
14
     StateListenerRegistry,
15
     toState
15
     toState
16
 } from '../../base/redux';
16
 } from '../../base/redux';
17
-import { toURLString } from '../../base/util';
18
 
17
 
19
 import { setConferenceTimestamp, setSessionId, setWatchReachable } from './actions';
18
 import { setConferenceTimestamp, setSessionId, setWatchReachable } from './actions';
20
 import { CMD_HANG_UP, CMD_JOIN_CONFERENCE, CMD_SET_MUTED, MAX_RECENT_URLS } from './constants';
19
 import { CMD_HANG_UP, CMD_JOIN_CONFERENCE, CMD_SET_MUTED, MAX_RECENT_URLS } from './constants';
39
 
38
 
40
 // Handles the conference URL state sent to the watch
39
 // Handles the conference URL state sent to the watch
41
 watchOSEnabled && StateListenerRegistry.register(
40
 watchOSEnabled && StateListenerRegistry.register(
42
-    /* selector */ state => _getCurrentConferenceUrl(state),
41
+    /* selector */ state => getCurrentConferenceUrl(state),
43
     /* listener */ (currentUrl, { dispatch, getState }) => {
42
     /* listener */ (currentUrl, { dispatch, getState }) => {
44
         dispatch(setSessionId());
43
         dispatch(setSessionId());
45
         _updateApplicationContext(getState);
44
         _updateApplicationContext(getState);
101
 
100
 
102
         switch (command) {
101
         switch (command) {
103
         case CMD_HANG_UP:
102
         case CMD_HANG_UP:
104
-            if (typeof _getCurrentConferenceUrl(getState()) !== undefined) {
103
+            if (typeof getCurrentConferenceUrl(getState()) !== undefined) {
105
                 dispatch(appNavigate(undefined));
104
                 dispatch(appNavigate(undefined));
106
             }
105
             }
107
             break;
106
             break;
108
         case CMD_JOIN_CONFERENCE: {
107
         case CMD_JOIN_CONFERENCE: {
109
             const newConferenceURL = message.data;
108
             const newConferenceURL = message.data;
110
-            const oldConferenceURL = _getCurrentConferenceUrl(getState());
109
+            const oldConferenceURL = getCurrentConferenceUrl(getState());
111
 
110
 
112
             if (oldConferenceURL !== newConferenceURL) {
111
             if (oldConferenceURL !== newConferenceURL) {
113
                 dispatch(appNavigate(newConferenceURL));
112
                 dispatch(appNavigate(newConferenceURL));
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
  * Gets the current Apple Watch session's ID. A new session is started whenever the conference URL has changed. It is
127
  * Gets the current Apple Watch session's ID. A new session is started whenever the conference URL has changed. It is
153
  * used to filter out outdated commands which may arrive very later if the Apple Watch loses the connectivity.
128
  * used to filter out outdated commands which may arrive very later if the Apple Watch loses the connectivity.
214
     try {
189
     try {
215
         watch.updateApplicationContext({
190
         watch.updateApplicationContext({
216
             conferenceTimestamp,
191
             conferenceTimestamp,
217
-            conferenceURL: _getCurrentConferenceUrl(state),
192
+            conferenceURL: getCurrentConferenceUrl(state),
218
             micMuted: _isAudioMuted(state),
193
             micMuted: _isAudioMuted(state),
219
             recentURLs: _getRecentUrls(state),
194
             recentURLs: _getRecentUrls(state),
220
             sessionID
195
             sessionID

正在加载...
取消
保存