|
|
@@ -1,7 +1,9 @@
|
|
|
import 'dart:async';
|
|
|
+import 'dart:convert';
|
|
|
|
|
|
import 'package:flutter/foundation.dart';
|
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
|
+import 'package:http/http.dart' as http;
|
|
|
import 'package:uuid/uuid.dart';
|
|
|
|
|
|
import 'package:asr_client/models/conversation.dart';
|
|
|
@@ -116,9 +118,10 @@ final class RecordingNotifier extends AutoDisposeAsyncNotifier<RecordingState> {
|
|
|
_messageSub?.cancel();
|
|
|
});
|
|
|
|
|
|
- final roomName = 'asr-test';
|
|
|
final identity = 'user-${_uuid.v4().substring(0, 6)}';
|
|
|
- final lkUrl = await ref.read(settingsServiceProvider).getLiveKitUrl();
|
|
|
+ final settingsService = ref.read(settingsServiceProvider);
|
|
|
+ final lkUrl = await settingsService.getLiveKitUrl();
|
|
|
+ final dispatcherUrl = await settingsService.getDispatcherUrl();
|
|
|
|
|
|
final initialState = const RecordingState(
|
|
|
projectName: 'G15 沈海高速改扩建 · K1120+300',
|
|
|
@@ -126,8 +129,32 @@ final class RecordingNotifier extends AutoDisposeAsyncNotifier<RecordingState> {
|
|
|
templateName: '模板 · 普通混凝土坍落度 GB/T 50080',
|
|
|
);
|
|
|
|
|
|
+ String roomName = 'asr-test';
|
|
|
+ String token = '';
|
|
|
+ String url = lkUrl;
|
|
|
+
|
|
|
+ // Try dispatcher for isolated room
|
|
|
+ if (dispatcherUrl.isNotEmpty) {
|
|
|
+ try {
|
|
|
+ final resp = await http.post(
|
|
|
+ Uri.parse('$dispatcherUrl/connect'),
|
|
|
+ headers: {'Content-Type': 'application/json'},
|
|
|
+ body: jsonEncode({'identity': identity}),
|
|
|
+ ).timeout(const Duration(seconds: 5));
|
|
|
+ if (resp.statusCode == 200) {
|
|
|
+ final data = jsonDecode(resp.body) as Map<String, dynamic>;
|
|
|
+ roomName = data['room'] as String;
|
|
|
+ token = data['token'] as String;
|
|
|
+ url = data['url'] as String;
|
|
|
+ debugPrint('[notifier] dispatcher: room=$roomName url=$url');
|
|
|
+ }
|
|
|
+ } catch (e) {
|
|
|
+ debugPrint('[notifier] dispatcher failed: $e, using fallback');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
try {
|
|
|
- await _liveKit.connect(url: lkUrl, room: roomName, identity: identity);
|
|
|
+ await _liveKit.connect(url: url, room: roomName, identity: identity, token: token);
|
|
|
} on Exception catch (e) {
|
|
|
return initialState.copyWith(
|
|
|
errorMessage: '无法连接 LiveKit: $e',
|