Skip to content

Commit

Permalink
fix: no-op if call RtcEngine.release without calling RtcEngine.initia…
Browse files Browse the repository at this point in the history
…lize directly
  • Loading branch information
littleGnAl committed Jun 12, 2023
1 parent 6db3838 commit 95d29ae
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/src/impl/agora_rtc_engine_impl.dart
Expand Up @@ -312,24 +312,26 @@ class RtcEngineImpl extends rtc_engine_ex_binding.RtcEngineExImpl

@override
Future<void> release({bool sync = false}) async {
if (_isReleased) return;

// Same as explanation inside `initialize`. We should wait for
// the `initialize` function is completed here.
if (_initializingCompleter != null &&
!_initializingCompleter!.isCompleted) {
await _initializingCompleter?.future;
}

if (!_rtcEngineState.isInitialzed || _isReleased) {
return;
}

_releasingCompleter = Completer<void>();

_rtcEngineStateInternal?.dispose();
_rtcEngineStateInternal = null;

await _objectPool.clear();

await _globalVideoViewController!
.detachVideoFrameBufferManager(irisMethodChannel.getNativeHandle());
await _globalVideoViewController
?.detachVideoFrameBufferManager(irisMethodChannel.getNativeHandle());
_globalVideoViewController = null;

await irisMethodChannel.unregisterEventHandlers(_rtcEngineImplScopedKey);
Expand Down
Expand Up @@ -371,5 +371,24 @@ void testCases() {
await rtcEngine.setupLocalVideo(const VideoCanvas());
},
);

testWidgets(
'call release without calling initialize directly, do not thorw error',
(WidgetTester tester) async {
app.main();
await tester.pumpAndSettle();

String engineAppId = const String.fromEnvironment('TEST_APP_ID',
defaultValue: '<YOUR_APP_ID>');

RtcEngineEx rtcEngine = createAgoraRtcEngineEx();
await rtcEngine.release();

await rtcEngine.initialize(RtcEngineContext(
appId: engineAppId,
areaCode: AreaCode.areaCodeGlob.value(),
));
},
);
});
}

0 comments on commit 95d29ae

Please sign in to comment.