Options
All
  • Public
  • Public/Protected
  • All
Menu

A Sync primitive for pub-sub messaging. Stream Messages are not persisted, exist only in transit, and will be dropped if (due to congestion or network anomalies) they cannot be delivered promptly. Use the SyncClient.stream method to obtain a reference to a Sync Message Stream. Information about rate limits can be found here.

Hierarchy

  • Closeable
    • SyncStream

Index

Events

Static Readonly messagePublished

messagePublished: "messagePublished" = 'messagePublished'

Fired when a message is published to the stream either locally or by a remote actor.

Parameters:

  1. object args - info object provided with the event. It has the following properties:
    • SyncStreamMessage message - Published message
    • boolean isLocal - equals true if the message was published by a local actor, false otherwise
example
stream.on('messagePublished', (args) => {
  console.log('Stream message published');
  console.log('Message SID:', args.message.sid);
  console.log('Message data: ', args.message.data);
  console.log('args.isLocal:', args.isLocal);
});

Static Readonly removed

removed: "removed" = 'removed'

Fired when a stream is removed entirely, regardless of whether the remover was local or remote.

Parameters:

  1. object args - info object provided with the event. It has the following properties:
    • boolean isLocal - equals true if the stream was removed by a local actor, false otherwise
example
stream.on('removed', (args) => {
  console.log(`Stream ${stream.sid} was removed`);
  console.log('args.isLocal:', args.isLocal);
});

Accessors

sid

  • get sid(): string
  • The immutable system-assigned identifier of this stream. Never null.

    Returns string

uniqueName

  • get uniqueName(): string
  • A unique identifier optionally assigned to the stream on creation.

    Returns string

Methods

close

  • close(): void
  • Conclude work with the stream instance and remove all event listeners attached to it. Any subsequent operation on this object will be rejected with error. Other local copies of this stream will continue operating and receiving events normally.

    example
    stream.close();
    

    Returns void

publishMessage

  • Publish a message to the stream. The system will attempt delivery to all online subscribers.

    example
    stream.publishMessage({ x: 42, y: 123 })
      .then((message) => {
        console.log('Stream publishMessage() successful, message SID:', message.sid);
      })
      .catch((error) => {
        console.error('Stream publishMessage() failed', error);
      });
    

    Parameters

    • data: object

      The body of the dispatched message. Maximum size in serialized JSON: 4KB. A rate limit applies to this operation, refer to the Sync API documentation for details.

    Returns Promise<SyncStreamMessage>

    A promise which resolves after the message is successfully published to the Sync service. Resolves irrespective of ultimate delivery to any subscribers.

removeStream

  • removeStream(): Promise<void>
  • Permanently delete this Stream.

    example
    stream.removeStream()
      .then(() => {
        console.log('Stream removeStream() successful');
      })
      .catch((error) => {
        console.error('Stream removeStream() failed', error);
      });
    

    Returns Promise<void>

    A promise which resolves after the Stream is successfully deleted.

setTtl

  • setTtl(ttl: number): Promise<void>
  • Update the time-to-live of the stream.

    example
    stream.setTtl(3600)
      .then(() => {
        console.log('Stream setTtl() successful');
      })
      .catch((error) => {
        console.error('Stream setTtl() failed', error);
      });
    

    Parameters

    • ttl: number

      Specifies the TTL in seconds after which the stream is subject to automatic deletion. The value 0 means infinity.

    Returns Promise<void>

    A promise that resolves after the TTL update was successful.