PP.Media

Handle file buffers and thumbnails with built-in hooks for image/video processing. Optimized for media-heavy chats.

File Buffers

Send and receive binary payloads. The protocol uses the PP header to indicate binary mode and payload length.

// Send a file chunk
client.media.sendBuffer(roomId, buffer, { mime: 'image/png', name: 'screenshot.png' });

// Receive
client.media.on('buffer', ({ roomId, buffer, meta }) => {
  console.log(meta.name, buffer.byteLength);
});

Thumbnails

Built-in hooks let the server generate thumbnails for images/videos before relaying. Configure a thumbnail pipeline per room or globally.

server.media.setThumbnailHook(async (buffer, meta) => {
  const thumb = await generateThumb(buffer, { width: 200 });
  return { buffer: thumb, width: 200, height: 150 };
});

Combine with PP.Chat for rich media messages, or PP.Voice for call-related media.