| 1 | import type * as kv from "@distilled.cloud/aws/kinesis-video"; |
| 2 | import type * as kvs from "@distilled.cloud/aws/kinesis-video-signaling"; |
| 3 | import type * as Effect from "effect/Effect"; |
| 4 | import * as Binding from "../../Binding.ts"; |
| 5 | import type { SignalingEndpointUnavailable } from "./internal.ts"; |
| 6 | import type { SignalingChannel } from "./SignalingChannel.ts"; |
| 7 | |
| 8 | export interface GetIceServerConfigRequest extends Omit< |
| 9 | kvs.GetIceServerConfigRequest, |
| 10 | "ChannelARN" |
| 11 | > {} |
| 12 | |
| 13 | /** |
| 14 | * Runtime binding for `kinesisvideo:GetIceServerConfig` (WebRTC signaling |
| 15 | * data plane). |
| 16 | * |
| 17 | * Bind this operation to a `SignalingChannel` inside a function runtime to |
| 18 | * get a callable that resolves the per-channel HTTPS signaling endpoint |
| 19 | * (`GetSignalingChannelEndpoint`) and returns TURN server URIs with |
| 20 | * short-lived credentials for establishing WebRTC connectivity. |
| 21 | * ### WebRTC Connectivity |
| 22 | * **Example:** ICE Server Configuration |
| 23 | * ```typescript |
| 24 | * // init |
| 25 | * const getIceServers = yield* AWS.KinesisVideo.GetIceServerConfig(channel); |
| 26 | * |
| 27 | * // runtime |
| 28 | * const { IceServerList } = yield* getIceServers({ ClientId: "viewer-1" }); |
| 29 | * ``` |
| 30 | * |
| 31 | * **Example:** Wire into a Lambda Function |
| 32 | * ```typescript |
| 33 | * // Provide the GetIceServerConfigHttp layer on the Function's init Effect. |
| 34 | * export default SignalingFunction.make( |
| 35 | * { main: import.meta.url, functionUrl: true, timeout: Duration.seconds(30) }, |
| 36 | * Effect.gen(function* () { |
| 37 | * const channel = yield* AWS.KinesisVideo.SignalingChannel("Doorbell"); |
| 38 | * const getIceServers = yield* AWS.KinesisVideo.GetIceServerConfig(channel); |
| 39 | * return { |
| 40 | * fetch: Effect.gen(function* () { |
| 41 | * const { IceServerList } = yield* getIceServers({ |
| 42 | * ClientId: "viewer-1", |
| 43 | * }); |
| 44 | * return HttpServerResponse.json({ iceServers: IceServerList }); |
| 45 | * }), |
| 46 | * }; |
| 47 | * }).pipe(Effect.provide(AWS.KinesisVideo.GetIceServerConfigHttp)), |
| 48 | * ); |
| 49 | * ``` |
| 50 | * |
| 51 | * @binding |
| 52 | */ |
| 53 | export interface GetIceServerConfig extends Binding.Service< |
| 54 | GetIceServerConfig, |
| 55 | "AWS.KinesisVideo.GetIceServerConfig", |
| 56 | <C extends SignalingChannel>( |
| 57 | channel: C, |
| 58 | ) => Effect.Effect< |
| 59 | ( |
| 60 | request?: GetIceServerConfigRequest, |
| 61 | ) => Effect.Effect< |
| 62 | kvs.GetIceServerConfigResponse, |
| 63 | | kvs.GetIceServerConfigError |
| 64 | | kv.GetSignalingChannelEndpointError |
| 65 | | SignalingEndpointUnavailable |
| 66 | > |
| 67 | > |
| 68 | > {} |
| 69 | |
| 70 | export const GetIceServerConfig = Binding.Service<GetIceServerConfig>( |
| 71 | "AWS.KinesisVideo.GetIceServerConfig", |
| 72 | ); |