SmartDevicesManager.on(event: "change", handler: (event: { type: string; [key: string]: any }) => void)

Requires:
@ray-js/panel-sdk≥1.16.0

Description

Subscribe to multi-device manager change events. Inside SdmProvider, multi-device Hooks are already refreshed via the change event, so manual listeners are usually unnecessary. Use only to observe device state changes outside the Provider (e.g., global logging, non-React components).

Parameters

ParameterTypeRequiredDescription
event"change"YesEvent name, fixed to change
handler(event: { type: string; [key: string]: any }) => voidYesEvent callback

Return Value

Type: any
The current Manager instance; supports chaining

Examples

Listen for different event types and inspect the returned payload

manager.on('change', event => {
  switch (event.type) {
    case 'add':
    case 'init':
      console.log(event.key, event.instance);
      break;
    case 'initProgress':
      console.log(event.progress.total, event.progress.initialized, event.progress.keys);
      break;
    case 'dpDataChange':
    case 'deviceOnlineStatusUpdate':
    case 'deviceInfoUpdated':
      console.log(event.key, event.instance, event.data);
      break;
    case 'networkStatusChange':
    case 'bluetoothAdapterStateChange':
      console.log(event.data);
      break;
    case 'initComplete':
      console.log('all initialized');
      break;
    case 'delete':
      console.log(event.key);
      break;
  }
});