Pārlūkot izejas kodu

fix(recording): fetch events also for available broadcasts (#2810)

* fix(recording): fetch events also for available broadcasts

Only "persistent" broadcasts were being fetched using the
YouTube API. Fetching "all" will get persistent broadcasts
and events. If events use a custom encoder then the stream
key can be obtained. If google hangouts is used for the event
then a stream key will not be obtainable; in those cases
input empty string as the stream key.

* squash: fix typos, reword comments, use object for preventing duplicate broadcasts
master
virtuacoplenny 7 gadus atpakaļ
vecāks
revīzija
219b93a3c9

+ 35
- 9
react/features/recording/components/LiveStream/StartLiveStreamDialog.web.js Parādīt failu

@@ -244,13 +244,7 @@ class StartLiveStreamDialog extends Component {
244 244
             })
245 245
             .then(() => googleApi.requestAvailableYouTubeBroadcasts())
246 246
             .then(response => {
247
-                const broadcasts = response.result.items.map(item => {
248
-                    return {
249
-                        title: item.snippet.title,
250
-                        boundStreamID: item.contentDetails.boundStreamId,
251
-                        status: item.status.lifeCycleStatus
252
-                    };
253
-                });
247
+                const broadcasts = this._parseBroadcasts(response.result.items);
254 248
 
255 249
                 this._setStateIfMounted({
256 250
                     broadcasts
@@ -331,8 +325,11 @@ class StartLiveStreamDialog extends Component {
331 325
     _onYouTubeBroadcastIDSelected(boundStreamID) {
332 326
         return googleApi.requestLiveStreamsForYouTubeBroadcast(boundStreamID)
333 327
             .then(response => {
334
-                const found = response.result.items[0];
335
-                const streamKey = found.cdn.ingestionInfo.streamName;
328
+                const broadcasts = response.result.items;
329
+                const streamName = broadcasts
330
+                    && broadcasts[0]
331
+                    && broadcasts[0].cdn.ingestionInfo.streamName;
332
+                const streamKey = streamName || '';
336 333
 
337 334
                 this._setStateIfMounted({
338 335
                     streamKey,
@@ -341,6 +338,35 @@ class StartLiveStreamDialog extends Component {
341 338
             });
342 339
     }
343 340
 
341
+    /**
342
+     * Takes in a list of broadcasts from the YouTube API, removes dupes,
343
+     * removes broadcasts that cannot get a stream key, and parses the
344
+     * broadcasts into flat objects.
345
+     *
346
+     * @param {Array} broadcasts - Broadcast descriptions as obtained from
347
+     * calling the YouTube API.
348
+     * @private
349
+     * @returns {Array} An array of objects describing each unique broadcast.
350
+     */
351
+    _parseBroadcasts(broadcasts) {
352
+        const parsedBroadcasts = {};
353
+
354
+        for (let i = 0; i < broadcasts.length; i++) {
355
+            const broadcast = broadcasts[i];
356
+            const boundStreamID = broadcast.contentDetails.boundStreamId;
357
+
358
+            if (boundStreamID && !parsedBroadcasts[boundStreamID]) {
359
+                parsedBroadcasts[boundStreamID] = {
360
+                    boundStreamID,
361
+                    status: broadcast.status.lifeCycleStatus,
362
+                    title: broadcast.snippet.title
363
+                };
364
+            }
365
+        }
366
+
367
+        return Object.values(parsedBroadcasts);
368
+    }
369
+
344 370
     /**
345 371
      * Renders a React Element for authenticating with the Google web client.
346 372
      *

+ 1
- 1
react/features/recording/googleApi.js Parādīt failu

@@ -205,7 +205,7 @@ const googleApi = {
205 205
     _getURLForLiveBroadcasts() {
206 206
         return [
207 207
             'https://content.googleapis.com/youtube/v3/liveBroadcasts',
208
-            '?broadcastType=persistent',
208
+            '?broadcastType=all',
209 209
             '&mine=true&part=id%2Csnippet%2CcontentDetails%2Cstatus'
210 210
         ].join('');
211 211
     },

Notiek ielāde…
Atcelt
Saglabāt