diff --git a/Cargo.lock b/Cargo.lock index 777eec920..225d6fae1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -539,7 +539,6 @@ dependencies = [ "instant", "pin-project-lite", "rand", - "tokio", ] [[package]] @@ -795,9 +794,9 @@ dependencies = [ [[package]] name = "core-foundation" -version = "0.9.3" +version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "194a7a9e6de53fa55116934067c844d9d749312f75c6f6d0980e8c252f8c2146" +checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" dependencies = [ "core-foundation-sys", "libc", @@ -805,9 +804,9 @@ dependencies = [ [[package]] name = "core-foundation-sys" -version = "0.8.4" +version = "0.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa" +checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f" [[package]] name = "cpufeatures" @@ -1810,9 +1809,9 @@ checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f" [[package]] name = "linux-raw-sys" -version = "0.4.11" +version = "0.4.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "969488b55f8ac402214f3f5fd243ebb7206cf82de60d3172994707a4bcc2b829" +checksum = "c4cd1a83af159aa67994778be9070f0ae1bd732942279cabb14f86f986a21456" [[package]] name = "local-channel" @@ -1872,7 +1871,6 @@ dependencies = [ "actix-cors", "actix-web", "actix-web-actors", - "backoff", "clap", "derive_more", "dotenv", @@ -1933,7 +1931,6 @@ name = "medea-jason" version = "0.4.0" dependencies = [ "android_logger", - "anyhow", "async-recursion", "async-trait", "backoff", @@ -2630,15 +2627,15 @@ dependencies = [ [[package]] name = "rustix" -version = "0.38.25" +version = "0.38.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc99bc2d4f1fed22595588a013687477aedf3cdcfb26558c559edb67b4d9b22e" +checksum = "9470c4bf8246c8daf25f9598dca807fb6510347b1e1cfa55749113850c79d88a" dependencies = [ "bitflags 2.4.1", "errno", "libc", "linux-raw-sys", - "windows-sys 0.48.0", + "windows-sys 0.52.0", ] [[package]] @@ -4044,18 +4041,18 @@ dependencies = [ [[package]] name = "zerocopy" -version = "0.7.26" +version = "0.7.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e97e415490559a91254a2979b4829267a57d2fcd741a98eee8b722fb57289aa0" +checksum = "7d6f15f7ade05d2a4935e34a457b936c23dc70a05cc1d97133dc99e7a3fe0f0e" dependencies = [ "zerocopy-derive", ] [[package]] name = "zerocopy-derive" -version = "0.7.26" +version = "0.7.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd7e48ccf166952882ca8bd778a43502c64f33bf94c12ebe2a7f08e5a0f6689f" +checksum = "dbbad221e3f78500350ecbd7dfa4e63ef945c05f4c61cb7f4d3f84cd0bba649b" dependencies = [ "proc-macro2", "quote", diff --git a/Cargo.toml b/Cargo.toml index 281205c94..454f283ff 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -61,7 +61,6 @@ android_logger = "0.13" simple_logger = "4.0" [target.'cfg(not(target_family = "wasm"))'.dependencies] -anyhow = "1.0" dart-sys = "4.0" flutter_rust_bridge = { version = "=1.82.4", default-features = false } libc = "0.2" diff --git a/e2e/src/browser/mock/websocket.rs b/e2e/src/browser/mock/websocket.rs index 76d81c210..b3145f133 100644 --- a/e2e/src/browser/mock/websocket.rs +++ b/e2e/src/browser/mock/websocket.rs @@ -54,18 +54,14 @@ impl<'a> WebSocket<'a> { self.0 .execute(Statement::new( // language=JavaScript - r#" + " async () => { const [code] = args; for (socket of window.wsMock.allSockets) { - window.wsMock.isClosed = true; - window.wsMock.closeCode = code; - socket.dispatchEvent( - new CloseEvent("close", { code: code }) - ); + socket.close(code); } } - "#, + ", [code.into()], )) .await diff --git a/e2e/tests/features/state_synchronization.feature b/e2e/tests/features/state_synchronization.feature index 51ece66f1..e33fbc191 100644 --- a/e2e/tests/features/state_synchronization.feature +++ b/e2e/tests/features/state_synchronization.feature @@ -27,7 +27,6 @@ Feature: State synchronization And Alice restores WS connection Then Bob's audio remote track from Alice is enabled - @mesh Scenario: Audio endpoint added while disconnected Given room with joined member Alice and Bob with no WebRTC endpoints When Alice loses WS connection @@ -36,7 +35,6 @@ Feature: State synchronization Then Alice has audio remote tracks from Bob And Bob has audio remote tracks from Alice - @mesh Scenario: Video endpoint added while disconnected Given room with joined member Alice and Bob with no WebRTC endpoints When Alice loses WS connection @@ -45,7 +43,6 @@ Feature: State synchronization Then Alice has video remote tracks from Bob And Bob has video remote tracks from Alice - @mesh Scenario: New endpoint creates new tracks Given room with joined member Alice and Bob with no WebRTC endpoints When Alice loses WS connection diff --git a/e2e/tests/steps/websocket.rs b/e2e/tests/steps/websocket.rs index 71ef10881..36fa46422 100644 --- a/e2e/tests/steps/websocket.rs +++ b/e2e/tests/steps/websocket.rs @@ -1,11 +1,15 @@ +use std::time::Duration; + use cucumber::{then, when}; +use tokio::time::sleep; use crate::World; #[when(regex = r"^(\S+) loses WS connection$")] async fn ws_connection_loss(world: &mut World, id: String) { let member = world.get_member(&id).unwrap(); - member.ws_mock().enable_connection_loss(9999).await; + member.ws_mock().enable_connection_loss(3999).await; + sleep(Duration::from_millis(500)).await; } #[when(regex = r"^(\S+) restores WS connection$")] diff --git a/flutter/example/pubspec.lock b/flutter/example/pubspec.lock index 5e51ea64e..3beed586c 100644 --- a/flutter/example/pubspec.lock +++ b/flutter/example/pubspec.lock @@ -318,10 +318,10 @@ packages: dependency: "direct main" description: name: medea_flutter_webrtc - sha256: f4d5aa921795d8509dbeeafe83b38e7e7441e2a7d0542a7f4e5c5b723616501e + sha256: "5b308b88d7eba6279971c218cfddb374e2f60977811cc9b5cf30f26379a66a97" url: "https://pub.dev" source: hosted - version: "0.8.3-dev+rev.d5a07ce262833b307e4b0e5d39badd55eadf812a" + version: "0.8.3-dev+rev.0fe64b4610154ddb7e8774a952b6ecf6369b7633" medea_jason: dependency: "direct main" description: @@ -365,10 +365,10 @@ packages: dependency: transitive description: name: petitparser - sha256: eeb2d1428ee7f4170e2bd498827296a18d4e7fc462b71727d111c0ac7707cfa6 + sha256: c15605cd28af66339f8eb6fbe0e541bfe2d1b72d5825efc6598f3e0a31b9ad27 url: "https://pub.dev" source: hosted - version: "6.0.1" + version: "6.0.2" platform: dependency: transitive description: @@ -615,5 +615,5 @@ packages: source: hosted version: "3.1.2" sdks: - dart: ">=3.2.0-194.0.dev <4.0.0" + dart: ">=3.2.0 <4.0.0" flutter: ">=3.10.0" diff --git a/flutter/example/pubspec.yaml b/flutter/example/pubspec.yaml index 4fc14f222..8d9c950e4 100644 --- a/flutter/example/pubspec.yaml +++ b/flutter/example/pubspec.yaml @@ -23,7 +23,7 @@ dependencies: faker_dart: ^0.1.11 freezed_annotation: ^2.2.0 http: ^0.13.6 - medea_flutter_webrtc: 0.8.3-dev+rev.d5a07ce262833b307e4b0e5d39badd55eadf812a + medea_flutter_webrtc: 0.8.3-dev+rev.0fe64b4610154ddb7e8774a952b6ecf6369b7633 retry: ^3.1.2 dev_dependencies: diff --git a/flutter/lib/src/native/connection_handle.dart b/flutter/lib/src/native/connection_handle.dart index c238308aa..8b300da4a 100644 --- a/flutter/lib/src/native/connection_handle.dart +++ b/flutter/lib/src/native/connection_handle.dart @@ -1,5 +1,3 @@ -import 'package:flutter_rust_bridge/flutter_rust_bridge.dart'; - import 'package:medea_jason/src/native/remote_media_track.dart'; import '../interface/connection_handle.dart'; import '../interface/media_track.dart'; @@ -22,45 +20,29 @@ class NativeConnectionHandle implements ConnectionHandle { @override String getRemoteMemberId() { - try { - return api.connectionHandleGetRemoteMemberId( - connection: opaque.innerOpaque); - } on FfiException catch (anyhow) { - throw anyhow.parse(); - } + return api.connectionHandleGetRemoteMemberId( + connection: opaque.innerOpaque); } @override void onClose(void Function() f) { - try { - api.connectionHandleOnClose(connection: opaque.innerOpaque, f: f); - } on FfiException catch (anyhow) { - throw anyhow.parse(); - } + api.connectionHandleOnClose(connection: opaque.innerOpaque, f: f); } @override void onRemoteTrackAdded(void Function(RemoteMediaTrack) f) { - try { - api.connectionHandleOnRemoteTrackAdded( - connection: opaque.innerOpaque, - f: (t) { - f(NativeRemoteMediaTrack( - api.remoteMediaTrackFromPtr(ptr: t.address))); - }); - } on FfiException catch (anyhow) { - throw anyhow.parse(); - } + api.connectionHandleOnRemoteTrackAdded( + connection: opaque.innerOpaque, + f: (t) { + f(NativeRemoteMediaTrack( + api.remoteMediaTrackFromPtr(ptr: t.address))); + }); } @override void onQualityScoreUpdate(void Function(int) f) { - try { - api.connectionHandleOnQualityScoreUpdate( - connection: opaque.innerOpaque, f: f); - } on FfiException catch (anyhow) { - throw anyhow.parse(); - } + api.connectionHandleOnQualityScoreUpdate( + connection: opaque.innerOpaque, f: f); } @moveSemantics @@ -75,41 +57,25 @@ class NativeConnectionHandle implements ConnectionHandle { @override Future enableRemoteAudio() async { - try { - await (api.connectionHandleEnableRemoteAudio( - connection: opaque.innerOpaque) as Future); - } on FfiException catch (anyhow) { - throw anyhow.parse(); - } + await (api.connectionHandleEnableRemoteAudio(connection: opaque.innerOpaque) + as Future); } @override Future disableRemoteAudio() async { - try { - await (api.connectionHandleDisableRemoteAudio( - connection: opaque.innerOpaque) as Future); - } on FfiException catch (anyhow) { - throw anyhow.parse(); - } + await (api.connectionHandleDisableRemoteAudio( + connection: opaque.innerOpaque) as Future); } @override Future enableRemoteVideo([MediaSourceKind? kind]) async { - try { - await (api.connectionHandleEnableRemoteVideo( - connection: opaque.innerOpaque, sourceKind: kind) as Future); - } on FfiException catch (anyhow) { - throw anyhow.parse(); - } + await (api.connectionHandleEnableRemoteVideo( + connection: opaque.innerOpaque, sourceKind: kind) as Future); } @override Future disableRemoteVideo([MediaSourceKind? kind]) async { - try { - await (api.connectionHandleDisableRemoteVideo( - connection: opaque.innerOpaque, sourceKind: kind) as Future); - } on FfiException catch (anyhow) { - throw anyhow.parse(); - } + await (api.connectionHandleDisableRemoteVideo( + connection: opaque.innerOpaque, sourceKind: kind) as Future); } } diff --git a/flutter/lib/src/native/ffi/jason_api.g.dart b/flutter/lib/src/native/ffi/jason_api.g.dart index 1f54b8adc..362d96d00 100644 --- a/flutter/lib/src/native/ffi/jason_api.g.dart +++ b/flutter/lib/src/native/ffi/jason_api.g.dart @@ -1083,7 +1083,7 @@ class MedeaJasonImpl implements MedeaJason { callFfi: () => _platform.inner.wire_connection_handle_on_close(arg0, arg1), parseSuccessData: _wire2api_unit, - parseErrorData: _wire2api_FrbAnyhowException, + parseErrorData: _wire2api_DartOpaque, constMeta: kConnectionHandleOnCloseConstMeta, argValues: [connection, f], hint: hint, @@ -1104,7 +1104,7 @@ class MedeaJasonImpl implements MedeaJason { callFfi: () => _platform.inner .wire_connection_handle_on_remote_track_added(arg0, arg1), parseSuccessData: _wire2api_unit, - parseErrorData: _wire2api_FrbAnyhowException, + parseErrorData: _wire2api_DartOpaque, constMeta: kConnectionHandleOnRemoteTrackAddedConstMeta, argValues: [connection, f], hint: hint, @@ -1126,7 +1126,7 @@ class MedeaJasonImpl implements MedeaJason { callFfi: () => _platform.inner .wire_connection_handle_on_quality_score_update(arg0, arg1), parseSuccessData: _wire2api_unit, - parseErrorData: _wire2api_FrbAnyhowException, + parseErrorData: _wire2api_DartOpaque, constMeta: kConnectionHandleOnQualityScoreUpdateConstMeta, argValues: [connection, f], hint: hint, @@ -1147,7 +1147,7 @@ class MedeaJasonImpl implements MedeaJason { callFfi: () => _platform.inner.wire_connection_handle_get_remote_member_id(arg0), parseSuccessData: _wire2api_String, - parseErrorData: _wire2api_FrbAnyhowException, + parseErrorData: _wire2api_DartOpaque, constMeta: kConnectionHandleGetRemoteMemberIdConstMeta, argValues: [connection], hint: hint, @@ -1714,7 +1714,7 @@ class MedeaJasonImpl implements MedeaJason { callFfi: () => _platform.inner .wire_media_manager_handle_on_device_change(arg0, arg1), parseSuccessData: _wire2api_unit, - parseErrorData: _wire2api_FrbAnyhowException, + parseErrorData: _wire2api_DartOpaque, constMeta: kMediaManagerHandleOnDeviceChangeConstMeta, argValues: [manager, cb], hint: hint, @@ -2162,7 +2162,7 @@ class MedeaJasonImpl implements MedeaJason { return _platform.executeSync(FlutterRustBridgeSyncTask( callFfi: () => _platform.inner.wire_room_handle_mute_video(arg0, arg1), parseSuccessData: _wire2api_DartOpaque, - parseErrorData: _wire2api_FrbAnyhowException, + parseErrorData: null, constMeta: kRoomHandleMuteVideoConstMeta, argValues: [roomHandle, sourceKind], hint: hint, @@ -2184,7 +2184,7 @@ class MedeaJasonImpl implements MedeaJason { return _platform.executeSync(FlutterRustBridgeSyncTask( callFfi: () => _platform.inner.wire_room_handle_unmute_video(arg0, arg1), parseSuccessData: _wire2api_DartOpaque, - parseErrorData: _wire2api_FrbAnyhowException, + parseErrorData: null, constMeta: kRoomHandleUnmuteVideoConstMeta, argValues: [roomHandle, sourceKind], hint: hint, @@ -2206,7 +2206,7 @@ class MedeaJasonImpl implements MedeaJason { return _platform.executeSync(FlutterRustBridgeSyncTask( callFfi: () => _platform.inner.wire_room_handle_enable_video(arg0, arg1), parseSuccessData: _wire2api_DartOpaque, - parseErrorData: _wire2api_FrbAnyhowException, + parseErrorData: null, constMeta: kRoomHandleEnableVideoConstMeta, argValues: [roomHandle, sourceKind], hint: hint, @@ -2228,7 +2228,7 @@ class MedeaJasonImpl implements MedeaJason { return _platform.executeSync(FlutterRustBridgeSyncTask( callFfi: () => _platform.inner.wire_room_handle_disable_video(arg0, arg1), parseSuccessData: _wire2api_DartOpaque, - parseErrorData: _wire2api_FrbAnyhowException, + parseErrorData: null, constMeta: kRoomHandleDisableVideoConstMeta, argValues: [roomHandle, sourceKind], hint: hint, @@ -2290,7 +2290,7 @@ class MedeaJasonImpl implements MedeaJason { callFfi: () => _platform.inner.wire_room_handle_enable_remote_video(arg0, arg1), parseSuccessData: _wire2api_DartOpaque, - parseErrorData: _wire2api_FrbAnyhowException, + parseErrorData: null, constMeta: kRoomHandleEnableRemoteVideoConstMeta, argValues: [roomHandle, sourceKind], hint: hint, @@ -2313,7 +2313,7 @@ class MedeaJasonImpl implements MedeaJason { callFfi: () => _platform.inner.wire_room_handle_disable_remote_video(arg0, arg1), parseSuccessData: _wire2api_DartOpaque, - parseErrorData: _wire2api_FrbAnyhowException, + parseErrorData: null, constMeta: kRoomHandleDisableRemoteVideoConstMeta, argValues: [roomHandle, sourceKind], hint: hint, @@ -2334,7 +2334,7 @@ class MedeaJasonImpl implements MedeaJason { callFfi: () => _platform.inner.wire_room_handle_on_new_connection(arg0, arg1), parseSuccessData: _wire2api_unit, - parseErrorData: _wire2api_FrbAnyhowException, + parseErrorData: _wire2api_DartOpaque, constMeta: kRoomHandleOnNewConnectionConstMeta, argValues: [roomHandle, cb], hint: hint, @@ -2354,7 +2354,7 @@ class MedeaJasonImpl implements MedeaJason { return _platform.executeSync(FlutterRustBridgeSyncTask( callFfi: () => _platform.inner.wire_room_handle_on_close(arg0, arg1), parseSuccessData: _wire2api_unit, - parseErrorData: _wire2api_FrbAnyhowException, + parseErrorData: _wire2api_DartOpaque, constMeta: kRoomHandleOnCloseConstMeta, argValues: [roomHandle, cb], hint: hint, @@ -2375,7 +2375,7 @@ class MedeaJasonImpl implements MedeaJason { callFfi: () => _platform.inner.wire_room_handle_on_local_track(arg0, arg1), parseSuccessData: _wire2api_unit, - parseErrorData: _wire2api_FrbAnyhowException, + parseErrorData: _wire2api_DartOpaque, constMeta: kRoomHandleOnLocalTrackConstMeta, argValues: [roomHandle, cb], hint: hint, @@ -2396,7 +2396,7 @@ class MedeaJasonImpl implements MedeaJason { callFfi: () => _platform.inner.wire_room_handle_on_connection_loss(arg0, arg1), parseSuccessData: _wire2api_unit, - parseErrorData: _wire2api_FrbAnyhowException, + parseErrorData: _wire2api_DartOpaque, constMeta: kRoomHandleOnConnectionLossConstMeta, argValues: [roomHandle, cb], hint: hint, @@ -2417,7 +2417,7 @@ class MedeaJasonImpl implements MedeaJason { callFfi: () => _platform.inner.wire_room_handle_on_failed_local_media(arg0, arg1), parseSuccessData: _wire2api_unit, - parseErrorData: _wire2api_FrbAnyhowException, + parseErrorData: _wire2api_DartOpaque, constMeta: kRoomHandleOnFailedLocalMediaConstMeta, argValues: [roomHandle, cb], hint: hint, @@ -2487,10 +2487,6 @@ class MedeaJasonImpl implements MedeaJason { return _platform.inner.get_dart_object(raw); } - FrbAnyhowException _wire2api_FrbAnyhowException(dynamic raw) { - return FrbAnyhowException(raw as String); - } - Jason _wire2api_Jason(dynamic raw) { return Jason.fromRaw(raw[0], raw[1], this); } diff --git a/flutter/lib/src/native/ffi/jason_api.g.freezed.dart b/flutter/lib/src/native/ffi/jason_api.g.freezed.dart index 8b1fffad4..677c87cff 100644 --- a/flutter/lib/src/native/ffi/jason_api.g.freezed.dart +++ b/flutter/lib/src/native/ffi/jason_api.g.freezed.dart @@ -1,7 +1,7 @@ // coverage:ignore-file // GENERATED CODE - DO NOT MODIFY BY HAND // ignore_for_file: type=lint -// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target +// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark part of 'jason_api.g.dart'; @@ -96,25 +96,25 @@ class _$ApiConstrainFacingModeCopyWithImpl<$Res, } /// @nodoc -abstract class _$$ApiConstrainFacingMode_ExactCopyWith<$Res> +abstract class _$$ApiConstrainFacingMode_ExactImplCopyWith<$Res> implements $ApiConstrainFacingModeCopyWith<$Res> { - factory _$$ApiConstrainFacingMode_ExactCopyWith( - _$ApiConstrainFacingMode_Exact value, - $Res Function(_$ApiConstrainFacingMode_Exact) then) = - __$$ApiConstrainFacingMode_ExactCopyWithImpl<$Res>; + factory _$$ApiConstrainFacingMode_ExactImplCopyWith( + _$ApiConstrainFacingMode_ExactImpl value, + $Res Function(_$ApiConstrainFacingMode_ExactImpl) then) = + __$$ApiConstrainFacingMode_ExactImplCopyWithImpl<$Res>; @override @useResult $Res call({FacingMode field0}); } /// @nodoc -class __$$ApiConstrainFacingMode_ExactCopyWithImpl<$Res> +class __$$ApiConstrainFacingMode_ExactImplCopyWithImpl<$Res> extends _$ApiConstrainFacingModeCopyWithImpl<$Res, - _$ApiConstrainFacingMode_Exact> - implements _$$ApiConstrainFacingMode_ExactCopyWith<$Res> { - __$$ApiConstrainFacingMode_ExactCopyWithImpl( - _$ApiConstrainFacingMode_Exact _value, - $Res Function(_$ApiConstrainFacingMode_Exact) _then) + _$ApiConstrainFacingMode_ExactImpl> + implements _$$ApiConstrainFacingMode_ExactImplCopyWith<$Res> { + __$$ApiConstrainFacingMode_ExactImplCopyWithImpl( + _$ApiConstrainFacingMode_ExactImpl _value, + $Res Function(_$ApiConstrainFacingMode_ExactImpl) _then) : super(_value, _then); @pragma('vm:prefer-inline') @@ -122,7 +122,7 @@ class __$$ApiConstrainFacingMode_ExactCopyWithImpl<$Res> $Res call({ Object? field0 = null, }) { - return _then(_$ApiConstrainFacingMode_Exact( + return _then(_$ApiConstrainFacingMode_ExactImpl( null == field0 ? _value.field0 : field0 // ignore: cast_nullable_to_non_nullable @@ -133,8 +133,9 @@ class __$$ApiConstrainFacingMode_ExactCopyWithImpl<$Res> /// @nodoc -class _$ApiConstrainFacingMode_Exact implements ApiConstrainFacingMode_Exact { - const _$ApiConstrainFacingMode_Exact(this.field0); +class _$ApiConstrainFacingMode_ExactImpl + implements ApiConstrainFacingMode_Exact { + const _$ApiConstrainFacingMode_ExactImpl(this.field0); @override final FacingMode field0; @@ -148,7 +149,7 @@ class _$ApiConstrainFacingMode_Exact implements ApiConstrainFacingMode_Exact { bool operator ==(dynamic other) { return identical(this, other) || (other.runtimeType == runtimeType && - other is _$ApiConstrainFacingMode_Exact && + other is _$ApiConstrainFacingMode_ExactImpl && (identical(other.field0, field0) || other.field0 == field0)); } @@ -158,9 +159,10 @@ class _$ApiConstrainFacingMode_Exact implements ApiConstrainFacingMode_Exact { @JsonKey(ignore: true) @override @pragma('vm:prefer-inline') - _$$ApiConstrainFacingMode_ExactCopyWith<_$ApiConstrainFacingMode_Exact> - get copyWith => __$$ApiConstrainFacingMode_ExactCopyWithImpl< - _$ApiConstrainFacingMode_Exact>(this, _$identity); + _$$ApiConstrainFacingMode_ExactImplCopyWith< + _$ApiConstrainFacingMode_ExactImpl> + get copyWith => __$$ApiConstrainFacingMode_ExactImplCopyWithImpl< + _$ApiConstrainFacingMode_ExactImpl>(this, _$identity); @override @optionalTypeArgs @@ -227,36 +229,37 @@ class _$ApiConstrainFacingMode_Exact implements ApiConstrainFacingMode_Exact { abstract class ApiConstrainFacingMode_Exact implements ApiConstrainFacingMode { const factory ApiConstrainFacingMode_Exact(final FacingMode field0) = - _$ApiConstrainFacingMode_Exact; + _$ApiConstrainFacingMode_ExactImpl; @override FacingMode get field0; @override @JsonKey(ignore: true) - _$$ApiConstrainFacingMode_ExactCopyWith<_$ApiConstrainFacingMode_Exact> + _$$ApiConstrainFacingMode_ExactImplCopyWith< + _$ApiConstrainFacingMode_ExactImpl> get copyWith => throw _privateConstructorUsedError; } /// @nodoc -abstract class _$$ApiConstrainFacingMode_IdealCopyWith<$Res> +abstract class _$$ApiConstrainFacingMode_IdealImplCopyWith<$Res> implements $ApiConstrainFacingModeCopyWith<$Res> { - factory _$$ApiConstrainFacingMode_IdealCopyWith( - _$ApiConstrainFacingMode_Ideal value, - $Res Function(_$ApiConstrainFacingMode_Ideal) then) = - __$$ApiConstrainFacingMode_IdealCopyWithImpl<$Res>; + factory _$$ApiConstrainFacingMode_IdealImplCopyWith( + _$ApiConstrainFacingMode_IdealImpl value, + $Res Function(_$ApiConstrainFacingMode_IdealImpl) then) = + __$$ApiConstrainFacingMode_IdealImplCopyWithImpl<$Res>; @override @useResult $Res call({FacingMode field0}); } /// @nodoc -class __$$ApiConstrainFacingMode_IdealCopyWithImpl<$Res> +class __$$ApiConstrainFacingMode_IdealImplCopyWithImpl<$Res> extends _$ApiConstrainFacingModeCopyWithImpl<$Res, - _$ApiConstrainFacingMode_Ideal> - implements _$$ApiConstrainFacingMode_IdealCopyWith<$Res> { - __$$ApiConstrainFacingMode_IdealCopyWithImpl( - _$ApiConstrainFacingMode_Ideal _value, - $Res Function(_$ApiConstrainFacingMode_Ideal) _then) + _$ApiConstrainFacingMode_IdealImpl> + implements _$$ApiConstrainFacingMode_IdealImplCopyWith<$Res> { + __$$ApiConstrainFacingMode_IdealImplCopyWithImpl( + _$ApiConstrainFacingMode_IdealImpl _value, + $Res Function(_$ApiConstrainFacingMode_IdealImpl) _then) : super(_value, _then); @pragma('vm:prefer-inline') @@ -264,7 +267,7 @@ class __$$ApiConstrainFacingMode_IdealCopyWithImpl<$Res> $Res call({ Object? field0 = null, }) { - return _then(_$ApiConstrainFacingMode_Ideal( + return _then(_$ApiConstrainFacingMode_IdealImpl( null == field0 ? _value.field0 : field0 // ignore: cast_nullable_to_non_nullable @@ -275,8 +278,9 @@ class __$$ApiConstrainFacingMode_IdealCopyWithImpl<$Res> /// @nodoc -class _$ApiConstrainFacingMode_Ideal implements ApiConstrainFacingMode_Ideal { - const _$ApiConstrainFacingMode_Ideal(this.field0); +class _$ApiConstrainFacingMode_IdealImpl + implements ApiConstrainFacingMode_Ideal { + const _$ApiConstrainFacingMode_IdealImpl(this.field0); @override final FacingMode field0; @@ -290,7 +294,7 @@ class _$ApiConstrainFacingMode_Ideal implements ApiConstrainFacingMode_Ideal { bool operator ==(dynamic other) { return identical(this, other) || (other.runtimeType == runtimeType && - other is _$ApiConstrainFacingMode_Ideal && + other is _$ApiConstrainFacingMode_IdealImpl && (identical(other.field0, field0) || other.field0 == field0)); } @@ -300,9 +304,10 @@ class _$ApiConstrainFacingMode_Ideal implements ApiConstrainFacingMode_Ideal { @JsonKey(ignore: true) @override @pragma('vm:prefer-inline') - _$$ApiConstrainFacingMode_IdealCopyWith<_$ApiConstrainFacingMode_Ideal> - get copyWith => __$$ApiConstrainFacingMode_IdealCopyWithImpl< - _$ApiConstrainFacingMode_Ideal>(this, _$identity); + _$$ApiConstrainFacingMode_IdealImplCopyWith< + _$ApiConstrainFacingMode_IdealImpl> + get copyWith => __$$ApiConstrainFacingMode_IdealImplCopyWithImpl< + _$ApiConstrainFacingMode_IdealImpl>(this, _$identity); @override @optionalTypeArgs @@ -369,13 +374,14 @@ class _$ApiConstrainFacingMode_Ideal implements ApiConstrainFacingMode_Ideal { abstract class ApiConstrainFacingMode_Ideal implements ApiConstrainFacingMode { const factory ApiConstrainFacingMode_Ideal(final FacingMode field0) = - _$ApiConstrainFacingMode_Ideal; + _$ApiConstrainFacingMode_IdealImpl; @override FacingMode get field0; @override @JsonKey(ignore: true) - _$$ApiConstrainFacingMode_IdealCopyWith<_$ApiConstrainFacingMode_Ideal> + _$$ApiConstrainFacingMode_IdealImplCopyWith< + _$ApiConstrainFacingMode_IdealImpl> get copyWith => throw _privateConstructorUsedError; } @@ -466,22 +472,22 @@ class _$ConstrainU32CopyWithImpl<$Res, $Val extends ConstrainU32> } /// @nodoc -abstract class _$$ConstrainU32_ExactCopyWith<$Res> +abstract class _$$ConstrainU32_ExactImplCopyWith<$Res> implements $ConstrainU32CopyWith<$Res> { - factory _$$ConstrainU32_ExactCopyWith(_$ConstrainU32_Exact value, - $Res Function(_$ConstrainU32_Exact) then) = - __$$ConstrainU32_ExactCopyWithImpl<$Res>; + factory _$$ConstrainU32_ExactImplCopyWith(_$ConstrainU32_ExactImpl value, + $Res Function(_$ConstrainU32_ExactImpl) then) = + __$$ConstrainU32_ExactImplCopyWithImpl<$Res>; @override @useResult $Res call({int field0}); } /// @nodoc -class __$$ConstrainU32_ExactCopyWithImpl<$Res> - extends _$ConstrainU32CopyWithImpl<$Res, _$ConstrainU32_Exact> - implements _$$ConstrainU32_ExactCopyWith<$Res> { - __$$ConstrainU32_ExactCopyWithImpl( - _$ConstrainU32_Exact _value, $Res Function(_$ConstrainU32_Exact) _then) +class __$$ConstrainU32_ExactImplCopyWithImpl<$Res> + extends _$ConstrainU32CopyWithImpl<$Res, _$ConstrainU32_ExactImpl> + implements _$$ConstrainU32_ExactImplCopyWith<$Res> { + __$$ConstrainU32_ExactImplCopyWithImpl(_$ConstrainU32_ExactImpl _value, + $Res Function(_$ConstrainU32_ExactImpl) _then) : super(_value, _then); @pragma('vm:prefer-inline') @@ -489,7 +495,7 @@ class __$$ConstrainU32_ExactCopyWithImpl<$Res> $Res call({ Object? field0 = null, }) { - return _then(_$ConstrainU32_Exact( + return _then(_$ConstrainU32_ExactImpl( null == field0 ? _value.field0 : field0 // ignore: cast_nullable_to_non_nullable @@ -500,8 +506,8 @@ class __$$ConstrainU32_ExactCopyWithImpl<$Res> /// @nodoc -class _$ConstrainU32_Exact implements ConstrainU32_Exact { - const _$ConstrainU32_Exact(this.field0); +class _$ConstrainU32_ExactImpl implements ConstrainU32_Exact { + const _$ConstrainU32_ExactImpl(this.field0); @override final int field0; @@ -515,7 +521,7 @@ class _$ConstrainU32_Exact implements ConstrainU32_Exact { bool operator ==(dynamic other) { return identical(this, other) || (other.runtimeType == runtimeType && - other is _$ConstrainU32_Exact && + other is _$ConstrainU32_ExactImpl && (identical(other.field0, field0) || other.field0 == field0)); } @@ -525,8 +531,8 @@ class _$ConstrainU32_Exact implements ConstrainU32_Exact { @JsonKey(ignore: true) @override @pragma('vm:prefer-inline') - _$$ConstrainU32_ExactCopyWith<_$ConstrainU32_Exact> get copyWith => - __$$ConstrainU32_ExactCopyWithImpl<_$ConstrainU32_Exact>( + _$$ConstrainU32_ExactImplCopyWith<_$ConstrainU32_ExactImpl> get copyWith => + __$$ConstrainU32_ExactImplCopyWithImpl<_$ConstrainU32_ExactImpl>( this, _$identity); @override @@ -599,33 +605,33 @@ class _$ConstrainU32_Exact implements ConstrainU32_Exact { } abstract class ConstrainU32_Exact implements ConstrainU32 { - const factory ConstrainU32_Exact(final int field0) = _$ConstrainU32_Exact; + const factory ConstrainU32_Exact(final int field0) = _$ConstrainU32_ExactImpl; @override int get field0; @override @JsonKey(ignore: true) - _$$ConstrainU32_ExactCopyWith<_$ConstrainU32_Exact> get copyWith => + _$$ConstrainU32_ExactImplCopyWith<_$ConstrainU32_ExactImpl> get copyWith => throw _privateConstructorUsedError; } /// @nodoc -abstract class _$$ConstrainU32_IdealCopyWith<$Res> +abstract class _$$ConstrainU32_IdealImplCopyWith<$Res> implements $ConstrainU32CopyWith<$Res> { - factory _$$ConstrainU32_IdealCopyWith(_$ConstrainU32_Ideal value, - $Res Function(_$ConstrainU32_Ideal) then) = - __$$ConstrainU32_IdealCopyWithImpl<$Res>; + factory _$$ConstrainU32_IdealImplCopyWith(_$ConstrainU32_IdealImpl value, + $Res Function(_$ConstrainU32_IdealImpl) then) = + __$$ConstrainU32_IdealImplCopyWithImpl<$Res>; @override @useResult $Res call({int field0}); } /// @nodoc -class __$$ConstrainU32_IdealCopyWithImpl<$Res> - extends _$ConstrainU32CopyWithImpl<$Res, _$ConstrainU32_Ideal> - implements _$$ConstrainU32_IdealCopyWith<$Res> { - __$$ConstrainU32_IdealCopyWithImpl( - _$ConstrainU32_Ideal _value, $Res Function(_$ConstrainU32_Ideal) _then) +class __$$ConstrainU32_IdealImplCopyWithImpl<$Res> + extends _$ConstrainU32CopyWithImpl<$Res, _$ConstrainU32_IdealImpl> + implements _$$ConstrainU32_IdealImplCopyWith<$Res> { + __$$ConstrainU32_IdealImplCopyWithImpl(_$ConstrainU32_IdealImpl _value, + $Res Function(_$ConstrainU32_IdealImpl) _then) : super(_value, _then); @pragma('vm:prefer-inline') @@ -633,7 +639,7 @@ class __$$ConstrainU32_IdealCopyWithImpl<$Res> $Res call({ Object? field0 = null, }) { - return _then(_$ConstrainU32_Ideal( + return _then(_$ConstrainU32_IdealImpl( null == field0 ? _value.field0 : field0 // ignore: cast_nullable_to_non_nullable @@ -644,8 +650,8 @@ class __$$ConstrainU32_IdealCopyWithImpl<$Res> /// @nodoc -class _$ConstrainU32_Ideal implements ConstrainU32_Ideal { - const _$ConstrainU32_Ideal(this.field0); +class _$ConstrainU32_IdealImpl implements ConstrainU32_Ideal { + const _$ConstrainU32_IdealImpl(this.field0); @override final int field0; @@ -659,7 +665,7 @@ class _$ConstrainU32_Ideal implements ConstrainU32_Ideal { bool operator ==(dynamic other) { return identical(this, other) || (other.runtimeType == runtimeType && - other is _$ConstrainU32_Ideal && + other is _$ConstrainU32_IdealImpl && (identical(other.field0, field0) || other.field0 == field0)); } @@ -669,8 +675,8 @@ class _$ConstrainU32_Ideal implements ConstrainU32_Ideal { @JsonKey(ignore: true) @override @pragma('vm:prefer-inline') - _$$ConstrainU32_IdealCopyWith<_$ConstrainU32_Ideal> get copyWith => - __$$ConstrainU32_IdealCopyWithImpl<_$ConstrainU32_Ideal>( + _$$ConstrainU32_IdealImplCopyWith<_$ConstrainU32_IdealImpl> get copyWith => + __$$ConstrainU32_IdealImplCopyWithImpl<_$ConstrainU32_IdealImpl>( this, _$identity); @override @@ -743,33 +749,33 @@ class _$ConstrainU32_Ideal implements ConstrainU32_Ideal { } abstract class ConstrainU32_Ideal implements ConstrainU32 { - const factory ConstrainU32_Ideal(final int field0) = _$ConstrainU32_Ideal; + const factory ConstrainU32_Ideal(final int field0) = _$ConstrainU32_IdealImpl; @override int get field0; @override @JsonKey(ignore: true) - _$$ConstrainU32_IdealCopyWith<_$ConstrainU32_Ideal> get copyWith => + _$$ConstrainU32_IdealImplCopyWith<_$ConstrainU32_IdealImpl> get copyWith => throw _privateConstructorUsedError; } /// @nodoc -abstract class _$$ConstrainU32_RangeCopyWith<$Res> +abstract class _$$ConstrainU32_RangeImplCopyWith<$Res> implements $ConstrainU32CopyWith<$Res> { - factory _$$ConstrainU32_RangeCopyWith(_$ConstrainU32_Range value, - $Res Function(_$ConstrainU32_Range) then) = - __$$ConstrainU32_RangeCopyWithImpl<$Res>; + factory _$$ConstrainU32_RangeImplCopyWith(_$ConstrainU32_RangeImpl value, + $Res Function(_$ConstrainU32_RangeImpl) then) = + __$$ConstrainU32_RangeImplCopyWithImpl<$Res>; @override @useResult $Res call({int field0, int field1}); } /// @nodoc -class __$$ConstrainU32_RangeCopyWithImpl<$Res> - extends _$ConstrainU32CopyWithImpl<$Res, _$ConstrainU32_Range> - implements _$$ConstrainU32_RangeCopyWith<$Res> { - __$$ConstrainU32_RangeCopyWithImpl( - _$ConstrainU32_Range _value, $Res Function(_$ConstrainU32_Range) _then) +class __$$ConstrainU32_RangeImplCopyWithImpl<$Res> + extends _$ConstrainU32CopyWithImpl<$Res, _$ConstrainU32_RangeImpl> + implements _$$ConstrainU32_RangeImplCopyWith<$Res> { + __$$ConstrainU32_RangeImplCopyWithImpl(_$ConstrainU32_RangeImpl _value, + $Res Function(_$ConstrainU32_RangeImpl) _then) : super(_value, _then); @pragma('vm:prefer-inline') @@ -778,7 +784,7 @@ class __$$ConstrainU32_RangeCopyWithImpl<$Res> Object? field0 = null, Object? field1 = null, }) { - return _then(_$ConstrainU32_Range( + return _then(_$ConstrainU32_RangeImpl( null == field0 ? _value.field0 : field0 // ignore: cast_nullable_to_non_nullable @@ -793,8 +799,8 @@ class __$$ConstrainU32_RangeCopyWithImpl<$Res> /// @nodoc -class _$ConstrainU32_Range implements ConstrainU32_Range { - const _$ConstrainU32_Range(this.field0, this.field1); +class _$ConstrainU32_RangeImpl implements ConstrainU32_Range { + const _$ConstrainU32_RangeImpl(this.field0, this.field1); @override final int field0; @@ -810,7 +816,7 @@ class _$ConstrainU32_Range implements ConstrainU32_Range { bool operator ==(dynamic other) { return identical(this, other) || (other.runtimeType == runtimeType && - other is _$ConstrainU32_Range && + other is _$ConstrainU32_RangeImpl && (identical(other.field0, field0) || other.field0 == field0) && (identical(other.field1, field1) || other.field1 == field1)); } @@ -821,8 +827,8 @@ class _$ConstrainU32_Range implements ConstrainU32_Range { @JsonKey(ignore: true) @override @pragma('vm:prefer-inline') - _$$ConstrainU32_RangeCopyWith<_$ConstrainU32_Range> get copyWith => - __$$ConstrainU32_RangeCopyWithImpl<_$ConstrainU32_Range>( + _$$ConstrainU32_RangeImplCopyWith<_$ConstrainU32_RangeImpl> get copyWith => + __$$ConstrainU32_RangeImplCopyWithImpl<_$ConstrainU32_RangeImpl>( this, _$identity); @override @@ -896,13 +902,13 @@ class _$ConstrainU32_Range implements ConstrainU32_Range { abstract class ConstrainU32_Range implements ConstrainU32 { const factory ConstrainU32_Range(final int field0, final int field1) = - _$ConstrainU32_Range; + _$ConstrainU32_RangeImpl; @override int get field0; int get field1; @override @JsonKey(ignore: true) - _$$ConstrainU32_RangeCopyWith<_$ConstrainU32_Range> get copyWith => + _$$ConstrainU32_RangeImplCopyWith<_$ConstrainU32_RangeImpl> get copyWith => throw _privateConstructorUsedError; } diff --git a/flutter/lib/src/native/jason.dart b/flutter/lib/src/native/jason.dart index aa9dc2bfa..dec327611 100644 --- a/flutter/lib/src/native/jason.dart +++ b/flutter/lib/src/native/jason.dart @@ -3,15 +3,12 @@ library jason; import 'dart:ffi'; import 'dart:io'; -import 'package:flutter_rust_bridge/flutter_rust_bridge.dart'; - import '../interface/jason.dart' as base; import '../interface/media_manager.dart'; import '../interface/room_handle.dart'; import '../util/move_semantic.dart'; import '../util/rust_opaque.dart'; import '/src/util/rust_handles_storage.dart'; -import 'ffi/box_handle.dart'; import 'ffi/callback.dart' as callback; import 'ffi/completer.dart' as completer; import 'ffi/exception.dart' as exceptions; @@ -47,22 +44,6 @@ void onPanic(void Function(String)? cb) { _onPanicCallback = cb; } -extension FfiExceptionParse on FfiException { - Object parse() { - if (!message.contains('RESULT_ERROR: DartError')) { - return this; - } - var handle = message; - var reg = RegExp(r'\(([^]*?)\)'); - var errPtr = - Pointer.fromAddress(int.parse(reg.firstMatch(handle)![1]!)); - var err = unboxDartHandle(errPtr); - freeBoxedDartHandle(errPtr); - - return err; - } -} - DynamicLibrary _dlLoad() { if (!(Platform.isAndroid || Platform.isLinux || diff --git a/flutter/lib/src/native/media_manager.dart b/flutter/lib/src/native/media_manager.dart index e9952844d..b8117c7f5 100644 --- a/flutter/lib/src/native/media_manager.dart +++ b/flutter/lib/src/native/media_manager.dart @@ -1,8 +1,6 @@ import 'dart:ffi'; import 'dart:io'; -import 'package:flutter_rust_bridge/flutter_rust_bridge.dart'; - import '../../medea_jason.dart'; import '../interface/media_stream_settings.dart' as base_settings; import '../util/move_semantic.dart'; @@ -28,13 +26,9 @@ class NativeMediaManagerHandle implements MediaManagerHandle { Future> initLocalTracks( base_settings.MediaStreamSettings caps) async { Pointer tracks; - try { - tracks = await (api.mediaManagerHandleInitLocalTracks( - manager: opaque.innerOpaque, - caps: (caps as MediaStreamSettings).setting) as Future) as Pointer; - } on FfiException catch (anyhow) { - throw anyhow.parse(); - } + tracks = await (api.mediaManagerHandleInitLocalTracks( + manager: opaque.innerOpaque, + caps: (caps as MediaStreamSettings).setting) as Future) as Pointer; return api .vecLocalTracksFromPtr(ptr: tracks.address) @@ -45,13 +39,8 @@ class NativeMediaManagerHandle implements MediaManagerHandle { @override Future> enumerateDevices() async { Pointer devices; - try { - devices = await (api.mediaManagerHandleEnumerateDevices( - manager: opaque.innerOpaque) as Future); - } on FfiException catch (anyhow) { - throw anyhow.parse(); - } - + devices = await (api.mediaManagerHandleEnumerateDevices( + manager: opaque.innerOpaque) as Future); return api .vecMediaDeviceDetailsFromPtr(ptr: devices.address) .map((info) => NativeMediaDeviceDetails(info)) @@ -66,12 +55,8 @@ class NativeMediaManagerHandle implements MediaManagerHandle { } Pointer devices; - try { - devices = await (api.mediaManagerHandleEnumerateDisplays( - manager: opaque.innerOpaque) as Future) as Pointer; - } on FfiException catch (anyhow) { - throw anyhow.parse(); - } + devices = await (api.mediaManagerHandleEnumerateDisplays( + manager: opaque.innerOpaque) as Future) as Pointer; return api .vecMediaDisplayDetailsFromPtr(ptr: devices.address) @@ -81,51 +66,31 @@ class NativeMediaManagerHandle implements MediaManagerHandle { @override Future setOutputAudioId(String deviceId) async { - try { - await (api.mediaManagerHandleSetOutputAudioId( - manager: opaque.innerOpaque, deviceId: deviceId) as Future); - } on FfiException catch (anyhow) { - throw anyhow.parse(); - } + await (api.mediaManagerHandleSetOutputAudioId( + manager: opaque.innerOpaque, deviceId: deviceId) as Future); } @override Future setMicrophoneVolume(int level) async { - try { - await (api.mediaManagerHandleSetMicrophoneVolume( - manager: opaque.innerOpaque, level: level) as Future); - } on FfiException catch (anyhow) { - throw anyhow.parse(); - } + await (api.mediaManagerHandleSetMicrophoneVolume( + manager: opaque.innerOpaque, level: level) as Future); } @override Future microphoneVolume() async { - try { - return await (api.mediaManagerHandleMicrophoneVolume( - manager: opaque.innerOpaque) as Future) as int; - } on FfiException catch (anyhow) { - throw anyhow.parse(); - } + return await (api.mediaManagerHandleMicrophoneVolume( + manager: opaque.innerOpaque) as Future) as int; } @override Future microphoneVolumeIsAvailable() async { - try { - return await (api.mediaManagerHandleMicrophoneVolumeIsAvailable( - manager: opaque.innerOpaque) as Future) as bool; - } on FfiException catch (anyhow) { - throw anyhow.parse(); - } + return await (api.mediaManagerHandleMicrophoneVolumeIsAvailable( + manager: opaque.innerOpaque) as Future) as bool; } @override void onDeviceChange(void Function() cb) { - try { - api.mediaManagerHandleOnDeviceChange(manager: opaque.innerOpaque, cb: cb); - } on FfiException catch (anyhow) { - throw anyhow.parse(); - } + api.mediaManagerHandleOnDeviceChange(manager: opaque.innerOpaque, cb: cb); } @moveSemantics diff --git a/flutter/lib/src/native/reconnect_handle.dart b/flutter/lib/src/native/reconnect_handle.dart index c8916f5f0..2c5fcc247 100644 --- a/flutter/lib/src/native/reconnect_handle.dart +++ b/flutter/lib/src/native/reconnect_handle.dart @@ -1,5 +1,3 @@ -import 'package:flutter_rust_bridge/flutter_rust_bridge.dart'; - import '../interface/reconnect_handle.dart'; import '../util/move_semantic.dart'; import '../util/rust_opaque.dart'; @@ -24,12 +22,8 @@ class NativeReconnectHandle implements ReconnectHandle { throw ArgumentError.value(delayMs, 'delayMs', 'Expected `u32`'); } - try { - await (api.reconnectHandleReconnectWithDelay( - reconnectHandle: opaque.innerOpaque, delayMs: delayMs) as Future); - } on FfiException catch (anyhow) { - throw anyhow.parse(); - } + await (api.reconnectHandleReconnectWithDelay( + reconnectHandle: opaque.innerOpaque, delayMs: delayMs) as Future); } @override @@ -52,16 +46,12 @@ class NativeReconnectHandle implements ReconnectHandle { } } - try { - await (api.reconnectHandleReconnectWithBackoff( - reconnectHandle: opaque.innerOpaque, - startingDelay: startingDelayMs, - multiplier: multiplier, - maxDelay: maxDelay, - maxElapsedTimeMs: maxElapsedTimeMs) as Future); - } on FfiException catch (anyhow) { - throw anyhow.parse(); - } + await (api.reconnectHandleReconnectWithBackoff( + reconnectHandle: opaque.innerOpaque, + startingDelay: startingDelayMs, + multiplier: multiplier, + maxDelay: maxDelay, + maxElapsedTimeMs: maxElapsedTimeMs) as Future); } @moveSemantics diff --git a/flutter/lib/src/native/room_handle.dart b/flutter/lib/src/native/room_handle.dart index 781214c8d..76371bfce 100644 --- a/flutter/lib/src/native/room_handle.dart +++ b/flutter/lib/src/native/room_handle.dart @@ -1,5 +1,3 @@ -import 'package:flutter_rust_bridge/flutter_rust_bridge.dart'; - import '../interface/connection_handle.dart'; import '../interface/media_stream_settings.dart' as base_settings; import '../interface/media_track.dart'; @@ -30,214 +28,133 @@ class NativeRoomHandle implements RoomHandle { @override Future join(String token) async { - try { - await (api.roomHandleJoin(roomHandle: opaque.innerOpaque, token: token) - as Future); - } on FfiException catch (anyhow) { - throw anyhow.parse(); - } + await (api.roomHandleJoin(roomHandle: opaque.innerOpaque, token: token) + as Future); } @override Future setLocalMediaSettings(base_settings.MediaStreamSettings settings, bool stopFirst, bool rollbackOnFail) async { - try { - await (api.roomHandleSetLocalMediaSettings( - roomHandle: opaque.innerOpaque, - settings: (settings as MediaStreamSettings).setting, - stopFirst: stopFirst, - rollbackOnFail: rollbackOnFail) as Future); - } on FfiException catch (anyhow) { - throw anyhow.parse(); - } + await (api.roomHandleSetLocalMediaSettings( + roomHandle: opaque.innerOpaque, + settings: (settings as MediaStreamSettings).setting, + stopFirst: stopFirst, + rollbackOnFail: rollbackOnFail) as Future); } @override Future muteAudio() async { - try { - await (api.roomHandleMuteAudio(roomHandle: opaque.innerOpaque) as Future); - } on FfiException catch (anyhow) { - throw anyhow.parse(); - } + await (api.roomHandleMuteAudio(roomHandle: opaque.innerOpaque) as Future); } @override Future unmuteAudio() async { - try { - await (api.roomHandleUnmuteAudio(roomHandle: opaque.innerOpaque) - as Future); - } on FfiException catch (anyhow) { - throw anyhow.parse(); - } + await (api.roomHandleUnmuteAudio(roomHandle: opaque.innerOpaque) as Future); } @override Future enableAudio() async { - try { - await (api.roomHandleEnableAudio(roomHandle: opaque.innerOpaque) - as Future); - } on FfiException catch (anyhow) { - throw anyhow.parse(); - } + await (api.roomHandleEnableAudio(roomHandle: opaque.innerOpaque) as Future); } @override Future disableAudio() async { - try { - await (api.roomHandleDisableAudio(roomHandle: opaque.innerOpaque) - as Future); - } on FfiException catch (anyhow) { - throw anyhow.parse(); - } + await (api.roomHandleDisableAudio(roomHandle: opaque.innerOpaque) + as Future); } @override Future muteVideo([MediaSourceKind? kind]) async { - try { - await (api.roomHandleMuteVideo( - roomHandle: opaque.innerOpaque, sourceKind: kind) as Future); - } on FfiException catch (anyhow) { - throw anyhow.parse(); - } + await (api.roomHandleMuteVideo( + roomHandle: opaque.innerOpaque, sourceKind: kind) as Future); } @override Future unmuteVideo([MediaSourceKind? kind]) async { - try { - await (api.roomHandleUnmuteVideo( - roomHandle: opaque.innerOpaque, sourceKind: kind) as Future); - } on FfiException catch (anyhow) { - throw anyhow.parse(); - } + await (api.roomHandleUnmuteVideo( + roomHandle: opaque.innerOpaque, sourceKind: kind) as Future); } @override Future enableVideo([MediaSourceKind? kind]) async { - try { - await (api.roomHandleEnableVideo( - roomHandle: opaque.innerOpaque, sourceKind: kind) as Future); - } on FfiException catch (anyhow) { - throw anyhow.parse(); - } + await (api.roomHandleEnableVideo( + roomHandle: opaque.innerOpaque, sourceKind: kind) as Future); } @override Future disableVideo([MediaSourceKind? kind]) async { - try { - await (api.roomHandleDisableVideo( - roomHandle: opaque.innerOpaque, sourceKind: kind) as Future); - } on FfiException catch (anyhow) { - throw anyhow.parse(); - } + await (api.roomHandleDisableVideo( + roomHandle: opaque.innerOpaque, sourceKind: kind) as Future); } @override Future enableRemoteAudio() async { - try { - await (api.roomHandleEnableRemoteAudio(roomHandle: opaque.innerOpaque) - as Future); - } on FfiException catch (anyhow) { - throw anyhow.parse(); - } + await (api.roomHandleEnableRemoteAudio(roomHandle: opaque.innerOpaque) + as Future); } @override Future disableRemoteAudio() async { - try { - await (api.roomHandleDisableRemoteAudio(roomHandle: opaque.innerOpaque) - as Future); - } on FfiException catch (anyhow) { - throw anyhow.parse(); - } + await (api.roomHandleDisableRemoteAudio(roomHandle: opaque.innerOpaque) + as Future); } @override Future enableRemoteVideo([MediaSourceKind? kind]) async { - try { - await (api.roomHandleEnableRemoteVideo( - roomHandle: opaque.innerOpaque, sourceKind: kind) as Future); - } on FfiException catch (anyhow) { - throw anyhow.parse(); - } + await (api.roomHandleEnableRemoteVideo( + roomHandle: opaque.innerOpaque, sourceKind: kind) as Future); } @override Future disableRemoteVideo([MediaSourceKind? kind]) async { - try { - await (api.roomHandleDisableRemoteVideo( - roomHandle: opaque.innerOpaque, sourceKind: kind) as Future); - } on FfiException catch (anyhow) { - throw anyhow.parse(); - } + await (api.roomHandleDisableRemoteVideo( + roomHandle: opaque.innerOpaque, sourceKind: kind) as Future); } @override void onNewConnection(void Function(ConnectionHandle) f) { - try { - api.roomHandleOnNewConnection( - roomHandle: opaque.innerOpaque, - cb: (t) { - f(NativeConnectionHandle( - api.connectionHandleFromPtr(ptr: t.address))); - }); - } on FfiException catch (anyhow) { - throw anyhow.parse(); - } + api.roomHandleOnNewConnection( + roomHandle: opaque.innerOpaque, + cb: (t) { + f(NativeConnectionHandle( + api.connectionHandleFromPtr(ptr: t.address))); + }); } @override void onClose(void Function(RoomCloseReason) f) { - try { - api.roomHandleOnClose( - roomHandle: opaque.innerOpaque, - cb: (t) { - f(NativeRoomCloseReason( - api.roomCloseReasonFromPtr(ptr: t.address))); - }); - } on FfiException catch (anyhow) { - throw anyhow.parse(); - } + api.roomHandleOnClose( + roomHandle: opaque.innerOpaque, + cb: (t) { + f(NativeRoomCloseReason(api.roomCloseReasonFromPtr(ptr: t.address))); + }); } @override void onLocalTrack(void Function(LocalMediaTrack) f) { - try { - api.roomHandleOnLocalTrack( - roomHandle: opaque.innerOpaque, - cb: (t) { - f(NativeLocalMediaTrack( - api.localMediaTrackFromPtr(ptr: t.address))); - }); - } on FfiException catch (anyhow) { - throw anyhow.parse(); - } + api.roomHandleOnLocalTrack( + roomHandle: opaque.innerOpaque, + cb: (t) { + f(NativeLocalMediaTrack(api.localMediaTrackFromPtr(ptr: t.address))); + }); } @override void onConnectionLoss(void Function(ReconnectHandle) f) { - try { - api.roomHandleOnConnectionLoss( - roomHandle: opaque.innerOpaque, - cb: (t) { - f(NativeReconnectHandle( - api.reconnectHandleFromPtr(ptr: t.address))); - }); - } on FfiException catch (anyhow) { - throw anyhow.parse(); - } + api.roomHandleOnConnectionLoss( + roomHandle: opaque.innerOpaque, + cb: (t) { + f(NativeReconnectHandle(api.reconnectHandleFromPtr(ptr: t.address))); + }); } @override void onFailedLocalMedia(void Function(Object) f) { - try { - api.roomHandleOnFailedLocalMedia( - roomHandle: opaque.innerOpaque, - cb: (err) { - f(err); - }); - } on FfiException catch (anyhow) { - throw anyhow.parse(); - } + api.roomHandleOnFailedLocalMedia( + roomHandle: opaque.innerOpaque, + cb: (err) { + f(err); + }); } @moveSemantics diff --git a/flutter/pubspec.yaml b/flutter/pubspec.yaml index 39cb02479..f6f65b671 100644 --- a/flutter/pubspec.yaml +++ b/flutter/pubspec.yaml @@ -16,7 +16,7 @@ dependencies: http: ^0.13.5 js: ^0.6.5 json_annotation: ^4.7.0 - medea_flutter_webrtc: 0.8.3-dev+rev.d5a07ce262833b307e4b0e5d39badd55eadf812a + medea_flutter_webrtc: 0.8.3-dev+rev.0fe64b4610154ddb7e8774a952b6ecf6369b7633 meta: ^1.8.0 retry: ^3.1.0 tuple: ^2.0.1 diff --git a/src/api/dart/api.rs b/src/api/dart/api.rs index 609a84f0c..393ecd683 100644 --- a/src/api/dart/api.rs +++ b/src/api/dart/api.rs @@ -311,14 +311,12 @@ pub fn connection_handle_from_ptr( pub fn connection_handle_on_close( connection: RustOpaque, f: DartOpaque, -) -> anyhow::Result> { +) -> Result, DartOpaque> { let f = unsafe { platform::Function::new(f.try_unwrap().unwrap().into_raw().cast()) }; - connection - .on_close(f) - .map_err(|err| anyhow::anyhow!("{:?}", DartError::from(err)))?; + connection.on_close(f).map_err(DartError::from)?; Ok(SyncReturn(())) } @@ -334,14 +332,14 @@ pub fn connection_handle_on_close( pub fn connection_handle_on_remote_track_added( connection: RustOpaque, f: DartOpaque, -) -> anyhow::Result> { +) -> Result, DartOpaque> { let f = unsafe { platform::Function::new(f.try_unwrap().unwrap().into_raw().cast()) }; connection .on_remote_track_added(f) - .map_err(|err| anyhow::anyhow!("{:?}", DartError::from(err)))?; + .map_err(DartError::from)?; Ok(SyncReturn(())) } @@ -355,14 +353,14 @@ pub fn connection_handle_on_remote_track_added( pub fn connection_handle_on_quality_score_update( connection: RustOpaque, f: DartOpaque, -) -> anyhow::Result> { +) -> Result, DartOpaque> { let f = unsafe { platform::Function::new(f.try_unwrap().unwrap().into_raw().cast()) }; connection .on_quality_score_update(f) - .map_err(|err| anyhow::anyhow!("{:?}", DartError::from(err)))?; + .map_err(DartError::from)?; Ok(SyncReturn(())) } @@ -374,10 +372,10 @@ pub fn connection_handle_on_quality_score_update( /// If [`ConnectionHandle::get_remote_member_id()`] errors. pub fn connection_handle_get_remote_member_id( connection: RustOpaque, -) -> anyhow::Result> { - Ok(SyncReturn(connection.get_remote_member_id().map_err( - |err| anyhow::anyhow!("{:?}", DartError::from(err)), - )?)) +) -> Result, DartOpaque> { + Ok(SyncReturn( + connection.get_remote_member_id().map_err(DartError::from)?, + )) } /// Enables inbound audio in the provided `connection`. @@ -800,13 +798,13 @@ pub fn media_manager_handle_microphone_volume( pub fn media_manager_handle_on_device_change( manager: RustOpaque, cb: DartOpaque, -) -> anyhow::Result> { +) -> Result, DartOpaque> { let manager = MediaManagerHandle::clone(&manager); manager .on_device_change(unsafe { platform::Function::new(cb.try_unwrap().unwrap().into_raw().cast()) }) - .map_err(|err| anyhow::anyhow!("{:?}", DartError::from(err)))?; + .map_err(DartError::from)?; Ok(SyncReturn(())) } @@ -1197,13 +1195,14 @@ pub fn room_handle_disable_audio( /// If `source_kind` is not a [`MediaSourceKind`] index. /// /// [`Room`]: room::Room +#[must_use] pub fn room_handle_mute_video( room_handle: RustOpaque, source_kind: Option, -) -> anyhow::Result> { +) -> SyncReturn { let room_handle = RoomHandle::clone(&room_handle); - Ok(SyncReturn( + SyncReturn( async move { room_handle.mute_video(source_kind).await?; @@ -1211,7 +1210,7 @@ pub fn room_handle_mute_video( } .into_dart_future() .into_dart_opaque(), - )) + ) } /// Unmutes outbound video in the provided [`Room`]. @@ -1223,13 +1222,14 @@ pub fn room_handle_mute_video( /// If `source_kind` is not a [`MediaSourceKind`] index. /// /// [`Room`]: room::Room +#[must_use] pub fn room_handle_unmute_video( room_handle: RustOpaque, source_kind: Option, -) -> anyhow::Result> { +) -> SyncReturn { let room_handle = RoomHandle::clone(&room_handle); - Ok(SyncReturn( + SyncReturn( async move { room_handle.unmute_video(source_kind).await?; @@ -1237,7 +1237,7 @@ pub fn room_handle_unmute_video( } .into_dart_future() .into_dart_opaque(), - )) + ) } /// Enables outbound video in the provided [`Room`]. @@ -1249,13 +1249,14 @@ pub fn room_handle_unmute_video( /// If `source_kind` is not [`MediaSourceKind`] index. /// /// [`Room`]: room::Room +#[must_use] pub fn room_handle_enable_video( room_handle: RustOpaque, source_kind: Option, -) -> anyhow::Result> { +) -> SyncReturn { let room_handle = RoomHandle::clone(&room_handle); - Ok(SyncReturn( + SyncReturn( async move { room_handle.enable_video(source_kind).await?; @@ -1263,7 +1264,7 @@ pub fn room_handle_enable_video( } .into_dart_future() .into_dart_opaque(), - )) + ) } /// Disables outbound video in the provided [`Room`]. @@ -1275,13 +1276,14 @@ pub fn room_handle_enable_video( /// If `source_kind` is not [`MediaSourceKind`] index. /// /// [`Room`]: room::Room +#[must_use] pub fn room_handle_disable_video( room_handle: RustOpaque, source_kind: Option, -) -> anyhow::Result> { +) -> SyncReturn { let room_handle = RoomHandle::clone(&room_handle); - Ok(SyncReturn( + SyncReturn( async move { room_handle.disable_video(source_kind).await?; @@ -1289,7 +1291,7 @@ pub fn room_handle_disable_video( } .into_dart_future() .into_dart_opaque(), - )) + ) } /// Enables inbound audio in the provided [`Room`]. @@ -1341,13 +1343,14 @@ pub fn room_handle_disable_remote_audio( /// If `source_kind` is not [`MediaSourceKind`] index. /// /// [`Room`]: room::Room +#[must_use] pub fn room_handle_enable_remote_video( room_handle: RustOpaque, source_kind: Option, -) -> anyhow::Result> { +) -> SyncReturn { let room_handle = RoomHandle::clone(&room_handle); - Ok(SyncReturn( + SyncReturn( async move { room_handle.enable_remote_video(source_kind).await?; @@ -1355,7 +1358,7 @@ pub fn room_handle_enable_remote_video( } .into_dart_future() .into_dart_opaque(), - )) + ) } /// Disables inbound video in the provided [`Room`]. @@ -1367,13 +1370,14 @@ pub fn room_handle_enable_remote_video( /// If `source_kind` is not [`MediaSourceKind`] index. /// /// [`Room`]: room::Room +#[must_use] pub fn room_handle_disable_remote_video( room_handle: RustOpaque, source_kind: Option, -) -> anyhow::Result> { +) -> SyncReturn { let room_handle = RoomHandle::clone(&room_handle); - Ok(SyncReturn( + SyncReturn( async move { room_handle.disable_remote_video(source_kind).await?; @@ -1381,7 +1385,7 @@ pub fn room_handle_disable_remote_video( } .into_dart_future() .into_dart_opaque(), - )) + ) } /// Sets a callback to be invoked once a new [`Connection`] with some remote @@ -1395,7 +1399,7 @@ pub fn room_handle_disable_remote_video( pub fn room_handle_on_new_connection( room_handle: RustOpaque, cb: DartOpaque, -) -> anyhow::Result> { +) -> Result, DartOpaque> { Ok(SyncReturn( room_handle .on_new_connection(unsafe { @@ -1403,7 +1407,7 @@ pub fn room_handle_on_new_connection( cb.try_unwrap().unwrap().into_raw().cast(), ) }) - .map_err(|err| anyhow::anyhow!("{:?}", DartError::from(err)))?, + .map_err(DartError::from)?, )) } @@ -1418,12 +1422,12 @@ pub fn room_handle_on_new_connection( pub fn room_handle_on_close( room_handle: RustOpaque, cb: DartOpaque, -) -> anyhow::Result> { +) -> Result, DartOpaque> { room_handle .on_close(unsafe { platform::Function::new(cb.try_unwrap().unwrap().into_raw().cast()) }) - .map_err(|err| anyhow::anyhow!("{:?}", DartError::from(err)))?; + .map_err(DartError::from)?; Ok(SyncReturn(())) } @@ -1445,12 +1449,12 @@ pub fn room_handle_on_close( pub fn room_handle_on_local_track( room_handle: RustOpaque, cb: DartOpaque, -) -> anyhow::Result> { +) -> Result, DartOpaque> { room_handle .on_local_track(unsafe { platform::Function::new(cb.try_unwrap().unwrap().into_raw().cast()) }) - .map_err(|err| anyhow::anyhow!("{:?}", DartError::from(err)))?; + .map_err(DartError::from)?; Ok(SyncReturn(())) } @@ -1463,12 +1467,12 @@ pub fn room_handle_on_local_track( pub fn room_handle_on_connection_loss( room_handle: RustOpaque, cb: DartOpaque, -) -> anyhow::Result> { +) -> Result, DartOpaque> { room_handle .on_connection_loss(unsafe { platform::Function::new(cb.try_unwrap().unwrap().into_raw().cast()) }) - .map_err(|err| anyhow::anyhow!("{:?}", DartError::from(err)))?; + .map_err(DartError::from)?; Ok(SyncReturn(())) } @@ -1481,12 +1485,12 @@ pub fn room_handle_on_connection_loss( pub fn room_handle_on_failed_local_media( room_handle: RustOpaque, cb: DartOpaque, -) -> anyhow::Result> { +) -> Result, DartOpaque> { room_handle .on_failed_local_media(unsafe { platform::Function::new(cb.try_unwrap().unwrap().into_raw().cast()) }) - .map_err(|err| anyhow::anyhow!("{:?}", DartError::from(err)))?; + .map_err(DartError::from)?; Ok(SyncReturn(())) } diff --git a/src/api/dart/api_bridge_generated.rs b/src/api/dart/api_bridge_generated.rs index 6710d0e70..6e12da7d0 100644 --- a/src/api/dart/api_bridge_generated.rs +++ b/src/api/dart/api_bridge_generated.rs @@ -925,7 +925,10 @@ fn wire_room_handle_mute_video_impl( move || { let api_room_handle = room_handle.wire2api(); let api_source_kind = source_kind.wire2api(); - room_handle_mute_video(api_room_handle, api_source_kind) + Result::<_, ()>::Ok(room_handle_mute_video( + api_room_handle, + api_source_kind, + )) }, ) } @@ -942,7 +945,10 @@ fn wire_room_handle_unmute_video_impl( move || { let api_room_handle = room_handle.wire2api(); let api_source_kind = source_kind.wire2api(); - room_handle_unmute_video(api_room_handle, api_source_kind) + Result::<_, ()>::Ok(room_handle_unmute_video( + api_room_handle, + api_source_kind, + )) }, ) } @@ -959,7 +965,10 @@ fn wire_room_handle_enable_video_impl( move || { let api_room_handle = room_handle.wire2api(); let api_source_kind = source_kind.wire2api(); - room_handle_enable_video(api_room_handle, api_source_kind) + Result::<_, ()>::Ok(room_handle_enable_video( + api_room_handle, + api_source_kind, + )) }, ) } @@ -976,7 +985,10 @@ fn wire_room_handle_disable_video_impl( move || { let api_room_handle = room_handle.wire2api(); let api_source_kind = source_kind.wire2api(); - room_handle_disable_video(api_room_handle, api_source_kind) + Result::<_, ()>::Ok(room_handle_disable_video( + api_room_handle, + api_source_kind, + )) }, ) } @@ -1027,7 +1039,10 @@ fn wire_room_handle_enable_remote_video_impl( move || { let api_room_handle = room_handle.wire2api(); let api_source_kind = source_kind.wire2api(); - room_handle_enable_remote_video(api_room_handle, api_source_kind) + Result::<_, ()>::Ok(room_handle_enable_remote_video( + api_room_handle, + api_source_kind, + )) }, ) } @@ -1044,7 +1059,10 @@ fn wire_room_handle_disable_remote_video_impl( move || { let api_room_handle = room_handle.wire2api(); let api_source_kind = source_kind.wire2api(); - room_handle_disable_remote_video(api_room_handle, api_source_kind) + Result::<_, ()>::Ok(room_handle_disable_remote_video( + api_room_handle, + api_source_kind, + )) }, ) } diff --git a/src/api/dart/utils/err.rs b/src/api/dart/utils/err.rs index 6ab42b582..f322c7948 100644 --- a/src/api/dart/utils/err.rs +++ b/src/api/dart/utils/err.rs @@ -4,6 +4,7 @@ use std::ptr; use dart_sys::Dart_Handle; use derive_more::Into; +use flutter_rust_bridge::DartOpaque; use medea_macro::dart_bridge; use crate::{ @@ -137,6 +138,12 @@ impl DartError { } } +impl From for DartOpaque { + fn from(val: DartError) -> Self { + unsafe { Self::new_non_droppable(*Box::from_raw(val.0.as_ptr())) } + } +} + impl From for DartError { fn from(err: platform::Error) -> Self { Self::new(err.get_handle())