Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface Group<MessageTypes>

Groups are a collection of nodes that can be reached in some way. This may either be a full network or a sub-set of one. Groups will emit events when membership changes via onNodeAvailable and onNodeUnavailable.

Messages sent to nodes in the group can be listened to via onMessage and broadcasts can be sent via broadcast.

const group = ...;

// Listen to messages
group.onMessage(message => ...);

// Join the group
await group.join();

// Leave the group
await group.leave();

Type parameters

  • MessageTypes: object = any

Hierarchy

  • Group

Implemented by

Index

Properties

Readonly name

name: string

Name of this group, useful for debugging purposes.

Readonly nodes

nodes: readonly Node<any>[]

Get all of the nodes that are part of this group.

Readonly onMessage

onMessage: Subscribable<Group<MessageTypes>, [message: MessageUnion<MessageTypes>]>

Event emitted when a message is received on this group.

Readonly onNodeAvailable

onNodeAvailable: Subscribable<Group<MessageTypes>, [node: Node<MessageTypes>]>

Event emitted when a new node joins this group.

Readonly onNodeUnavailable

onNodeUnavailable: Subscribable<Group<MessageTypes>, [node: Node<MessageTypes>]>

Event emitted when a node leaves this group.

Methods

broadcast

  • broadcast<T>(type: T, data: MessageData<MessageTypes, T>): Promise<void>
  • Broadcast a message to all nodes that have joined this group.

    Type parameters

    • T: string

    Parameters

    • type: T
      • the type of message to send
    • data: MessageData<MessageTypes, T>
      • the data to send

    Returns Promise<void>

join

  • join(): Promise<void>

leave

  • leave(): Promise<void>

Generated using TypeDoc