Skip to content

Commit

Permalink
Fix connection loss E2E tests on Web (#128)
Browse files Browse the repository at this point in the history
Co-authored-by: alexlapa <[email protected]>
  • Loading branch information
rogurotus and alexlapa authored Dec 5, 2023
1 parent 116a5fb commit 7387cf4
Show file tree
Hide file tree
Showing 18 changed files with 316 additions and 473 deletions.
29 changes: 13 additions & 16 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
10 changes: 3 additions & 7 deletions e2e/src/browser/mock/websocket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions e2e/tests/features/state_synchronization.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
6 changes: 5 additions & 1 deletion e2e/tests/steps/websocket.rs
Original file line number Diff line number Diff line change
@@ -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$")]
Expand Down
10 changes: 5 additions & 5 deletions flutter/example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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"
2 changes: 1 addition & 1 deletion flutter/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
72 changes: 19 additions & 53 deletions flutter/lib/src/native/connection_handle.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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
Expand All @@ -75,41 +57,25 @@ class NativeConnectionHandle implements ConnectionHandle {

@override
Future<void> 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<void> 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<void> 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<void> 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);
}
}
Loading

0 comments on commit 7387cf4

Please sign in to comment.