fix(ios-audio): add voice join session coordinator
This commit is contained in:
@@ -0,0 +1,23 @@
|
|||||||
|
typedef VoiceJoinCallback = Future<void> Function({
|
||||||
|
required BigInt channelId,
|
||||||
|
required String password,
|
||||||
|
});
|
||||||
|
|
||||||
|
typedef IosVoiceSessionActivation = Future<void> Function();
|
||||||
|
typedef IosVoiceSessionDeactivation = Future<void> Function();
|
||||||
|
|
||||||
|
Future<void> joinVoiceChannelWithIosAudioSession({
|
||||||
|
required BigInt channelId,
|
||||||
|
required String password,
|
||||||
|
required VoiceJoinCallback voiceJoin,
|
||||||
|
required IosVoiceSessionActivation activateIosAudioSession,
|
||||||
|
required IosVoiceSessionDeactivation deactivateIosAudioSession,
|
||||||
|
}) async {
|
||||||
|
await activateIosAudioSession();
|
||||||
|
try {
|
||||||
|
await voiceJoin(channelId: channelId, password: password);
|
||||||
|
} catch (_) {
|
||||||
|
await deactivateIosAudioSession();
|
||||||
|
rethrow;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
|
||||||
|
import 'package:chanora_flutter/services/voice_join_ordering.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
group('joinVoiceChannelWithIosAudioSession', () {
|
||||||
|
test('activates the iOS audio session before Rust voiceJoin', () async {
|
||||||
|
final calls = <String>[];
|
||||||
|
|
||||||
|
await joinVoiceChannelWithIosAudioSession(
|
||||||
|
channelId: BigInt.from(42),
|
||||||
|
password: 'secret',
|
||||||
|
activateIosAudioSession: () async {
|
||||||
|
calls.add('activateIosAudioSession');
|
||||||
|
},
|
||||||
|
deactivateIosAudioSession: () async {
|
||||||
|
calls.add('deactivateIosAudioSession');
|
||||||
|
},
|
||||||
|
voiceJoin: ({required channelId, required password}) async {
|
||||||
|
expect(channelId, BigInt.from(42));
|
||||||
|
expect(password, 'secret');
|
||||||
|
calls.add('voiceJoin');
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(calls, ['activateIosAudioSession', 'voiceJoin']);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('deactivates the iOS audio session when Rust voiceJoin fails',
|
||||||
|
() async {
|
||||||
|
final calls = <String>[];
|
||||||
|
|
||||||
|
await expectLater(
|
||||||
|
joinVoiceChannelWithIosAudioSession(
|
||||||
|
channelId: BigInt.from(42),
|
||||||
|
password: '',
|
||||||
|
activateIosAudioSession: () async {
|
||||||
|
calls.add('activateIosAudioSession');
|
||||||
|
},
|
||||||
|
deactivateIosAudioSession: () async {
|
||||||
|
calls.add('deactivateIosAudioSession');
|
||||||
|
},
|
||||||
|
voiceJoin: ({required channelId, required password}) async {
|
||||||
|
calls.add('voiceJoin');
|
||||||
|
throw StateError('join rejected');
|
||||||
|
},
|
||||||
|
),
|
||||||
|
throwsStateError,
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(calls, [
|
||||||
|
'activateIosAudioSession',
|
||||||
|
'voiceJoin',
|
||||||
|
'deactivateIosAudioSession',
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user