Manages subscription channels and coordinates node update subscriptions. This is the central hub for all parameter update subscriptions from various sources (custom channels)

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

Subscription pattern: register one or more channels, set global channel order, then subscribeToNode(node, callback). Node must have .id; for channel selection it may have .type, .metadata, .subscriptionConfig.channelOrder. Callback receives ESPNodeUpdateData.

// Register channels
await ESPRMNeoBase.subscriptionManager.registerChannel(new MQTTSubscriptionChannel());

// Set global channel order (applies to nodes without their own override)
ESPRMNeoBase.subscriptionManager.setGlobalChannelOrder(["mqtt"]);

// Subscribe to node updates (node can be an SDK node or a proxy with { id, nodeId, type, config, metadata })
await ESPRMNeoBase.subscriptionManager.subscribeToNode(node, (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 ESPRMNeoBase.subscriptionManager.dispose();
    
  • Get the effective channel order for a node. Priority: node.subscriptionConfig.channelOrder > global channel order

    Parameters

    • node: NodeLike

      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 = ESPRMNeoBase.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 mqttChannel = new MQTTSubscriptionChannel();
    await ESPRMNeoBase.subscriptionManager.registerChannel(mqttChannel);
  • 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 MQTT
    ESPRMNeoBase.subscriptionManager.setGlobalChannelOrder([
    "matter",
    "mqtt"
    ]);
  • Subscribe to updates for all nodes.

    Parameters

    • nodes: NodeLike[]

      Array of nodes to subscribe to

    • callback: (update: ESPNodeUpdateData) => void

      Function to call when any node is updated

    Returns Promise<void>

    const nodes = group.getNodes();
    await ESPRMNeoBase.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

    • node: NodeLike

      The node to subscribe to

    • callback: (update: ESPNodeUpdateData) => void

      Function to call when updates are received

    Returns Promise<void>

    Error if no channels are available or all channels fail

    await ESPRMNeoBase.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 ESPRMNeoBase.subscriptionManager.unregisterChannel("mqtt");
    
  • Unsubscribe from updates for a specific node across all channels.

    Parameters

    • nodeId: string

      ID of the node to unsubscribe from.

    • Optionalcallback: (update: ESPNodeUpdateData) => void

      Optional specific subscriber to remove. When provided, only that callback is detached (the node's other subscribers keep receiving updates); when omitted, all subscribers for the node are removed AND the node's MQTT shadow binding on NodeMQTTOrchestrator is cleared — so the next subscribe re-registers a fresh shadow name (needed when app-side membership changes the node's shadow topic).

    Returns Promise<void>

    // Remove one subscriber (siblings keep receiving updates):
    await ESPRMNeoBase.subscriptionManager.unsubscribeFromNode("node-123", myCallback);
    // Remove every subscriber for the node + clear MQTT shadow binding:
    await ESPRMNeoBase.subscriptionManager.unsubscribeFromNode("node-123");