publish

Bun

Symbol

Server.publish

publish(topic: string, data: string | ArrayBuffer | SharedArrayBuffer | ArrayBufferView<ArrayBufferLike>, compress?: boolean): number

Send a message to all connected ServerWebSocket subscribed to a topic

@param topic

The topic to publish to

@param data

The data to send

@param compress

Should the data be compressed? Ignored if the client does not support compression.

@returns

0 if the message was dropped, -1 if backpressure was applied, or the number of bytes sent.

server.publish("chat", "Hello World");

Referenced types

class ArrayBuffer

Represents a raw buffer of binary data, which is used to store data for the different typed arrays. ArrayBuffers cannot be read from or written to directly, but can be passed to a typed array or DataView Object to interpret the raw buffer as needed.

  • readonly [Symbol.toStringTag]: string
  • readonly byteLength: number

    Read-only. The length of the ArrayBuffer (in bytes).

  • resize(newByteLength?: number): void

    Resizes the ArrayBuffer to the specified size (in bytes).

    MDN

    resize(byteLength: number): ArrayBuffer

    Resize an ArrayBuffer in-place.

  • slice(begin: number, end?: number): ArrayBuffer

    Returns a section of an ArrayBuffer.

  • transfer(newByteLength?: number): ArrayBuffer

    Creates a new ArrayBuffer with the same byte content as this buffer, then detaches this buffer.

    MDN

  • transferToFixedLength(newByteLength?: number): ArrayBuffer

    Creates a new non-resizable ArrayBuffer with the same byte content as this buffer, then detaches this buffer.

    MDN

interface SharedArrayBuffer

type ArrayBufferView<TArrayBuffer extends ArrayBufferLike = ArrayBufferLike> = NodeJS.TypedArray<TArrayBuffer> | DataView<TArrayBuffer>