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
This commit is contained in:
virtuacoplenny 2018-04-13 13:49:24 -07:00 committed by bbaldino
parent 2a55548b84
commit 219b93a3c9
2 changed files with 36 additions and 10 deletions

View File

@ -244,13 +244,7 @@ class StartLiveStreamDialog extends Component {
})
.then(() => googleApi.requestAvailableYouTubeBroadcasts())
.then(response => {
const broadcasts = response.result.items.map(item => {
return {
title: item.snippet.title,
boundStreamID: item.contentDetails.boundStreamId,
status: item.status.lifeCycleStatus
};
});
const broadcasts = this._parseBroadcasts(response.result.items);
this._setStateIfMounted({
broadcasts
@ -331,8 +325,11 @@ class StartLiveStreamDialog extends Component {
_onYouTubeBroadcastIDSelected(boundStreamID) {
return googleApi.requestLiveStreamsForYouTubeBroadcast(boundStreamID)
.then(response => {
const found = response.result.items[0];
const streamKey = found.cdn.ingestionInfo.streamName;
const broadcasts = response.result.items;
const streamName = broadcasts
&& broadcasts[0]
&& broadcasts[0].cdn.ingestionInfo.streamName;
const streamKey = streamName || '';
this._setStateIfMounted({
streamKey,
@ -341,6 +338,35 @@ class StartLiveStreamDialog extends Component {
});
}
/**
* Takes in a list of broadcasts from the YouTube API, removes dupes,
* removes broadcasts that cannot get a stream key, and parses the
* broadcasts into flat objects.
*
* @param {Array} broadcasts - Broadcast descriptions as obtained from
* calling the YouTube API.
* @private
* @returns {Array} An array of objects describing each unique broadcast.
*/
_parseBroadcasts(broadcasts) {
const parsedBroadcasts = {};
for (let i = 0; i < broadcasts.length; i++) {
const broadcast = broadcasts[i];
const boundStreamID = broadcast.contentDetails.boundStreamId;
if (boundStreamID && !parsedBroadcasts[boundStreamID]) {
parsedBroadcasts[boundStreamID] = {
boundStreamID,
status: broadcast.status.lifeCycleStatus,
title: broadcast.snippet.title
};
}
}
return Object.values(parsedBroadcasts);
}
/**
* Renders a React Element for authenticating with the Google web client.
*

View File

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