{"version":3,"file":"MatterSubscriptionChannel.cjs","sources":["../../../../src/services/ESPMatterSubscriptionChannel/MatterSubscriptionChannel.ts"],"sourcesContent":["/*\n * SPDX-FileCopyrightText: 2026 Espressif Systems (Shanghai) CO LTD\n *\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { ESPRMNode } from \"@espressif/rainmaker-base-sdk\";\nimport type {\n  ESPNodeUpdateData,\n  ESPSubscriptionChannelInterface,\n} from \"../../types/subscription\";\nimport { MatterSubscriptionChannelIds } from \"../../utils/constants\";\n\n/**\n * Interface for Matter local control adapter.\n * Platform implementations must provide this adapter to enable Matter local control.\n * \n * The adapter handles the platform-specific Matter communication layer\n * (e.g., using @matter/main, react-native-matter, or platform-specific Matter SDKs).\n */\nexport interface ESPMatterAdapter {\n  /**\n   * Subscribe to attribute updates from a Matter device.\n   * \n   * @param nodeId - The Rainmaker node ID\n   * @param fabricId - The Matter fabric ID\n   * @param callback - Function to call when attribute updates are received\n   * @returns Promise that resolves when subscription is active\n   * \n   * @example\n   * ```typescript\n   * await adapter.subscribeToDevice(\n   *   \"node-123\",\n   *   \"fabric-456\",\n   *   (update) => {\n   *     console.log(\"Matter update:\", update);\n   *   }\n   * );\n   * ```\n   */\n  subscribeToDevice(\n    nodeId: string,\n    fabricId: string,\n    callback: (update: MatterDeviceUpdate) => void\n  ): Promise<void>;\n\n  /**\n   * Unsubscribe from attribute updates for a specific device.\n   * \n   * @param nodeId - The Rainmaker node ID\n   * @param fabricId - The Matter fabric ID\n   * @returns Promise that resolves when unsubscription is complete\n   */\n  unsubscribeFromDevice(nodeId: string, fabricId: string): Promise<void>;\n\n  /**\n   * Check if a device is currently reachable on the local network.\n   * \n   * @param nodeId - The Rainmaker node ID\n   * @param fabricId - The Matter fabric ID\n   * @returns Promise that resolves to true if device is reachable\n   */\n  isDeviceReachable(nodeId: string, fabricId: string): Promise<boolean>;\n\n  /**\n   * Initialize the Matter adapter.\n   * This should set up the Matter controller and any necessary connections.\n   * \n   * @returns Promise that resolves when initialization is complete\n   */\n  initialize(): Promise<void>;\n\n  /**\n   * Cleanup and dispose of Matter adapter resources.\n   * \n   * @returns Promise that resolves when disposal is complete\n   */\n  dispose(): Promise<void>;\n}\n\n/**\n * Matter device update data from the platform-specific Matter SDK.\n * This represents raw Matter attribute updates that will be transformed\n * to the standard ESPNodeUpdateData format.\n */\nexport interface MatterDeviceUpdate {\n  /**\n   * Matter endpoint ID (e.g., 1 for the main device endpoint)\n   */\n  endpointId: number;\n\n  /**\n   * Matter cluster ID (e.g., 6 for OnOff cluster, 8 for LevelControl)\n   */\n  clusterId: number;\n\n  /**\n   * Matter attribute ID (e.g., 0 for OnOff attribute)\n   */\n  attributeId: number;\n\n  /**\n   * The attribute value\n   */\n  value: any;\n\n  /**\n   * Optional timestamp of the update\n   */\n  timestamp?: number;\n\n  /**\n   * Optional metadata from the Matter layer\n   */\n  metadata?: Record<string, any>;\n}\n\n/**\n * Function type for resolving fabric ID from node ID.\n * This allows the channel to look up fabric information from the ESPRMMatterBase instance.\n */\nexport type FabricIdResolver = (nodeId: string) => Promise<string>;\n\n/**\n * Subscription channel for Matter local control.\n * Provides device parameter updates via Matter protocol for local network communication.\n * \n * This channel:\n * - Supports nodes whose type is `pure_matter` / `rainmaker_matter` or that carry Matter metadata\n * - Delegates to a platform-specific {@link ESPMatterAdapter} for the native Matter layer\n * - Transforms raw Matter attribute updates into the standard {@link ESPNodeUpdateData} format\n * \n * @example\n * ```typescript\n * const matterChannel = new MatterSubscriptionChannel(matterAdapter, fabricIdResolver);\n * await ESPRMBase.subscriptionManager.registerChannel(matterChannel);\n * ESPRMBase.subscriptionManager.setGlobalChannelOrder([\"matter\", \"notification\"]);\n * ```\n */\nexport class MatterSubscriptionChannel\n  implements ESPSubscriptionChannelInterface\n{\n  readonly channelId = MatterSubscriptionChannelIds.MATTER;\n\n  /**\n   * Platform-specific Matter adapter\n   */\n  private adapter: ESPMatterAdapter;\n\n  /**\n   * Function to resolve fabric ID from node ID\n   */\n  private fabricIdResolver?: FabricIdResolver;\n\n  /**\n   * Map of callbacks for specific nodes (nodeId -> Set of callbacks)\n   */\n  private callbacks: Map<string, Set<(update: ESPNodeUpdateData) => void>> =\n    new Map();\n\n  /**\n   * Map to track subscribed nodes (nodeId -> fabricId)\n   */\n  private subscribedNodes: Map<string, string> = new Map();\n\n  /**\n   * Set to track nodes currently being subscribed (prevents race conditions)\n   */\n  private subscribingNodes: Set<string> = new Set();\n\n  /**\n   * Whether the channel has been initialized\n   */\n  private isInitialized: boolean = false;\n\n  /**\n   * Create a new Matter subscription channel.\n   * \n   * @param adapter - Platform-specific Matter adapter implementation\n   * @param fabricIdResolver - Optional function to resolve fabric ID from node ID\n   */\n  constructor(adapter: ESPMatterAdapter, fabricIdResolver?: FabricIdResolver) {\n    this.adapter = adapter;\n    this.fabricIdResolver = fabricIdResolver;\n  }\n\n  /**\n   * Set the fabric ID resolver function.\n   * This is typically called by ESPRMMatterBase after construction.\n   * \n   * @param resolver - Function to resolve fabric ID from node ID\n   */\n  setFabricIdResolver(resolver: FabricIdResolver): void {\n    this.fabricIdResolver = resolver;\n  }\n\n  /**\n   * Initialize the Matter channel.\n   * Sets up the Matter adapter and prepares for device subscriptions.\n   */\n  async initialize(): Promise<void> {\n    if (this.isInitialized) {\n      return;\n    }\n\n    await this.adapter.initialize();\n    this.isInitialized = true;\n  }\n\n  /**\n   * Check if this channel supports a specific node.\n   *\n   * A node is treated as Matter-capable when it carries concrete evidence the\n   * channel can actually target — i.e. it is constructed as an\n   * {@link ESPRMMatterNode} (canonical `isMatter` marker), or it has a\n   * RainMaker API `metadata.Matter` payload, or it has an explicit Matter\n   * Node ID in metadata.\n   *\n   * The cloud `node_type` field is not consulted on its own because non-Matter\n   * RainMaker nodes can carry stale `node_type` values that incorrectly claim\n   * a Matter channel and produce spurious `no matterNodeId for rmNodeId=…`\n   * warnings on every `subscribeToAllNodes` pass.\n   *\n   * @param node - The node to check support for\n   * @returns true if the node has actionable Matter capability\n   */\n  supportsNode(node: ESPRMNode): boolean {\n    if ((node as { isMatter?: boolean }).isMatter === true) {\n      return true;\n    }\n\n    const metadata = node.metadata as\n      | {\n          Matter?: unknown;\n          matter_node_id?: unknown;\n          matterNodeId?: unknown;\n        }\n      | undefined;\n\n    return Boolean(\n      metadata?.Matter ||\n        metadata?.matter_node_id ||\n        metadata?.matterNodeId\n    );\n  }\n\n  /**\n   * Subscribe to Matter attribute updates for a specific node.\n   * \n   * Registers the callback immediately and initiates the underlying Matter\n   * adapter subscription asynchronously. This non-blocking design allows\n   * {@link ESPSubscriptionManager.subscribeToAllNodes} to process multiple\n   * nodes without waiting for each adapter handshake to complete.\n   * \n   * Callbacks registered before the adapter subscription is ready will begin\n   * receiving updates as soon as the subscription is established.\n   * \n   * @param callback - Function to call when updates are received\n   * @param nodeId - Node ID to subscribe to (required for Matter)\n   * @throws Error if nodeId is not provided\n   */\n  async subscribe(\n    callback: (update: ESPNodeUpdateData) => void,\n    nodeId?: string\n  ): Promise<void> {\n    if (!this.isInitialized) {\n      await this.initialize();\n    }\n\n    if (!nodeId) {\n      throw new Error(\n        \"Matter subscription requires a specific nodeId. Global subscriptions are not supported.\"\n      );\n    }\n\n    const key = nodeId;\n\n    if (!this.callbacks.has(key)) {\n      this.callbacks.set(key, new Set());\n    }\n\n    this.callbacks.get(key)!.add(callback);\n\n    if (this.subscribedNodes.has(nodeId) || this.subscribingNodes.has(nodeId)) {\n      return;\n    }\n\n    this.subscribingNodes.add(nodeId);\n\n    (async () => {\n      try {\n        const fabricId = await this.getFabricIdForNode(nodeId);\n\n        await this.adapter.subscribeToDevice(\n          nodeId,\n          fabricId,\n          (matterUpdate: MatterDeviceUpdate) => {\n            this.handleMatterUpdate(nodeId, matterUpdate);\n          }\n        );\n\n        this.subscribedNodes.set(nodeId, fabricId);\n      } catch (error) {\n        console.error(\n          `[MatterSubscriptionChannel] Failed to subscribe to node ${nodeId}:`,\n          error\n        );\n        this.callbacks.get(nodeId)?.delete(callback);\n        if (this.callbacks.get(nodeId)?.size === 0) {\n          this.callbacks.delete(nodeId);\n        }\n      } finally {\n        this.subscribingNodes.delete(nodeId);\n      }\n    })();\n  }\n\n  /**\n   * Unsubscribe from Matter updates for a specific node.\n   * \n   * @param nodeId - Node ID to unsubscribe from\n   */\n  async unsubscribe(nodeId?: string): Promise<void> {\n    if (!nodeId) {\n      for (const [nId, fabricId] of this.subscribedNodes.entries()) {\n        await this.adapter.unsubscribeFromDevice(nId, fabricId);\n      }\n      this.subscribedNodes.clear();\n      this.subscribingNodes.clear();\n      this.callbacks.clear();\n      return;\n    }\n\n    const fabricId = this.subscribedNodes.get(nodeId);\n    if (fabricId) {\n      await this.adapter.unsubscribeFromDevice(nodeId, fabricId);\n      this.subscribedNodes.delete(nodeId);\n    }\n\n    this.subscribingNodes.delete(nodeId);\n    this.callbacks.delete(nodeId);\n  }\n\n  /**\n   * Cleanup and dispose of Matter channel resources.\n   */\n  async dispose(): Promise<void> {\n    await this.unsubscribe();\n    await this.adapter.dispose();\n    this.isInitialized = false;\n  }\n\n  /**\n   * Get the fabric ID for a node.\n   * This extracts the fabric ID from the node's group metadata.\n   * \n   * @param nodeId - The node ID\n   * @returns Promise that resolves to the fabric ID\n   * @throws Error if fabric ID cannot be determined\n   */\n  private async getFabricIdForNode(nodeId: string): Promise<string> {\n    if (!this.fabricIdResolver) {\n      throw new Error(\n        \"Fabric ID resolver not configured. Please set the resolver using setFabricIdResolver().\"\n      );\n    }\n\n    return await this.fabricIdResolver(nodeId);\n  }\n\n  /**\n   * Handle raw Matter attribute updates, transform them to the standard\n   * {@link ESPNodeUpdateData} format, and dispatch to registered callbacks.\n   */\n  private handleMatterUpdate(\n    nodeId: string,\n    matterUpdate: MatterDeviceUpdate\n  ): void {\n    const payload = this.transformMatterToRainmaker(matterUpdate);\n\n    const update: ESPNodeUpdateData = {\n      nodeId: nodeId,\n      source: this.channelId,\n      eventType: \"rmaker.event.node_params_changed\",\n      payload: payload,\n      metadata: {\n        endpointId: matterUpdate.endpointId,\n        clusterId: matterUpdate.clusterId,\n        attributeId: matterUpdate.attributeId,\n        timestamp: matterUpdate.timestamp || Date.now(),\n        ...matterUpdate.metadata,\n      },\n    };\n\n    const nodeCallbacks = this.callbacks.get(nodeId);\n    if (nodeCallbacks) {\n      nodeCallbacks.forEach((cb) => cb(update));\n    }\n\n    const globalCallbacks = this.callbacks.get(\"*\");\n    if (globalCallbacks) {\n      globalCallbacks.forEach((cb) => cb(update));\n    }\n  }\n\n  /**\n   * Transform Matter attribute updates to Rainmaker parameter format.\n   * \n   * Mapping:\n   * - OnOff cluster (6), attr 0        -> Power (boolean)\n   * - LevelControl cluster (8), attr 0 -> Brightness (0-100 %)\n   * - ColorControl cluster (768)       -> Hue / Saturation / CCT\n   * - TemperatureMeasurement (1026)    -> Temperature (degrees C)\n   */\n  private transformMatterToRainmaker(\n    matterUpdate: MatterDeviceUpdate\n  ): Record<string, any> {\n    const { clusterId, attributeId, value } = matterUpdate;\n    const params: Record<string, any> = {};\n\n    switch (clusterId) {\n      case 6: // OnOff\n        if (attributeId === 0) {\n          params[\"Power\"] = value;\n        }\n        break;\n\n      case 8: // LevelControl\n        if (attributeId === 0) {\n          params[\"Brightness\"] = Math.round((value / 254) * 100);\n        }\n        break;\n\n      case 768: // ColorControl\n        if (attributeId === 0) {\n          params[\"Hue\"] = Math.round((value / 254) * 360);\n        } else if (attributeId === 1) {\n          params[\"Saturation\"] = Math.round((value / 254) * 100);\n        } else if (attributeId === 7) {\n          params[\"CCT\"] = value;\n        }\n        break;\n\n      case 1026: // TemperatureMeasurement\n        if (attributeId === 0) {\n          params[\"Temperature\"] = value / 100;\n        }\n        break;\n\n      default:\n        params[`cluster_${clusterId}_attr_${attributeId}`] = value;\n    }\n\n    return params;\n  }\n}\n"],"names":["MatterSubscriptionChannelIds"],"mappings":";;;;AAAA;;;;AAIG;AAuHH;;;;;;;;;;;;;;;AAeG;MACU,yBAAyB,CAAA;AAG3B,IAAA,SAAS,GAAGA,sCAA4B,CAAC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