@@ -345,7 +345,8 @@ void CastingServer::DeviceEventCallback(const DeviceLayer::ChipDeviceEvent * eve
345
345
if (event->Type == DeviceLayer::DeviceEventType::kBindingsChangedViaCluster )
346
346
{
347
347
ChipLogProgress (AppServer, " CastingServer::DeviceEventCallback kBindingsChangedViaCluster received" );
348
- if (CastingServer::GetInstance ()->GetActiveTargetVideoPlayer ()->IsInitialized ())
348
+ if (CastingServer::GetInstance ()->GetActiveTargetVideoPlayer ()->IsInitialized () &&
349
+ CastingServer::GetInstance ()->GetActiveTargetVideoPlayer ()->GetOperationalDeviceProxy () != nullptr )
349
350
{
350
351
ChipLogProgress (AppServer,
351
352
" CastingServer::DeviceEventCallback already connected to video player, reading server clusters" );
@@ -355,40 +356,40 @@ void CastingServer::DeviceEventCallback(const DeviceLayer::ChipDeviceEvent * eve
355
356
else if (CastingServer::GetInstance ()->mUdcInProgress )
356
357
{
357
358
ChipLogProgress (AppServer,
358
- " CastingServer::DeviceEventCallback UDC is in progress while handling kBindingsChangedViaCluster" );
359
+ " CastingServer::DeviceEventCallback UDC is in progress while handling kBindingsChangedViaCluster with "
360
+ " fabricIndex: %d" ,
361
+ event->BindingsChanged .fabricIndex );
359
362
CastingServer::GetInstance ()->mUdcInProgress = false ;
360
- if (CastingServer::GetInstance ()->mTargetVideoPlayerNumIPs > 0 )
361
- {
362
- TargetVideoPlayerInfo * connectableVideoPlayerList =
363
- CastingServer::GetInstance ()->ReadCachedTargetVideoPlayerInfos ();
364
- if (connectableVideoPlayerList == nullptr || !connectableVideoPlayerList[0 ].IsInitialized ())
365
- {
366
- ChipLogError (AppServer, " CastingServer::DeviceEventCallback No cached video players found" );
367
- CastingServer::GetInstance ()->mCommissioningCompleteCallback (CHIP_ERROR_INCORRECT_STATE);
368
- return ;
369
- }
370
363
371
- for (size_t i = 0 ; i < kMaxCachedVideoPlayers && connectableVideoPlayerList[i].IsInitialized (); i++)
364
+ // find targetPeerNodeId from binding table by matching the binding's fabricIndex with the accessing fabricIndex
365
+ // received in BindingsChanged event
366
+ for (const auto & binding : BindingTable::GetInstance ())
367
+ {
368
+ ChipLogProgress (
369
+ AppServer,
370
+ " CastingServer::DeviceEventCallback Read cached binding type=%d fabrixIndex=%d nodeId=0x" ChipLogFormatX64
371
+ " groupId=%d local endpoint=%d remote endpoint=%d cluster=" ChipLogFormatMEI,
372
+ binding.type , binding.fabricIndex , ChipLogValueX64 (binding.nodeId ), binding.groupId , binding.local ,
373
+ binding.remote , ChipLogValueMEI (binding.clusterId .ValueOr (0 )));
374
+ if (binding.type == EMBER_UNICAST_BINDING && event->BindingsChanged .fabricIndex == binding.fabricIndex )
372
375
{
373
- if (connectableVideoPlayerList[i].IsSameAs (CastingServer::GetInstance ()->mTargetVideoPlayerDeviceName ,
374
- CastingServer::GetInstance ()->mTargetVideoPlayerNumIPs ,
375
- CastingServer::GetInstance ()->mTargetVideoPlayerIpAddress ))
376
- {
377
- ChipLogProgress (AppServer,
378
- " CastingServer::DeviceEventCallback found the video player to initialize/connect to" );
379
- targetPeerNodeId = connectableVideoPlayerList[i].GetNodeId ();
380
- targetFabricIndex = connectableVideoPlayerList[i].GetFabricIndex ();
381
- runPostCommissioning = true ;
382
- }
376
+ ChipLogProgress (
377
+ NotSpecified,
378
+ " CastingServer::DeviceEventCallback Matched accessingFabricIndex with nodeId=0x" ChipLogFormatX64,
379
+ ChipLogValueX64 (binding.nodeId ));
380
+ targetPeerNodeId = binding.nodeId ;
381
+ targetFabricIndex = binding.fabricIndex ;
382
+ runPostCommissioning = true ;
383
+ break ;
383
384
}
385
+ }
384
386
385
- if (targetPeerNodeId == 0 && runPostCommissioning == false )
386
- {
387
- ChipLogError (AppServer,
388
- " CastingServer::DeviceEventCallback did NOT find the video player to initialize/connect to" );
389
- CastingServer::GetInstance ()->mCommissioningCompleteCallback (CHIP_ERROR_INCORRECT_STATE);
390
- return ;
391
- }
387
+ if (targetPeerNodeId == 0 && runPostCommissioning == false )
388
+ {
389
+ ChipLogError (AppServer, " CastingServer::DeviceEventCallback accessingFabricIndex: %d did not match bindings" ,
390
+ event->BindingsChanged .fabricIndex );
391
+ CastingServer::GetInstance ()->mCommissioningCompleteCallback (CHIP_ERROR_INCORRECT_STATE);
392
+ return ;
392
393
}
393
394
}
394
395
}
0 commit comments