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:
parent
2a55548b84
commit
219b93a3c9
|
@ -244,13 +244,7 @@ class StartLiveStreamDialog extends Component {
|
||||||
})
|
})
|
||||||
.then(() => googleApi.requestAvailableYouTubeBroadcasts())
|
.then(() => googleApi.requestAvailableYouTubeBroadcasts())
|
||||||
.then(response => {
|
.then(response => {
|
||||||
const broadcasts = response.result.items.map(item => {
|
const broadcasts = this._parseBroadcasts(response.result.items);
|
||||||
return {
|
|
||||||
title: item.snippet.title,
|
|
||||||
boundStreamID: item.contentDetails.boundStreamId,
|
|
||||||
status: item.status.lifeCycleStatus
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
this._setStateIfMounted({
|
this._setStateIfMounted({
|
||||||
broadcasts
|
broadcasts
|
||||||
|
@ -331,8 +325,11 @@ class StartLiveStreamDialog extends Component {
|
||||||
_onYouTubeBroadcastIDSelected(boundStreamID) {
|
_onYouTubeBroadcastIDSelected(boundStreamID) {
|
||||||
return googleApi.requestLiveStreamsForYouTubeBroadcast(boundStreamID)
|
return googleApi.requestLiveStreamsForYouTubeBroadcast(boundStreamID)
|
||||||
.then(response => {
|
.then(response => {
|
||||||
const found = response.result.items[0];
|
const broadcasts = response.result.items;
|
||||||
const streamKey = found.cdn.ingestionInfo.streamName;
|
const streamName = broadcasts
|
||||||
|
&& broadcasts[0]
|
||||||
|
&& broadcasts[0].cdn.ingestionInfo.streamName;
|
||||||
|
const streamKey = streamName || '';
|
||||||
|
|
||||||
this._setStateIfMounted({
|
this._setStateIfMounted({
|
||||||
streamKey,
|
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.
|
* Renders a React Element for authenticating with the Google web client.
|
||||||
*
|
*
|
||||||
|
|
|
@ -205,7 +205,7 @@ const googleApi = {
|
||||||
_getURLForLiveBroadcasts() {
|
_getURLForLiveBroadcasts() {
|
||||||
return [
|
return [
|
||||||
'https://content.googleapis.com/youtube/v3/liveBroadcasts',
|
'https://content.googleapis.com/youtube/v3/liveBroadcasts',
|
||||||
'?broadcastType=persistent',
|
'?broadcastType=all',
|
||||||
'&mine=true&part=id%2Csnippet%2CcontentDetails%2Cstatus'
|
'&mine=true&part=id%2Csnippet%2CcontentDetails%2Cstatus'
|
||||||
].join('');
|
].join('');
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue