Skip to content

Commit

Permalink
fix: create livestream
Browse files Browse the repository at this point in the history
  • Loading branch information
0xcadams committed Apr 25, 2024
1 parent 3295edc commit 0e784ed
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions examples/with-pubnub/src/app/actions.ts
@@ -1,13 +1,25 @@
"use server";

import type { Stream } from "livepeer/dist/models/components";
import { revalidatePath } from "next/cache";
import { cookies } from "next/headers";

export const createLivestream = async () => {
try {
if (process.env.STREAM_KEY && process.env.PLAYBACK_ID) {
cookies().set("stream-key", process.env.STREAM_KEY);
cookies().set("playback-id", "26d5m3zw80ejzby6");
const response: Stream = await fetch("https://livepeer.studio/api/stream", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.STUDIO_API_KEY ?? "none"}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
name: "Pubnub <> Livepeer",
}),
}).then((response) => response.json());

if (response.streamKey && response.playbackId) {
cookies().set("stream-key", response.streamKey);
cookies().set("playback-id", response.playbackId);
} else {
return {
success: false,
Expand Down

0 comments on commit 0e784ed

Please sign in to comment.