feat(mobile-next): 迁移 Android 一对一语音通话薄适配与入口
复用官方 OpenIMLive 信令与房间,换票改走账号服务 /api/rtc_token;入口仅音频,占线/超时/重复回调与销毁释放由公司层防护。 Co-authored-by: Cursor <cursoragent@cursor.com> Co-authored-by: multica-agent <github@multica.ai>
This commit is contained in:
co-authored by
Cursor
multica-agent
parent
2a817e77d8
commit
3832e080c4
@@ -0,0 +1,65 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:openim/company/rtc/call_session_guard.dart';
|
||||
import 'package:openim/company/rtc/livekit_call_config.dart';
|
||||
|
||||
void main() {
|
||||
test('配置门:内网地址与换票路径齐全时才打开入口', () {
|
||||
expect(LiveKitCallConfig.rtcTokenPath, '/api/rtc_token');
|
||||
expect(LiveKitCallConfig.endpointsReady, isTrue);
|
||||
expect(LiveKitCallConfig.enabled, LiveKitCallConfig.shipped);
|
||||
});
|
||||
|
||||
test('占线时拒绝第二路呼出/呼入', () {
|
||||
final guard = CallSessionGuard();
|
||||
expect(guard.startOutgoing('room-a'), isNull);
|
||||
expect(guard.startOutgoing('room-b'), 'busy');
|
||||
expect(guard.startIncoming('room-c'), 'busy');
|
||||
guard.dispose();
|
||||
expect(guard.isBusy, isFalse);
|
||||
expect(guard.startIncoming('room-d'), isNull);
|
||||
guard.dispose();
|
||||
});
|
||||
|
||||
test('同一房间同一信令只处理一次', () {
|
||||
final guard = CallSessionGuard();
|
||||
expect(guard.acceptSignaling(customType: 200, roomID: 'r1'), isTrue);
|
||||
expect(guard.acceptSignaling(customType: 200, roomID: 'r1'), isFalse);
|
||||
expect(guard.acceptSignaling(customType: 201, roomID: 'r1'), isTrue);
|
||||
expect(guard.acceptSignaling(customType: 200, roomID: ''), isFalse);
|
||||
guard.dispose();
|
||||
});
|
||||
|
||||
test('接听后取消超时,销毁后释放计时器', () async {
|
||||
var timedOut = false;
|
||||
final guard = CallSessionGuard(inviteTimeout: const Duration(milliseconds: 40));
|
||||
guard.onTimeout = () => timedOut = true;
|
||||
guard.startOutgoing('room-t');
|
||||
guard.markConnected();
|
||||
await Future<void>.delayed(const Duration(milliseconds: 80));
|
||||
expect(timedOut, isFalse);
|
||||
expect(guard.phase, VoiceCallPhase.inCall);
|
||||
|
||||
guard.dispose();
|
||||
expect(guard.phase, VoiceCallPhase.idle);
|
||||
expect(guard.roomID, isNull);
|
||||
});
|
||||
|
||||
test('呼出超时回调', () async {
|
||||
var timedOut = false;
|
||||
final guard = CallSessionGuard(inviteTimeout: const Duration(milliseconds: 30));
|
||||
guard.onTimeout = () => timedOut = true;
|
||||
guard.startOutgoing('room-t');
|
||||
await Future<void>.delayed(const Duration(milliseconds: 80));
|
||||
expect(timedOut, isTrue);
|
||||
guard.dispose();
|
||||
});
|
||||
|
||||
test('sameRoom 只认当前房间', () {
|
||||
final guard = CallSessionGuard();
|
||||
guard.startIncoming('room-1');
|
||||
expect(guard.sameRoom('room-1'), isTrue);
|
||||
expect(guard.sameRoom('room-2'), isFalse);
|
||||
expect(guard.sameRoom(null), isFalse);
|
||||
guard.dispose();
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:openim/company/rtc/rtc_token_mapper.dart';
|
||||
|
||||
void main() {
|
||||
const fallback = 'ws://192.168.200.11:17880';
|
||||
|
||||
test('解析账号服务 token,缺 liveURL 时回落到配置地址', () {
|
||||
final cred = RtcTokenMapper.parse(
|
||||
{
|
||||
'code': 0,
|
||||
'msg': '',
|
||||
'data': {'token': 'lk-token'},
|
||||
},
|
||||
fallbackLiveUrl: fallback,
|
||||
);
|
||||
expect(cred.token, 'lk-token');
|
||||
expect(cred.liveURL, fallback);
|
||||
});
|
||||
|
||||
test('兼容官方 serverUrl 字段', () {
|
||||
final cred = RtcTokenMapper.parse(
|
||||
{
|
||||
'code': 0,
|
||||
'data': {'token': 't', 'serverUrl': 'ws://live.example:7880'},
|
||||
},
|
||||
fallbackLiveUrl: fallback,
|
||||
);
|
||||
expect(cred.liveURL, 'ws://live.example:7880');
|
||||
});
|
||||
|
||||
test('优先使用 liveURL', () {
|
||||
final cred = RtcTokenMapper.parse(
|
||||
{
|
||||
'data': {
|
||||
'token': 't',
|
||||
'liveURL': 'ws://a:1',
|
||||
'serverUrl': 'ws://b:2',
|
||||
},
|
||||
},
|
||||
fallbackLiveUrl: fallback,
|
||||
);
|
||||
expect(cred.liveURL, 'ws://a:1');
|
||||
});
|
||||
|
||||
test('业务失败码抛出服务端文案', () {
|
||||
expect(
|
||||
() => RtcTokenMapper.parse(
|
||||
{'code': 1, 'msg': '语音通话服务未配置,请联系管理员'},
|
||||
fallbackLiveUrl: fallback,
|
||||
),
|
||||
throwsA(isA<FormatException>().having(
|
||||
(e) => e.message,
|
||||
'message',
|
||||
'语音通话服务未配置,请联系管理员',
|
||||
)),
|
||||
);
|
||||
});
|
||||
|
||||
test('缺 token 失败', () {
|
||||
expect(
|
||||
() => RtcTokenMapper.parse(
|
||||
{
|
||||
'code': 0,
|
||||
'data': {'token': ''},
|
||||
},
|
||||
fallbackLiveUrl: fallback,
|
||||
),
|
||||
throwsA(isA<FormatException>()),
|
||||
);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user