1import type * as kv from "@distilled.cloud/aws/kinesis-video";
2import type * as kvm from "@distilled.cloud/aws/kinesis-video-media";
3import type * as Effect from "effect/Effect";
4import * as Binding from "../../Binding.ts";
5import type { Stream } from "./Stream.ts";
6
7export interface GetMediaRequest extends Omit<
8 kvm.GetMediaInput,
9 "StreamName" | "StreamARN"
10> {}
11
12/**
13 * Runtime binding for `kinesisvideo:GetMedia` (media data plane).
14 *
15 * Bind this operation to a `Stream` inside a function runtime to get a
16 * callable that resolves the per-stream data endpoint (`GetDataEndpoint`)
17 * and opens a media stream starting at the requested selector. The
18 * response `Payload` is a streaming body of MKV-packaged media.
19 * ### Reading Media
20 * **Example:** Read Media from the Earliest Fragment
21 * ```typescript
22 * // init
23 * const getMedia = yield* AWS.KinesisVideo.GetMedia(stream);
24 *
25 * // runtime
26 * const media = yield* getMedia({
27 * StartSelector: { StartSelectorType: "EARLIEST" },
28 * });
29 * ```
30 *
31 * **Example:** Wire into a Lambda Function
32 * ```typescript
33 * // Provide the GetMediaHttp layer on the Function's init Effect; merge
34 * // with the other KinesisVideo layers when using several bindings.
35 * export default MediaFunction.make(
36 * { main: import.meta.url, functionUrl: true, timeout: Duration.seconds(30) },
37 * Effect.gen(function* () {
38 * const stream = yield* AWS.KinesisVideo.Stream("Camera", {
39 * mediaType: "video/h264",
40 * dataRetention: "24 hours",
41 * });
42 * const getMedia = yield* AWS.KinesisVideo.GetMedia(stream);
43 * // ... read media.Payload in the fetch handler
44 * return { fetch: handler };
45 * }).pipe(Effect.provide(AWS.KinesisVideo.GetMediaHttp)),
46 * );
47 * ```
48 *
49 * @binding
50 */
51export interface GetMedia extends Binding.Service<
52 GetMedia,
53 "AWS.KinesisVideo.GetMedia",
54 <S extends Stream>(
55 stream: S,
56 ) => Effect.Effect<
57 (
58 request: GetMediaRequest,
59 ) => Effect.Effect<
60 kvm.GetMediaOutput,
61 kvm.GetMediaError | kv.GetDataEndpointError
62 >
63 >
64> {}
65
66export const GetMedia = Binding.Service<GetMedia>("AWS.KinesisVideo.GetMedia");