|
|
@@ -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
|
*
|