47 lines
1.3 KiB
Dart
47 lines
1.3 KiB
Dart
import 'dart:io';
|
|
|
|
import 'package:device_info_plus/device_info_plus.dart';
|
|
import 'package:flutter_sdk/starcloud_flutter_sdk.dart';
|
|
|
|
import '../global.dart';
|
|
|
|
const _talkServerUrl = 'http://scd.skychip.top:8710';
|
|
Future<void>? _initialization;
|
|
|
|
/// 初始化后生成的 App PeerID 会同时供 WiFi 配网及监控使用。
|
|
Future<void> initializeVideoTalk() {
|
|
if (videoTalkReady.value) return Future<void>.value();
|
|
final pending = _initialization;
|
|
if (pending != null) return pending;
|
|
|
|
final future = _initialize();
|
|
_initialization = future;
|
|
future.whenComplete(() {
|
|
if (identical(_initialization, future)) _initialization = null;
|
|
});
|
|
return future;
|
|
}
|
|
|
|
Future<void> _initialize() async {
|
|
videoTalkInitializing.value = true;
|
|
try {
|
|
var deviceId = 'dev_user_123';
|
|
final deviceInfo = DeviceInfoPlugin();
|
|
if (Platform.isAndroid) {
|
|
deviceId = (await deviceInfo.androidInfo).id;
|
|
} else if (Platform.isIOS) {
|
|
deviceId = (await deviceInfo.iosInfo).identifierForVendor ?? deviceId;
|
|
}
|
|
|
|
await StarCloudClient.instance.talk.init(
|
|
productName: 'Demo',
|
|
unique: deviceId,
|
|
baseUrl: _talkServerUrl,
|
|
);
|
|
appPeerId.value = StarCloudClient.instance.talk.myPeerId;
|
|
videoTalkReady.value = true;
|
|
} finally {
|
|
videoTalkInitializing.value = false;
|
|
}
|
|
}
|