Skip to content

SendEvent

Source: src/AWS/IVSChat/SendEvent.ts

Send an application-defined event to every client connected to the bound room — the effectful call made from a deployed Lambda or Task. Use it to broadcast state changes (poll results, stream metadata, moderation notices) alongside user chat messages; attributes carries the payload as string key-value pairs.

Provide the SendEventHttp implementation layer on the Function effect, bind the room in the init phase, then call the returned client at runtime. The binding grants ivschat:SendEvent on the room and injects its ARN as the roomIdentifier automatically.

// init
const room = yield* IVSChat.Room("LiveChat");
const sendEvent = yield* IVSChat.SendEvent(room);
return {
fetch: Effect.gen(function* () {
// runtime
const { id } = yield* sendEvent({
eventName: "app:poll-result",
attributes: { question: "q1", winner: "option-b" },
});
return HttpServerResponse.json({ id });
}),
};
// on the Function effect:
// .pipe(Effect.provide(IVSChat.SendEventHttp))