Преглед изворни кода

feat(tracks): place remote tracks into the redux store

- Use actions trackAdded and trackRemoved to add and remove remote
  tracks from the redux store
- Emit out to non-react components on track added and removed in
  the track middleware
- Emit out to existing non-react components on track mute and
  video type changes
master
Leonard Kim пре 8 година
родитељ
комит
2a446b8799
2 измењених фајлова са 48 додато и 16 уклоњено
  1. 12
    15
      conference.js
  2. 36
    1
      react/features/base/tracks/middleware.js

+ 12
- 15
conference.js Прегледај датотеку

@@ -42,6 +42,7 @@ import {
42 42
     participantRoleChanged,
43 43
     participantUpdated
44 44
 } from './react/features/base/participants';
45
+import { trackAdded, trackRemoved } from './react/features/base/tracks';
45 46
 import {
46 47
     showDesktopPicker
47 48
 } from  './react/features/desktop-picker';
@@ -1327,36 +1328,32 @@ export default {
1327 1328
             if(!track || track.isLocal())
1328 1329
                 return;
1329 1330
 
1330
-            track.on(TrackEvents.TRACK_VIDEOTYPE_CHANGED, (type) => {
1331
-                APP.UI.onPeerVideoTypeChanged(track.getParticipantId(), type);
1332
-            });
1333
-            APP.UI.addRemoteStream(track);
1331
+            APP.store.dispatch(trackAdded(track));
1334 1332
         });
1335 1333
 
1336 1334
         room.on(ConferenceEvents.TRACK_REMOVED, (track) => {
1337 1335
             if(!track || track.isLocal())
1338 1336
                 return;
1339 1337
 
1340
-            APP.UI.removeRemoteStream(track);
1338
+            APP.store.dispatch(trackRemoved(track));
1341 1339
         });
1342 1340
 
1343 1341
         room.on(ConferenceEvents.TRACK_MUTE_CHANGED, (track) => {
1344
-            if(!track)
1342
+            if (!track || !track.isLocal()) {
1345 1343
                 return;
1344
+            }
1345
+
1346 1346
             const handler = (track.getType() === "audio")?
1347 1347
                 APP.UI.setAudioMuted : APP.UI.setVideoMuted;
1348
-            let id;
1349 1348
             const mute = track.isMuted();
1350
-            if(track.isLocal()){
1351
-                id = APP.conference.getMyUserId();
1352
-                if(track.getType() === "audio") {
1353
-                    this.audioMuted = mute;
1354
-                } else {
1355
-                    this.videoMuted = mute;
1356
-                }
1349
+            const id = APP.conference.getMyUserId();
1350
+
1351
+            if (track.getType() === "audio") {
1352
+                this.audioMuted = mute;
1357 1353
             } else {
1358
-                id = track.getParticipantId();
1354
+                this.videoMuted = mute;
1359 1355
             }
1356
+
1360 1357
             handler(id , mute);
1361 1358
         });
1362 1359
         room.on(ConferenceEvents.TRACK_AUDIO_LEVEL_CHANGED, (id, lvl) => {

+ 36
- 1
react/features/base/tracks/middleware.js Прегледај датотеку

@@ -18,9 +18,11 @@ import {
18 18
     createLocalTracks,
19 19
     destroyLocalTracks
20 20
 } from './actions';
21
-import { TRACK_UPDATED } from './actionTypes';
21
+import { TRACK_ADDED, TRACK_REMOVED, TRACK_UPDATED } from './actionTypes';
22 22
 import { getLocalTrack, setTrackMuted } from './functions';
23 23
 
24
+declare var APP: Object;
25
+
24 26
 /**
25 27
  * Middleware that captures LIB_DID_DISPOSE and LIB_DID_INIT actions and,
26 28
  * respectively, creates/destroys local media tracks. Also listens to
@@ -92,7 +94,40 @@ MiddlewareRegistry.register(store => next => action => {
92 94
         break;
93 95
     }
94 96
 
97
+    case TRACK_ADDED:
98
+        // TODO Remove this middleware case once all UI interested in new tracks
99
+        // being added are converted to react and listening for store changes.
100
+        if (typeof APP !== 'undefined' && !action.track.local) {
101
+            APP.UI.addRemoteStream(action.track.jitsiTrack);
102
+        }
103
+        break;
104
+
105
+    case TRACK_REMOVED:
106
+        // TODO Remove this middleware case once all UI interested in tracks
107
+        // being removed are converted to react and listening for store changes.
108
+        if (typeof APP !== 'undefined' && !action.track.local) {
109
+            APP.UI.removeRemoteStream(action.track.jitsiTrack);
110
+        }
111
+        break;
112
+
95 113
     case TRACK_UPDATED:
114
+        // TODO Remove the below calls to APP.UI once components interested in
115
+        // track mute changes are moved into react.
116
+        if (typeof APP !== 'undefined' && !action.track.local) {
117
+            const { jitsiTrack } = action.track;
118
+            const isMuted = jitsiTrack.isMuted();
119
+            const participantID = jitsiTrack.getParticipantId();
120
+            const { videoType } = jitsiTrack;
121
+
122
+            if (videoType) {
123
+                APP.UI.setVideoMuted(participantID, isMuted);
124
+                APP.UI.onPeerVideoTypeChanged(
125
+                    participantID, jitsiTrack.videoType);
126
+            } else {
127
+                APP.UI.setAudioMuted(participantID, isMuted);
128
+            }
129
+        }
130
+
96 131
         return _trackUpdated(store, next, action);
97 132
     }
98 133
 

Loading…
Откажи
Сачувај