Skip to content
For the complete documentation index, see llms.txt. This page is also available as Markdown.

Binary messaging

Send raw byte buffers without JSON structure using sendBinary(). Use this for custom protocols, efficient op streams, or payloads that do not fit the structured send() model.

For images, audio, and documents in chat apps, prefer Structured payloads via send() — your onMessage handler gets a typed JSON body. Use sendBinary() when you control both ends of a custom binary format.


sendBinary() contract

Field
Required
Description

senderId

Yes

Must match the connecting user's userId

receiverIds

Yes

Array of target user IDs

buffer

Yes

Raw bytes (Uint8Array in JS, List<int> in Dart)

type

No

Frame type hint (default "binary")

Unlike send(), sendBinary() always requires receiverIds (array form).


When to use sendBinary vs send

Use send()

Use sendBinary()

Chat text, images, audio, docs

Custom binary protocol

JSON-serializable data

Game state, CRDT ops, compressed streams

Automatic chunking of structured payloads

Low-level framed bytes you parse yourself

Both methods chunk large buffers automatically.


Receiving binary

Binary frames arrive in onMessage. Inspect metadata.type and use payload.raw() when the body is not JSON:


Language guides

Language
Guide

JavaScript / TypeScript

Dart / Flutter


Last updated