瀏覽代碼

Move local participant join to base/participants

master
Zoltan Bettenbuk 7 年之前
父節點
當前提交
44a65eb329
共有 2 個檔案被更改,包括 32 行新增22 行删除
  1. 2
    21
      react/features/app/components/AbstractApp.js
  2. 30
    1
      react/features/base/participants/middleware.js

+ 2
- 21
react/features/app/components/AbstractApp.js 查看文件

8
 import Thunk from 'redux-thunk';
8
 import Thunk from 'redux-thunk';
9
 
9
 
10
 import { i18next } from '../../base/i18n';
10
 import { i18next } from '../../base/i18n';
11
-import {
12
-    localParticipantJoined,
13
-    localParticipantLeft
14
-} from '../../base/participants';
11
+import { localParticipantLeft } from '../../base/participants';
15
 import { Fragment, RouteRegistry } from '../../base/react';
12
 import { Fragment, RouteRegistry } from '../../base/react';
16
 import { MiddlewareRegistry, ReducerRegistry } from '../../base/redux';
13
 import { MiddlewareRegistry, ReducerRegistry } from '../../base/redux';
17
 import { SoundCollection } from '../../base/sounds';
14
 import { SoundCollection } from '../../base/sounds';
126
      */
123
      */
127
     componentWillMount() {
124
     componentWillMount() {
128
         this._init.then(() => {
125
         this._init.then(() => {
129
-            const { dispatch, getState } = this._getStore();
126
+            const { dispatch } = this._getStore();
130
 
127
 
131
             dispatch(appWillMount(this));
128
             dispatch(appWillMount(this));
132
 
129
 
133
-            // FIXME I believe it makes more sense for a middleware to dispatch
134
-            // localParticipantJoined on APP_WILL_MOUNT because the order of
135
-            // actions is important, not the call site. Moreover, we've got
136
-            // localParticipant business logic in the React Component
137
-            // (i.e. UI) AbstractApp now.
138
-
139
-            const settings = getState()['features/base/settings'];
140
-            const localParticipant = {
141
-                avatarID: settings.avatarID,
142
-                avatarURL: settings.avatarURL,
143
-                email: settings.email,
144
-                name: settings.displayName
145
-            };
146
-
147
             // We set the initialized state here and not in the contructor to
130
             // We set the initialized state here and not in the contructor to
148
             // make sure that {@code componentWillMount} gets invoked before
131
             // make sure that {@code componentWillMount} gets invoked before
149
             // the app tries to render the actual app content.
132
             // the app tries to render the actual app content.
151
                 appAsyncInitialized: true
134
                 appAsyncInitialized: true
152
             });
135
             });
153
 
136
 
154
-            dispatch(localParticipantJoined(localParticipant));
155
-
156
             // If a URL was explicitly specified to this React Component,
137
             // If a URL was explicitly specified to this React Component,
157
             // then open it; otherwise, use a default.
138
             // then open it; otherwise, use a default.
158
             this._openURL(toURLString(this.props.url) || this._getDefaultURL());
139
             this._openURL(toURLString(this.props.url) || this._getDefaultURL());

+ 30
- 1
react/features/base/participants/middleware.js 查看文件

12
 
12
 
13
 import {
13
 import {
14
     localParticipantIdChanged,
14
     localParticipantIdChanged,
15
+    localParticipantJoined,
15
     participantUpdated
16
     participantUpdated
16
 } from './actions';
17
 } from './actions';
17
 import {
18
 import {
56
     switch (action.type) {
57
     switch (action.type) {
57
     case APP_WILL_MOUNT:
58
     case APP_WILL_MOUNT:
58
         _registerSounds(store);
59
         _registerSounds(store);
59
-        break;
60
+
61
+        return _localParticipantJoined(store, next, action);
60
     case APP_WILL_UNMOUNT:
62
     case APP_WILL_UNMOUNT:
61
         _unregisterSounds(store);
63
         _unregisterSounds(store);
62
         break;
64
         break;
174
     return next(action);
176
     return next(action);
175
 });
177
 });
176
 
178
 
179
+/**
180
+ * Initializes the local participant and signals that it joined.
181
+ *
182
+ * @private
183
+ * @param {Store} store - The Redux store.
184
+ * @param {Dispatch} next - The redux dispatch function to dispatch the
185
+ * specified action to the specified store.
186
+ * @param {Action} action - The redux action which is being dispatched
187
+ * in the specified store.
188
+ * @private
189
+ * @returns {Object} The value returned by {@code next(action)}.
190
+ */
191
+function _localParticipantJoined({ getState, dispatch }, next, action) {
192
+    const result = next(action);
193
+    const settings = getState()['features/base/settings'];
194
+    const localParticipant = {
195
+        avatarID: settings.avatarID,
196
+        avatarURL: settings.avatarURL,
197
+        email: settings.email,
198
+        name: settings.displayName
199
+    };
200
+
201
+    dispatch(localParticipantJoined(localParticipant));
202
+
203
+    return result;
204
+}
205
+
177
 /**
206
 /**
178
  * Plays sounds when participants join/leave conference.
207
  * Plays sounds when participants join/leave conference.
179
  *
208
  *

Loading…
取消
儲存