| 1 | import type * as ivs from "@distilled.cloud/aws/ivs"; |
| 2 | import type * as Effect from "effect/Effect"; |
| 3 | import * as Binding from "../../Binding.ts"; |
| 4 | import type { Channel } from "./Channel.ts"; |
| 5 | |
| 6 | /** |
| 7 | * Runtime binding for `ivs:GetStream`. |
| 8 | * |
| 9 | * Reads the bound {@link Channel}'s active (live) stream — state, health, |
| 10 | * viewer count, and playback URL. Fails with the typed |
| 11 | * `ChannelNotBroadcasting` tag when the channel is not live. The channel |
| 12 | * ARN is injected from the binding. Provide the implementation with |
| 13 | * `Effect.provide(AWS.IVS.GetStreamHttp)`. |
| 14 | * ### Monitoring Live Streams |
| 15 | * **Example:** Check Whether a Channel Is Live |
| 16 | * ```typescript |
| 17 | * // init — bind the operation to the channel |
| 18 | * const getStream = yield* AWS.IVS.GetStream(channel); |
| 19 | * |
| 20 | * // runtime |
| 21 | * const live = yield* getStream().pipe( |
| 22 | * Effect.map(({ stream }) => ({ live: true, viewers: stream?.viewerCount })), |
| 23 | * Effect.catchTag("ChannelNotBroadcasting", () => |
| 24 | * Effect.succeed({ live: false, viewers: 0 }), |
| 25 | * ), |
| 26 | * ); |
| 27 | * ``` |
| 28 | * |
| 29 | * @binding |
| 30 | */ |
| 31 | export interface GetStream extends Binding.Service< |
| 32 | GetStream, |
| 33 | "AWS.IVS.GetStream", |
| 34 | ( |
| 35 | channel: Channel, |
| 36 | ) => Effect.Effect< |
| 37 | () => Effect.Effect<ivs.GetStreamResponse, ivs.GetStreamError> |
| 38 | > |
| 39 | > {} |
| 40 | export const GetStream = Binding.Service<GetStream>("AWS.IVS.GetStream"); |