Преглед на файлове

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,10 +8,7 @@ import { compose, createStore } from 'redux';
8 8
 import Thunk from 'redux-thunk';
9 9
 
10 10
 import { i18next } from '../../base/i18n';
11
-import {
12
-    localParticipantJoined,
13
-    localParticipantLeft
14
-} from '../../base/participants';
11
+import { localParticipantLeft } from '../../base/participants';
15 12
 import { Fragment, RouteRegistry } from '../../base/react';
16 13
 import { MiddlewareRegistry, ReducerRegistry } from '../../base/redux';
17 14
 import { SoundCollection } from '../../base/sounds';
@@ -126,24 +123,10 @@ export class AbstractApp extends Component {
126 123
      */
127 124
     componentWillMount() {
128 125
         this._init.then(() => {
129
-            const { dispatch, getState } = this._getStore();
126
+            const { dispatch } = this._getStore();
130 127
 
131 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 130
             // We set the initialized state here and not in the contructor to
148 131
             // make sure that {@code componentWillMount} gets invoked before
149 132
             // the app tries to render the actual app content.
@@ -151,8 +134,6 @@ export class AbstractApp extends Component {
151 134
                 appAsyncInitialized: true
152 135
             });
153 136
 
154
-            dispatch(localParticipantJoined(localParticipant));
155
-
156 137
             // If a URL was explicitly specified to this React Component,
157 138
             // then open it; otherwise, use a default.
158 139
             this._openURL(toURLString(this.props.url) || this._getDefaultURL());

+ 30
- 1
react/features/base/participants/middleware.js Целия файл

@@ -12,6 +12,7 @@ import { playSound, registerSound, unregisterSound } from '../sounds';
12 12
 
13 13
 import {
14 14
     localParticipantIdChanged,
15
+    localParticipantJoined,
15 16
     participantUpdated
16 17
 } from './actions';
17 18
 import {
@@ -56,7 +57,8 @@ MiddlewareRegistry.register(store => next => action => {
56 57
     switch (action.type) {
57 58
     case APP_WILL_MOUNT:
58 59
         _registerSounds(store);
59
-        break;
60
+
61
+        return _localParticipantJoined(store, next, action);
60 62
     case APP_WILL_UNMOUNT:
61 63
         _unregisterSounds(store);
62 64
         break;
@@ -174,6 +176,33 @@ MiddlewareRegistry.register(store => next => action => {
174 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 207
  * Plays sounds when participants join/leave conference.
179 208
  *

Loading…
Отказ
Запис