Guide

Message


On message hook, you receive a message object containing data from the client.

Message object is API-compatible with standard Websocket MessageEvent with convenient superset of utils.

Instance properties

message.id

Unique random identifier (uuid v4) for the message.

message.event

Access to the original message event if available.

message.peer

Access to the peer instance that emitted the message.

message.rawData

Raw message data (can be of any type).

message.data

Message data (value varies based on peer.binaryType).

message.text()

Get stringified text version of the message.

If raw data is in any other format, it will be automatically converted or decoded.

message.json()

Get parsed version of the message text with JSON.parse().

message.uint8Array()

Get data as Uint8Array value.

If raw data is in any other format or string, it will be automatically converted or encoded.

message.arrayBuffer()

Get data as ArrayBuffer or SharedArrayBuffer value.

If raw data is in any other format or string, it will be automatically converted or encoded.

message.blob()

Get data as Blob value.

If raw data is in any other format or string, it will be automatically converted or encoded.

Instance methods

Adapter support

BunCloudflareCloudflare (durable)DenoNode (ws)Node (μWebSockets)SSE
event