-
Notifications
You must be signed in to change notification settings - Fork 390
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Fix MediaRecorder.startRecording return -4 after the previous de…
…stroy
- Loading branch information
1 parent
50199cb
commit 76d4dc4
Showing
5 changed files
with
188 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
test_shard/integration_test_app/integration_test/fake_apis_call_integration_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import 'package:integration_test/integration_test.dart'; | ||
|
||
import 'testcases/mediarecorder_fake_test_testcases.dart' as fake_mediarecorder; | ||
|
||
void main() { | ||
IntegrationTestWidgetsFlutterBinding.ensureInitialized(); | ||
|
||
fake_mediarecorder.testCases(); | ||
} |
132 changes: 132 additions & 0 deletions
132
...rd/integration_test_app/integration_test/testcases/mediarecorder_fake_test_testcases.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
import 'package:agora_rtc_engine/agora_rtc_engine.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
|
||
import 'package:agora_rtc_engine/src/impl/native_iris_api_engine_binding_delegate.dart'; | ||
import '../fake/fake_iris_method_channel.dart'; | ||
import 'package:agora_rtc_engine/src/impl/agora_rtc_engine_impl.dart'; | ||
import 'package:iris_method_channel/iris_method_channel.dart'; | ||
|
||
class MediaRecorderFakeIrisMethodChannel extends FakeIrisMethodChannel { | ||
MediaRecorderFakeIrisMethodChannel(NativeBindingsProvider provider) | ||
: super(provider); | ||
|
||
@override | ||
Future<CallApiResult> invokeMethod(IrisMethodCall methodCall) async { | ||
final result = super.invokeMethod(methodCall); | ||
if (methodCall.funcName == 'RtcEngine_createMediaRecorder') { | ||
return CallApiResult(data: {'result': '1000'}, irisReturnCode: 0); | ||
} | ||
|
||
return result; | ||
} | ||
|
||
Future<CallApiResult> registerEventHandler( | ||
ScopedEvent scopedEvent, String params) async { | ||
IrisMethodCall methodCall = | ||
IrisMethodCall(scopedEvent.registerName, params); | ||
|
||
return invokeMethod(methodCall); | ||
} | ||
|
||
Future<CallApiResult> unregisterEventHandler( | ||
ScopedEvent scopedEvent, String params) async { | ||
IrisMethodCall methodCall = | ||
IrisMethodCall(scopedEvent.unregisterName, params); | ||
|
||
return invokeMethod(methodCall); | ||
} | ||
} | ||
|
||
void testCases() { | ||
bool _isCallOnce( | ||
MediaRecorderFakeIrisMethodChannel irisMethodChannel, String apiName) { | ||
final calls = irisMethodChannel.methodCallQueue | ||
.where((e) => e.funcName == apiName) | ||
.toList(); | ||
|
||
return calls.length == 1; | ||
} | ||
|
||
group('FakeIrisMethodChannel integration test', () { | ||
final MediaRecorderFakeIrisMethodChannel irisMethodChannel = | ||
MediaRecorderFakeIrisMethodChannel( | ||
IrisApiEngineNativeBindingDelegateProvider()); | ||
final RtcEngine rtcEngine = | ||
RtcEngineImpl.create(irisMethodChannel: irisMethodChannel); | ||
|
||
setUp(() { | ||
irisMethodChannel.reset(); | ||
}); | ||
|
||
testWidgets( | ||
'can call startRecording after previous MediaRecorder destroy', | ||
(WidgetTester tester) async { | ||
String engineAppId = const String.fromEnvironment('TEST_APP_ID', | ||
defaultValue: '<YOUR_APP_ID>'); | ||
|
||
await rtcEngine.initialize(RtcEngineContext( | ||
appId: engineAppId, | ||
areaCode: AreaCode.areaCodeGlob.value(), | ||
)); | ||
|
||
MediaRecorder? recorder = await rtcEngine.createMediaRecorder( | ||
const RecorderStreamInfo(channelId: 'test', uid: 0)); | ||
recorder?.setMediaRecorderObserver(MediaRecorderObserver( | ||
onRecorderStateChanged: (channelId, uid, state, error) {}, | ||
)); | ||
await recorder?.startRecording( | ||
const MediaRecorderConfiguration(storagePath: 'path')); | ||
await recorder?.stopRecording(); | ||
await rtcEngine.destroyMediaRecorder(recorder!); | ||
|
||
expect(_isCallOnce(irisMethodChannel, 'RtcEngine_createMediaRecorder'), | ||
isTrue); | ||
expect( | ||
_isCallOnce( | ||
irisMethodChannel, 'MediaRecorder_setMediaRecorderObserver'), | ||
isTrue); | ||
expect(_isCallOnce(irisMethodChannel, 'MediaRecorder_startRecording'), | ||
isTrue); | ||
expect(_isCallOnce(irisMethodChannel, 'MediaRecorder_stopRecording'), | ||
isTrue); | ||
// When `RtcEngine.destroyMediaRecorder` is called, will call `MediaRecorderImpl.dispose` | ||
expect( | ||
_isCallOnce( | ||
irisMethodChannel, 'MediaRecorder_unsetMediaRecorderObserver'), | ||
isTrue); | ||
expect(_isCallOnce(irisMethodChannel, 'RtcEngine_destroyMediaRecorder'), | ||
isTrue); | ||
|
||
irisMethodChannel.reset(); | ||
|
||
recorder = await rtcEngine.createMediaRecorder( | ||
const RecorderStreamInfo(channelId: 'test', uid: 0)); | ||
recorder?.setMediaRecorderObserver(MediaRecorderObserver( | ||
onRecorderStateChanged: (channelId, uid, state, error) {}, | ||
)); | ||
await recorder?.startRecording( | ||
const MediaRecorderConfiguration(storagePath: 'path')); | ||
await recorder?.stopRecording(); | ||
await rtcEngine.destroyMediaRecorder(recorder!); | ||
|
||
expect(_isCallOnce(irisMethodChannel, 'RtcEngine_createMediaRecorder'), | ||
isTrue); | ||
expect( | ||
_isCallOnce( | ||
irisMethodChannel, 'MediaRecorder_setMediaRecorderObserver'), | ||
isTrue); | ||
expect(_isCallOnce(irisMethodChannel, 'MediaRecorder_startRecording'), | ||
isTrue); | ||
expect(_isCallOnce(irisMethodChannel, 'MediaRecorder_stopRecording'), | ||
isTrue); | ||
// When `RtcEngine.destroyMediaRecorder` is called, will call `MediaRecorderImpl.dispose` | ||
expect( | ||
_isCallOnce( | ||
irisMethodChannel, 'MediaRecorder_unsetMediaRecorderObserver'), | ||
isTrue); | ||
expect(_isCallOnce(irisMethodChannel, 'RtcEngine_destroyMediaRecorder'), | ||
isTrue); | ||
}, | ||
); | ||
}); | ||
} |