| 1 | import type * as ivsrealtime from "@distilled.cloud/aws/ivs-realtime"; |
| 2 | import type * as Duration from "effect/Duration"; |
| 3 | import type * as Effect from "effect/Effect"; |
| 4 | import * as Binding from "../../Binding.ts"; |
| 5 | import type { Stage } from "./Stage.ts"; |
| 6 | |
| 7 | /** |
| 8 | * The `stageArn` is injected by the binding from the bound stage, and the |
| 9 | * wire `duration` (whole minutes) is expressed as a `Duration.Input`. |
| 10 | */ |
| 11 | export interface CreateParticipantTokenRequest extends Omit< |
| 12 | ivsrealtime.CreateParticipantTokenRequest, |
| 13 | "stageArn" | "duration" |
| 14 | > { |
| 15 | /** |
| 16 | * How long the issued participant token remains valid. Converted to whole |
| 17 | * minutes on the wire (`1` - `20160` minutes, i.e. up to 14 days). |
| 18 | * @default 720 minutes (12 hours) |
| 19 | */ |
| 20 | duration?: Duration.Input; |
| 21 | } |
| 22 | |
| 23 | /** |
| 24 | * Mint a participant token that an end user presents to join the bound |
| 25 | * stage — the effectful call made from a deployed Lambda or Task. The |
| 26 | * `capabilities` field grants `PUBLISH` and/or `SUBSCRIBE` to the token |
| 27 | * holder; `attributes` attaches profile data (display name, avatar, …) that |
| 28 | * is visible to other participants. The returned `token` is sensitive and |
| 29 | * surfaces as a `Redacted` value. |
| 30 | * |
| 31 | * ### Minting Participant Tokens |
| 32 | * Provide the `CreateParticipantTokenHttp` implementation layer on the |
| 33 | * Function effect, bind the stage in the init phase, then call the returned |
| 34 | * client at runtime. The binding grants `ivs:CreateParticipantToken` on the |
| 35 | * stage and injects its ARN automatically. |
| 36 | * |
| 37 | * **Example:** Mint a token from a Lambda |
| 38 | * ```typescript |
| 39 | * // init |
| 40 | * const stage = yield* IVSRealtime.Stage("VideoRoom"); |
| 41 | * const createParticipantToken = yield* IVSRealtime.CreateParticipantToken(stage); |
| 42 | * |
| 43 | * return { |
| 44 | * fetch: Effect.gen(function* () { |
| 45 | * // runtime |
| 46 | * const { participantToken } = yield* createParticipantToken({ |
| 47 | * userId: "user-123", |
| 48 | * capabilities: ["PUBLISH", "SUBSCRIBE"], |
| 49 | * duration: "30 minutes", |
| 50 | * attributes: { displayName: "Sam" }, |
| 51 | * }); |
| 52 | * return HttpServerResponse.json({ |
| 53 | * token: |
| 54 | * participantToken?.token !== undefined |
| 55 | * ? Redacted.value(participantToken.token) |
| 56 | * : undefined, |
| 57 | * participantId: participantToken?.participantId, |
| 58 | * }); |
| 59 | * }), |
| 60 | * }; |
| 61 | * // on the Function effect: |
| 62 | * // .pipe(Effect.provide(IVSRealtime.CreateParticipantTokenHttp)) |
| 63 | * ``` |
| 64 | * |
| 65 | * @binding |
| 66 | */ |
| 67 | export interface CreateParticipantToken extends Binding.Service< |
| 68 | CreateParticipantToken, |
| 69 | "AWS.IVSRealtime.CreateParticipantToken", |
| 70 | ( |
| 71 | stage: Stage, |
| 72 | ) => Effect.Effect< |
| 73 | ( |
| 74 | request?: CreateParticipantTokenRequest, |
| 75 | ) => Effect.Effect< |
| 76 | ivsrealtime.CreateParticipantTokenResponse, |
| 77 | ivsrealtime.CreateParticipantTokenError |
| 78 | > |
| 79 | > |
| 80 | > {} |
| 81 | export const CreateParticipantToken = Binding.Service<CreateParticipantToken>( |
| 82 | "AWS.IVSRealtime.CreateParticipantToken", |
| 83 | ); |