Add getYouTubeBroadcastStatus helper
Query YouTube liveBroadcasts API to get lifecycle status (created, ready, testing, live, complete, revoked) for a given broadcast ID.
This commit is contained in:
@@ -202,6 +202,24 @@ export async function createYouTubeBroadcast(
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function getYouTubeBroadcastStatus(
|
||||||
|
accessToken: string,
|
||||||
|
broadcastId: string,
|
||||||
|
): Promise<string | null> {
|
||||||
|
const res = await fetch(
|
||||||
|
`https://www.googleapis.com/youtube/v3/liveBroadcasts?part=status&id=${broadcastId}`,
|
||||||
|
{
|
||||||
|
headers: { Authorization: `Bearer ${accessToken}` },
|
||||||
|
},
|
||||||
|
);
|
||||||
|
if (!res.ok) return null;
|
||||||
|
const data = (await res.json()) as any;
|
||||||
|
const items = data.items ?? [];
|
||||||
|
if (items.length === 0) return null;
|
||||||
|
// lifeCycleStatus: created, ready, testing, live, complete, revoked
|
||||||
|
return items[0].status?.lifeCycleStatus ?? null;
|
||||||
|
}
|
||||||
|
|
||||||
export async function transitionYouTubeBroadcast(
|
export async function transitionYouTubeBroadcast(
|
||||||
accessToken: string,
|
accessToken: string,
|
||||||
broadcastId: string,
|
broadcastId: string,
|
||||||
|
|||||||
Reference in New Issue
Block a user