@xlambda-tech/media
v0.2.0
Published
xlambda Media SDK: image/video/360-tour upload & transforms, plus live streaming (RTMP/WHIP ingest, WHEP/HLS playback).
Downloads
63
Readme
@xlambda-tech/media
Image, video, and 360-tour upload/transform, plus live streaming (RTMP/WHIP ingest, WHEP/HLS playback), for the xlambda platform.
import { MediaClient } from '@xlambda-tech/media';
const client = new MediaClient({ apiKey: process.env.XLAMBDA_API_KEY! });
const { mediaId } = await client.media.upload({
file: fileBytes, // Buffer, Uint8Array, or Blob/File
filename: 'photo.jpg',
contentType: 'image/jpeg',
});upload() collapses the platform's three-call flow (presign, PUT the
bytes, confirm) into one. For bulk uploads use uploadBatch() (presigns up
to 50 files in one request, transfers each independently). For piping bytes
you already hold server-side, use uploadStream() — a single multipart
request through this SDK's own process, no presigned URL involved.
On-demand image transforms
const url = client.image.transformUrl(mediaId, { width: 800, format: 'webp', quality: 75 });Pure URL builder, no network call — drop the result straight into an
<img src>.
Live streaming
const stream = await client.livestreams.create({ projectId, title: 'My stream' });
// stream.rtmpStreamKey -> paste into OBS's "Stream Key" field
// stream.hlsPlaybackUrl -> <video> src for viewers
await client.livestreams.simulcastTargets(stream.id).create({
label: 'YouTube',
destinationUrl: 'rtmp://a.rtmp.youtube.com/live2/<key>',
});RTMP/WHIP ingest and WHEP/HLS playback URLs are returned as plain strings for your encoder (OBS, etc.) or player to use directly — this SDK doesn't wrap the ingest/playback protocols themselves, since those are typically driven from a different runtime (an encoder, a browser) than the Node backend holding this client.
Handling webhook events
import { createMediaEventsHandler } from '@xlambda-tech/media';
export const { POST } = createMediaEventsHandler({
secret: process.env.XLAMBDA_WEBHOOK_SECRET!,
onReady: async ({ mediaId }) => { /* ... */ },
onLiveStreamRecorded: async ({ liveStreamId, mediaId }) => { /* ... */ },
}).toNextRouteHandler();See @xlambda-tech/core for the
Express/Fastify adapters and the full event catalog.
Not covered — use the dashboard
The unauthenticated unsigned-upload-preset flow (/v1/unsigned/uploads/:presetId)
and the internal S3/SRS callback routes aren't wrapped here — the former is
deferred to a later release, the latter is never customer-invoked.
