74 lines
2.3 KiB
Dart
74 lines
2.3 KiB
Dart
import 'dart:async';
|
|
|
|
import 'package:friendly_map/modules/app/app.dart';
|
|
import 'package:friendly_map/modules/core/core.dart';
|
|
import 'package:friendly_map/modules/discovery/discovery.dart';
|
|
import 'package:friendly_map/modules/platform/platform.dart';
|
|
import 'package:friendly_map/modules/storage/storage.dart';
|
|
import 'package:friendly_map/modules/transport/transport.dart';
|
|
|
|
import 'fake_cipher.dart';
|
|
import 'storage_contract.dart' show FakeProbe;
|
|
|
|
/// 시험용 기기 하나: 화면 없이 앱 내부 전체를 올린다.
|
|
class AppDevice {
|
|
AppDevice._(this.app, this.phone, this.name, this.key);
|
|
|
|
final FriendlyApp app;
|
|
final String phone; // 표준 형태
|
|
final String name;
|
|
final String key;
|
|
|
|
static final List<AppDevice> _all = [];
|
|
|
|
static Future<AppDevice> create(MemoryHub hub, String rawPhone, String normalized, String name,
|
|
{bool start = true, FakeProbe? probe, FakeLan? lan, LocationProvider? location,
|
|
PhoneVerifier? verifier,
|
|
CallLogProvider? callLog,
|
|
PhoneActions? phone,
|
|
Notifier? notifier,
|
|
ContactsProvider? contacts}) async {
|
|
final key = 'KEY-$name';
|
|
final app = FriendlyApp(AppDeps(
|
|
storage: Storage.memory(),
|
|
transport: MemoryTransport(normalized, hub),
|
|
cipher: FakeCipher(key),
|
|
identity: FakeIdentity(key),
|
|
probe: probe ?? FakeProbe(10),
|
|
lan: lan == null ? null : LanDirectory(lan),
|
|
location: location,
|
|
verifier: verifier,
|
|
callLog: callLog,
|
|
phone: phone,
|
|
notifier: notifier,
|
|
contacts: contacts,
|
|
));
|
|
final d = AppDevice._(app, normalized, name, key);
|
|
await app.profile.setUp(rawPhone, name);
|
|
_all.add(d);
|
|
if (start) await app.start();
|
|
return d;
|
|
}
|
|
|
|
static Future<void> settleAll() async {
|
|
for (var round = 0; round < 3; round++) {
|
|
for (final d in _all) {
|
|
await d.app.idle();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// 시험용 같은 네트워크 발견: 테스트가 직접 상대를 흘려 넣는다.
|
|
class FakeLan implements LanDiscovery {
|
|
final StreamController<LanPeer> ctl = StreamController<LanPeer>.broadcast(sync: true);
|
|
@override
|
|
Future<void> advertise({required String phone, required int port}) async {}
|
|
@override
|
|
Stream<LanPeer> get peers => ctl.stream;
|
|
@override
|
|
Future<void> start() async {}
|
|
@override
|
|
Future<void> stop() async {}
|
|
}
|