Skip to content

Commit

Permalink
fix: Fix missing OnEvent callbacks with IrisMethodChannel used by…
Browse files Browse the repository at this point in the history
… multiple packages (#108)

Resolved an issue where `OnEvent` callbacks were not received when
`IrisMethodChannel` was used by multiple packages (e.g.,
`agora_rtc_engine` and `agora_rtm`) simultaneously. This fix ensures
that events are properly handled even after disposal, maintaining
consistent behavior across packages.
  • Loading branch information
littleGnAl authored Oct 10, 2024
1 parent 56c024e commit fe29371
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/iris_event.cc
Original file line number Diff line number Diff line change
Expand Up @@ -199,23 +199,32 @@ class DartMessageHandlerManager : public DartMessageHandlerBase

std::mutex message_handler_mutex_;
std::unique_ptr<DartMessageHandlerManager> dartMessageHandlerManager_ = nullptr;
int init_dart_api_times_ = 0;

// Initialize `dart_api_dl.h`
EXPORT intptr_t InitDartApiDL(void *data)
{
std::lock_guard<std::mutex> lock(message_handler_mutex_);
if (!dartMessageHandlerManager_)
int ret = 0;
if (init_dart_api_times_ == 0 && !dartMessageHandlerManager_)
{
dartMessageHandlerManager_ = std::make_unique<DartMessageHandlerManager>();
ret = dartMessageHandlerManager_->InitDartApiDL(data);
}

return dartMessageHandlerManager_->InitDartApiDL(data);
++init_dart_api_times_;

return ret;
}

EXPORT void Dispose()
{
std::lock_guard<std::mutex> lock(message_handler_mutex_);
dartMessageHandlerManager_.reset();
--init_dart_api_times_;
if (init_dart_api_times_ == 0)
{
dartMessageHandlerManager_.reset();
}
}

EXPORT void OnEvent(EventParam *param)
Expand Down

0 comments on commit fe29371

Please sign in to comment.