Manages subscription channels and coordinates node update subscriptions. This is the central hub for all parameter update subscriptions from various sources (notifications, Matter, MQTT, BLE, custom channels, etc.)

The manager uses a priority-based approach:

  1. For each node, it determines the effective channel order (node-specific or global)
  2. It filters channels based on availability and node support
  3. It tries channels in order until one succeeds
// Register channels
await ESPRMBase.subscriptionManager.registerChannel(new NotificationSubscriptionChannel());
await ESPRMBase.subscriptionManager.registerChannel(new MatterSubscriptionChannel());

// Set global channel order
ESPRMBase.subscriptionManager.setGlobalChannelOrder(["matter", "notification"]);

// Subscribe to node updates
const nodes = await user.getNodes();
await ESPRMBase.subscriptionManager.subscribeToAllNodes(nodes, (update) => {
console.log(`Node ${update.nodeId} updated via ${update.source}`);
});

Constructors

Methods

  • Cleanup all subscriptions and dispose channels. Should be called when app is closing or SDK is being torn down.

    Returns Promise<void>

    await ESPRMBase.subscriptionManager.dispose();
    
  • Get available channels for a node. Filters channels based on:

    • Channel is registered
    • Channel supports the node (via supportsNode())
    • Channel is in the effective order

    Parameters

    Returns ESPSubscriptionChannelInterface[]

    Array of available channels in priority order

    const channels = ESPRMBase.subscriptionManager.getAvailableChannelsForNode(node);
    console.log(`Available channels: ${channels.map(c => c.channelId).join(", ")}`);
  • Get the effective channel order for a node. Priority: node.subscriptionConfig.channelOrder > global channel order

    Parameters

    • node: ESPRMNode

      The node to get channel order for

    Returns string[]

    Array of channel IDs in priority order

  • Get all registered channel IDs.

    Returns string[]

    Array of channel IDs

    const channels = ESPRMBase.subscriptionManager.getRegisteredChannels();
    console.log(`Registered channels: ${channels.join(", ")}`);
  • Initialize the subscription manager. This initializes all registered channels. Should be called during SDK initialization.

    Returns Promise<void>

    Promise that resolves when initialization is complete

  • Register a new subscription channel.

    Parameters

    • channel: ESPSubscriptionChannelInterface

      The channel to register

    • autoInitialize: boolean = true

      Whether to initialize the channel immediately (default: true)

    Returns Promise<void>

    Error if a channel with the same ID is already registered

    const matterChannel = new MatterSubscriptionChannel();
    await ESPRMBase.subscriptionManager.registerChannel(matterChannel);
  • Set the global default channel order. This order is used for all nodes unless they have a custom order in subscriptionConfig.

    Parameters

    • channelIds: string[]

      Array of channel IDs in priority order (first = highest priority)

    Returns void

    // Try Matter first, then notifications, then MQTT
    ESPRMBase.subscriptionManager.setGlobalChannelOrder([
    "matter",
    "notification",
    "mqtt"
    ]);
  • Subscribe to updates for all nodes. This is used by the global ESPRMEventType.nodeUpdates subscription.

    Parameters

    • nodes: ESPRMNode[]

      Array of nodes to subscribe to

    • callback: (update: ESPNodeUpdateData) => void

      Function to call when any node is updated

    Returns Promise<void>

    const nodes = await user.getNodes();
    await ESPRMBase.subscriptionManager.subscribeToAllNodes(nodes, (update) => {
    console.log(`Node ${update.nodeId} updated`);
    });
  • Subscribe to updates for a specific node using priority-based channel selection. Tries channels in order until one succeeds.

    Parameters

    Returns Promise<void>

    Error if no channels are available or all channels fail

    await ESPRMBase.subscriptionManager.subscribeToNode(node, (update) => {
    console.log(`Update from ${update.source}:`, update.payload);
    });
  • Unregister a subscription channel. This will dispose the channel and remove it from the manager.

    Parameters

    • channelId: string

      ID of the channel to unregister

    Returns Promise<void>

    await ESPRMBase.subscriptionManager.unregisterChannel("mqtt");
    
  • Unsubscribe from updates for a specific node. This will unsubscribe from all channels for the node.

    Parameters

    • nodeId: string

      ID of the node to unsubscribe from

    Returns Promise<void>

    await ESPRMBase.subscriptionManager.unsubscribeFromNode("node-123");