π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
mobile: consolidate cast packages
Neeraj Gupta04ab918e20c9
diff --git a/mobile/apps/photos/lib/service_locator.dart b/mobile/apps/photos/lib/service_locator.dartindex eafb4e5d3c..491c02e0fc 100644--- a/mobile/apps/photos/lib/service_locator.dart+++ b/mobile/apps/photos/lib/service_locator.dart@@ -1,6 +1,5 @@import "package:dio/dio.dart";import "package:ente_cast/ente_cast.dart";-import "package:ente_cast_normal/ente_cast_normal.dart";import "package:ente_feature_flag/ente_feature_flag.dart";import "package:package_info_plus/package_info_plus.dart";import "package:photos/app_mode.dart";@@ -82,7 +81,7 @@ FlagService get flagService {CastService? _castService;CastService get castService {- _castService ??= CastServiceImpl();+ _castService ??= CastService();return _castService!;}diff --git a/mobile/apps/photos/plugins/ente_cast/lib/src/service.dart b/mobile/apps/photos/plugins/ente_cast/lib/src/service.dartindex 2ab0961dbd..55b39daef9 100644--- a/mobile/apps/photos/plugins/ente_cast/lib/src/service.dart+++ b/mobile/apps/photos/plugins/ente_cast/lib/src/service.dart@@ -1,18 +1,112 @@+import "dart:async";+import "dart:developer" as dev;+import "dart:io";++import "package:cast/cast.dart";import "package:ente_cast/src/model.dart";-import "package:flutter/widgets.dart";+import "package:flutter/foundation.dart";+import "package:flutter/material.dart";++class CastService {+ final String _appId = "F5BCEC64";+ final String _pairRequestNamespace = "urn:x-cast:pair-request";++ bool get isSupported => !kIsWeb && (Platform.isAndroid || Platform.isIOS);++ Future<List<(String, Object)>> searchDevices() async {+ if (!isSupported) {+ return [];+ }++ final devices = await CastDiscoveryService().search(+ timeout: const Duration(seconds: 7),+ );+ return devices.map((device) => (device.name, device as Object)).toList();+ }-abstract class CastService {- bool get isSupported;- Future<List<(String, Object)>> searchDevices();Future<void> connectDevice(BuildContext context,Object device, {int? collectionID,- // callback that take a map of string, dynamicvoid Function(Map<CastMessageType, Map<String, dynamic>>)? onMessage,- });- // returns a map of sessionID to deviceNames- Map<String, String> getActiveSessions();+ }) async {+ if (!isSupported) {+ throw UnsupportedError("Cast is only supported on Android and iOS");+ }++ final castDevice = device as CastDevice;+ final session = await CastSessionManager().startSession(castDevice);++ session.messageStream.listen((message) {+ if (message["type"] == "RECEIVER_STATUS") {+ dev.log(+ "got RECEIVER_STATUS, Send request to pair",+ name: "CastService",+ );+ session.sendMessage(_pairRequestNamespace, {+ "collectionID": collectionID,+ });+ } else if (onMessage != null && message.containsKey("code")) {+ onMessage({CastMessageType.pairCode: message});+ } else if (kDebugMode) {+ print("receive message: $message");+ }+ });++ session.stateStream.listen((state) {+ if (state == CastSessionState.connected) {+ debugPrint("Send request to pair");+ session.sendMessage(_pairRequestNamespace, {});+ } else if (state == CastSessionState.closed) {+ dev.log("Session closed", name: "CastService");+ }+ });++ debugPrint("Send request to launch");+ session.sendMessage(CastSession.kNamespaceReceiver, {+ "type": "LAUNCH",+ "appId": _appId,+ });+ }++ Future<void> closeActiveCasts() async {+ if (!isSupported) {+ return;+ }++ final sessions = CastSessionManager().sessions;+ for (final session in sessions) {+ debugPrint("send close message for ${session.sessionId}");+ unawaited(+ Future(() {+ session.sendMessage(CastSession.kNamespaceConnection, {+ "type": "CLOSE",+ });+ }).timeout(+ const Duration(seconds: 5),+ onTimeout: () {+ debugPrint("sendMessage timed out after 5 seconds");+ },+ ),+ );+ debugPrint("close session ${session.sessionId}");+ unawaited(session.close());+ }+ CastSessionManager().sessions.clear();+ }++ Map<String, String> getActiveSessions() {+ if (!isSupported) {+ return {};+ }- Future<void> closeActiveCasts();+ final sessions = CastSessionManager().sessions;+ final result = <String, String>{};+ for (final session in sessions) {+ if (session.state == CastSessionState.connected) {+ result[session.sessionId] = session.state.toString();+ }+ }+ return result;+ }}diff --git a/mobile/apps/photos/plugins/ente_cast/pubspec.yaml b/mobile/apps/photos/plugins/ente_cast/pubspec.yamlindex 6cc08a0849..9dd7fc8d5b 100644--- a/mobile/apps/photos/plugins/ente_cast/pubspec.yaml+++ b/mobile/apps/photos/plugins/ente_cast/pubspec.yaml@@ -6,6 +6,11 @@ environment:sdk: '>=3.3.0 <4.0.0'dependencies:+ cast:+ git:+ url: https://github.com/guyluz11/flutter_cast.git+ ref: multicast_version+ commit: 1f39cd4collection:dio: ^5.8.0+1flutter:diff --git a/mobile/apps/photos/pubspec.lock b/mobile/apps/photos/pubspec.lockindex 322d3d7658..74ff418492 100644--- a/mobile/apps/photos/pubspec.lock+++ b/mobile/apps/photos/pubspec.lock@@ -594,13 +594,6 @@ packages:relative: truesource: pathversion: "0.0.1"- ente_cast_normal:- dependency: "direct main"- description:- path: "plugins/ente_cast_normal"- relative: true- source: path- version: "0.0.1"ente_crypto:dependency: "direct main"description:diff --git a/mobile/apps/photos/pubspec.yaml b/mobile/apps/photos/pubspec.yamlindex d1ae57cb9c..bef51a4753 100644--- a/mobile/apps/photos/pubspec.yaml+++ b/mobile/apps/photos/pubspec.yaml@@ -54,8 +54,6 @@ dependencies:encrypt: ^5.0.3ente_cast:path: plugins/ente_cast- ente_cast_normal:- path: plugins/ente_cast_normalente_crypto:path: plugins/ente_cryptoente_feature_flag:diff --git a/mobile/apps/photos/pubspec_overrides.yaml b/mobile/apps/photos/pubspec_overrides.yamlindex c7aff3dcd1..86276e3d28 100644--- a/mobile/apps/photos/pubspec_overrides.yaml+++ b/mobile/apps/photos/pubspec_overrides.yaml@@ -1,9 +1,7 @@-# melos_managed_dependency_overrides: ente_cast,ente_cast_normal,ente_crypto,ente_feature_flag,onnx_dart,ffi,flutter_sodium,intl,js,media_kit,media_kit_libs_ios_video,media_kit_libs_video,media_kit_video,protobuf,watcher,win32,log_viewer,native_video_editor,ente_qr_ui,ente_icons,ente_rust,ente_pure_utils+# melos_managed_dependency_overrides: ente_cast,ente_crypto,ente_feature_flag,onnx_dart,ffi,flutter_sodium,intl,js,media_kit,media_kit_libs_ios_video,media_kit_libs_video,media_kit_video,protobuf,watcher,win32,log_viewer,native_video_editor,ente_qr_ui,ente_icons,ente_rust,ente_pure_utilsdependency_overrides:ente_cast:path: plugins/ente_cast- ente_cast_normal:- path: plugins/ente_cast_normalente_crypto:path: plugins/ente_cryptoente_feature_flag: