Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add RemoteMediaTrack.onMediaDirectionChanged() (#42) #46

Merged
merged 31 commits into from
Apr 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
d3b2d2b
Impl
evdokimovs Apr 13, 2022
84c6bfb
Refactor
evdokimovs Apr 13, 2022
7a40b78
Add current MediaDirection returning
evdokimovs Apr 13, 2022
fbe3588
Add tests for MediaDirection
evdokimovs Apr 13, 2022
329ab1c
Fix MediaDirection update
evdokimovs Apr 14, 2022
fa0dbad
Merge branch 'master' into add-media-exchange-direction
evdokimovs Apr 14, 2022
924174f
Rebuild all
evdokimovs Apr 14, 2022
343bbcc
try refactor, maybe revert
alexlapa Apr 18, 2022
ca493d6
WIP
evdokimovs Apr 18, 2022
79bdcfc
Minor fixes, rebuild
evdokimovs Apr 18, 2022
8a0574d
Just testing
evdokimovs Apr 19, 2022
641254b
Minor
evdokimovs Apr 19, 2022
f037c12
Minor
evdokimovs Apr 19, 2022
3f61303
Minor E2E fix
evdokimovs Apr 19, 2022
3e20693
Minor E2E fix
evdokimovs Apr 19, 2022
2e509c5
Minor
evdokimovs Apr 19, 2022
6070776
Minor
evdokimovs Apr 20, 2022
33fa1dc
Minor upd
evdokimovs Apr 20, 2022
f77abaa
Minor refactor
evdokimovs Apr 20, 2022
f7acffc
Merge branch 'master' into add-media-exchange-direction
evdokimovs Apr 20, 2022
1ba721c
Rebuild all
evdokimovs Apr 20, 2022
22edfa5
Fix flutter_webrtc
evdokimovs Apr 20, 2022
fcf1fa3
Fix unit tests
evdokimovs Apr 20, 2022
81c2815
Minor fix unit
evdokimovs Apr 20, 2022
3ae5abf
corrections
alexlapa Apr 25, 2022
9fc1d66
corrections
alexlapa Apr 25, 2022
275fce3
corrections
alexlapa Apr 26, 2022
f6f511c
Compile windows
logist322 Apr 26, 2022
84c1ba4
Corrections
tyranron Apr 26, 2022
706f17a
Mention in CHANGELOG
tyranron Apr 26, 2022
c31d604
fix e2e tests
alexlapa Apr 26, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ concurrency:
cancel-in-progress: true

env:
MEDEA_BRANCH: edge # for E2E tests only
MEDEA_BRANCH: add-media-exchange-direction # for E2E tests only
Copy link
Contributor

@alexlapa alexlapa Apr 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tyranron ,

Это я в следующем PR'е ревертну, после слива соответсвующей задачи в instrumentisto/medea.

RUST_BACKTRACE: 1

jobs:
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ All user visible changes to this project will be documented in this file. This p
- `InternalException`;
- `LocalMediaInitException`.
- Renamed `InputDeviceInfo` object to `MediaDeviceInfo` ([#29]).
- `RemoteMediaTrack`:
- Replaced `on_enabled` and `on_disabled` callbacks with `on_media_direction_changed` callback ([#46]);
- Replaced `enabled` method with `media_direction` method ([#46]).

### Added

Expand All @@ -65,6 +68,7 @@ All user visible changes to this project will be documented in this file. This p
- `disable_remote_video`;
- `enable_remote_audio`;
- `disable_remote_audio`.
- `MediaDirection` type ([#46]).

### Updated

Expand All @@ -76,6 +80,7 @@ All user visible changes to this project will be documented in this file. This p
[#29]: /../../pull/29
[#30]: /../../pull/30
[#43]: /../../pull/43
[#46]: /../../pull/46



Expand Down
3 changes: 3 additions & 0 deletions e2e-demo/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,9 @@ window.onload = async function() {

connection.on_remote_track_added((track) => {
let playElement = undefined;
track.on_media_direction_changed((direction) => {
console.log('New TransceiverDirection: ' + direction);
});
if (track.kind() === rust.MediaKind.Video) {
if (track.media_source_kind() === rust.MediaSourceKind.Display) {
playElement = memberVideoDiv.getElementsByClassName('display-video')[0];
Expand Down
151 changes: 104 additions & 47 deletions e2e/src/object/remote_track.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,23 @@ use crate::{browser::Statement, object::Object};

use super::Error;

/// Media exchange direction of a `RemoteMediaTrack`.
#[derive(Clone, Copy, Debug)]
#[repr(u8)]
pub enum MediaDirection {
/// `RemoteMediaTrack` is enabled on both receiver and sender sides.
SendRecv = 0,

/// `RemoteMediaTrack` is enabled on sender side only.
SendOnly = 1,

/// `RemoteMediaTrack` is enabled on receiver side only.
RecvOnly = 2,

/// `RemoteMediaTrack` is disabled on both sides.
Inactive = 3,
}

/// Representation of a `RemoteMediaTrack` object.
#[derive(Clone, Copy, Debug)]
pub struct RemoteTrack;
Expand All @@ -19,7 +36,8 @@ impl Object<RemoteTrack> {
// language=JavaScript
r#"
async (track) => {
if (!track.track.enabled()) {
const currentDirection = track.track.media_direction()
if (currentDirection != 0) {
let waiter = new Promise((resolve) => {
track.onEnabledSubs.push(resolve);
});
Expand All @@ -44,7 +62,8 @@ impl Object<RemoteTrack> {
// language=JavaScript
r#"
async (track) => {
if (track.track.enabled()) {
const currentDirection = track.track.media_direction()
if (currentDirection == 0) {
let waiter = new Promise((resolve) => {
track.onDisabledSubs.push(resolve);
});
Expand All @@ -67,7 +86,12 @@ impl Object<RemoteTrack> {
pub async fn disabled(&self) -> Result<bool, Error> {
self.execute(Statement::new(
// language=JavaScript
r#"async (t) => !t.track.get_track().enabled"#,
r#"
async (t) => {
const currentDirection = t.track.media_direction();
return currentDirection != 0;
}
"#,
[],
))
.await?
Expand All @@ -88,18 +112,18 @@ impl Object<RemoteTrack> {
self.execute(Statement::new(
// language=JavaScript
r#"
async (track) => {
const [count] = args;
while (track.on_disabled_fire_count !== count) {
await new Promise((resolve) => {
if (track.on_disabled_fire_count !== count) {
track.onDisabledSubs.push(resolve);
} else {
resolve();
}
});
}
async (track) => {
const [count] = args;
while (track.on_disabled_fire_count !== count) {
await new Promise((resolve) => {
if (track.on_disabled_fire_count !== count) {
track.onDisabledSubs.push(resolve);
} else {
resolve();
}
});
}
}
"#,
[count.into()],
))
Expand All @@ -120,18 +144,18 @@ impl Object<RemoteTrack> {
self.execute(Statement::new(
// language=JavaScript
r#"
async (track) => {
const [count] = args;
while (track.on_enabled_fire_count !== count) {
await new Promise((resolve) => {
if (track.on_enabled_fire_count !== count) {
track.onEnabledSubs.push(resolve);
} else {
resolve();
}
});
}
async (track) => {
const [count] = args;
while (track.on_enabled_fire_count !== count) {
await new Promise((resolve) => {
if (track.on_enabled_fire_count !== count) {
track.onEnabledSubs.push(resolve);
} else {
resolve();
}
});
}
}
"#,
[count.into()],
))
Expand All @@ -152,18 +176,18 @@ impl Object<RemoteTrack> {
self.execute(Statement::new(
// language=JavaScript
r#"
async (track) => {
const [count] = args;
while (track.on_muted_fire_count !== count) {
await new Promise((resolve) => {
if (track.on_muted_fire_count !== count) {
track.onMutedSubs.push(resolve);
} else {
resolve();
}
});
}
async (track) => {
const [count] = args;
while (track.on_muted_fire_count !== count) {
await new Promise((resolve) => {
if (track.on_muted_fire_count !== count) {
track.onMutedSubs.push(resolve);
} else {
resolve();
}
});
}
}
"#,
[count.into()],
))
Expand All @@ -184,22 +208,55 @@ impl Object<RemoteTrack> {
self.execute(Statement::new(
// language=JavaScript
r#"
async (track) => {
const [count] = args;
while (track.on_unmuted_fire_count !== count) {
await new Promise((resolve) => {
if (track.on_unmuted_fire_count !== count) {
track.onUnmutedSubs.push(resolve);
} else {
resolve();
}
});
}
async (track) => {
const [count] = args;
while (track.on_unmuted_fire_count !== count) {
await new Promise((resolve) => {
if (track.on_unmuted_fire_count !== count) {
track.onUnmutedSubs.push(resolve);
} else {
resolve();
}
});
}
}
"#,
[count.into()],
))
.await
.map(drop)
}

/// Waits for the `RemoteMediaTrack.on_media_direction` with the provided
/// [`MediaDirection`].
///
/// # Errors
///
/// If failed to execute JS statement.
pub async fn wait_for_media_direction(
&self,
direction: MediaDirection,
) -> Result<(), Error> {
self.execute(Statement::new(
// language=JavaScript
r#"
async (track) => {
const [direction] = args;
if (track.track.media_direction() != direction) {
let waiter = new Promise((resolve) => {
track.onMediaDirectionChangedSubs.push((dir) => {
if (dir == direction) {
resolve();
}
});
});
await waiter;
}
}
"#,
[(direction as u8).into()],
))
.await
.map(drop)
}
}
Loading