Skip to content
This repository has been archived by the owner on Aug 25, 2021. It is now read-only.

Commit

Permalink
Prepare Jason's error handling for mobile platform support (#184, #182)
Browse files Browse the repository at this point in the history
- move JasonError to the api::wasm
- get rid of HandlerDetachedError
  • Loading branch information
evdokimovs authored Mar 10, 2021
1 parent e580a72 commit 1ff5d5f
Show file tree
Hide file tree
Showing 23 changed files with 732 additions and 512 deletions.
330 changes: 130 additions & 200 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ down.medea: docker.down.medea

up.control:
cargo build -p medea-control-api-mock
make wait.port port=6565
cargo run -p medea-control-api-mock $(if $(call eq,$(background),yes),&,)


Expand Down
4 changes: 3 additions & 1 deletion jason/src/api/wasm/constraints_update_exception.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ use std::iter::FromIterator as _;
use derive_more::From;
use wasm_bindgen::prelude::*;

use crate::{api::JasonError, room};
use crate::room;

use super::JasonError;

/// Exception returned from [`RoomHandle::set_local_media_settings()`][1].
///
Expand Down
63 changes: 54 additions & 9 deletions jason/src/api/wasm/jason_error.rs
Original file line number Diff line number Diff line change
@@ -1,36 +1,81 @@
//! App error exported to JS side.
use derive_more::From;
use std::fmt::{Debug, Display};

use derive_more::{Display, From};
use tracerr::{Trace, Traced};
use wasm_bindgen::prelude::*;

use crate::utils;
use crate::{platform, utils::JsCaused};

/// Representation of an app error exported to JS side.
///
/// Contains JS side error if it's the cause, and a trace information.
#[wasm_bindgen]
#[derive(From)]
pub struct JasonError(utils::JasonError);
#[derive(From, Clone, Debug, Display)]
#[display(fmt = "{}: {}\n{}", name, message, trace)]
pub struct JasonError {
/// Name of this [`JasonError`].
name: &'static str,

/// Message describing this [`JasonError`].
message: String,

/// [`Trace`] information of this [`JasonError`].
trace: Trace,

/// Optional cause of this [`JasonError`] as a JS side error.
source: Option<platform::Error>,
}

#[wasm_bindgen]
impl JasonError {
/// Returns a name of this error.
#[must_use]
pub fn name(&self) -> String {
self.0.name()
self.name.to_owned()
}

/// Returns a message of this errors.
/// Returns a message of this error.
#[must_use]
pub fn message(&self) -> String {
self.0.message()
self.message.clone()
}

/// Returns a trace information of this error.
#[must_use]
pub fn trace(&self) -> String {
self.0.trace()
self.trace.to_string()
}

/// Returns a JS side error if it's the cause.
#[must_use]
pub fn source(&self) -> Option<js_sys::Error> {
self.0.source().and_then(|a| a.sys_cause)
self.source.clone().and_then(|e| e.sys_cause)
}
}

impl<E: JsCaused + Display> From<(E, Trace)> for JasonError
where
E::Error: Into<platform::Error>,
{
#[inline]
fn from((err, trace): (E, Trace)) -> Self {
Self {
name: err.name(),
message: err.to_string(),
trace,
source: err.js_cause().map(Into::into),
}
}
}

impl<E: JsCaused + Display> From<Traced<E>> for JasonError
where
E::Error: Into<platform::Error>,
{
#[inline]
fn from(traced: Traced<E>) -> Self {
Self::from(traced.into_parts())
}
}
4 changes: 3 additions & 1 deletion jason/src/api/wasm/media_manager_handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ use wasm_bindgen::prelude::*;
use wasm_bindgen_futures::future_to_promise;

use crate::{
api::{InputDeviceInfo, JasonError, LocalMediaTrack, MediaStreamSettings},
api::{InputDeviceInfo, LocalMediaTrack, MediaStreamSettings},
media,
};

use super::JasonError;

/// [`MediaManagerHandle`] is a weak reference to a [`MediaManager`].
///
/// [`MediaManager`] performs all the media acquisition requests
Expand Down
2 changes: 2 additions & 0 deletions jason/src/api/wasm/media_stream_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ impl AudioTrackConstraints {
#[derive(From, Into)]
pub struct DeviceVideoTrackConstraints(media::DeviceVideoTrackConstraints);

/// Constraints applicable to video tracks that are sourced from a screen
/// capturing.
#[wasm_bindgen]
impl DeviceVideoTrackConstraints {
/// Creates new [`DeviceVideoTrackConstraints`] with none constraints
Expand Down
8 changes: 5 additions & 3 deletions jason/src/api/wasm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
//!
//! [`Jason`]: crate::api::Jason
use derive_more::Display;
use wasm_bindgen::prelude::*;

pub mod connection_handle;
pub mod constraints_update_exception;
pub mod input_device_info;
Expand All @@ -19,6 +16,11 @@ pub mod remote_media_track;
pub mod room_close_reason;
pub mod room_handle;

use derive_more::Display;
use wasm_bindgen::prelude::*;

pub use self::jason_error::JasonError;

/// [MediaStreamTrack.kind][1] representation.
///
/// [1]: https://w3.org/TR/mediacapture-streams/#dom-mediastreamtrack-kind
Expand Down
4 changes: 3 additions & 1 deletion jason/src/api/wasm/reconnect_handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ use js_sys::Promise;
use wasm_bindgen::prelude::*;
use wasm_bindgen_futures::future_to_promise;

use crate::{api::JasonError, rpc};
use crate::rpc;

use super::JasonError;

/// Handle that JS side can reconnect to a media server with when a connection
/// is lost.
Expand Down
87 changes: 83 additions & 4 deletions jason/src/api/wasm/room_handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ use wasm_bindgen::{prelude::*, JsValue};
use wasm_bindgen_futures::future_to_promise;

use crate::{
api::{
ConstraintsUpdateException, JasonError, MediaSourceKind,
MediaStreamSettings,
},
api::{ConstraintsUpdateException, MediaSourceKind, MediaStreamSettings},
room,
};

use super::JasonError;

/// JS side handle to a [`Room`] where all the media happens.
///
/// Like all handles it contains a weak reference to the object that is managed
Expand Down Expand Up @@ -171,6 +170,12 @@ impl RoomHandle {

/// Mutes outbound audio in this [`Room`].
///
/// # Errors
///
/// With `name = 'MediaConnections'` if [`RoomHandle::unmute_audio()`] was
/// called while muting or a media server didn't approve this state
/// transition.
///
/// [`Room`]: room::Room
pub fn mute_audio(&self) -> Promise {
let this = self.0.clone();
Expand All @@ -183,6 +188,12 @@ impl RoomHandle {

/// Unmutes outbound audio in this [`Room`].
///
/// # Errors
///
/// With `name = 'MediaConnections'` if [`RoomHandle::mute_audio()`] was
/// called while unmuting or a media server didn't approve this state
/// transition.
///
/// [`Room`]: room::Room
pub fn unmute_audio(&self) -> Promise {
let this = self.0.clone();
Expand All @@ -195,6 +206,12 @@ impl RoomHandle {

/// Mutes outbound video in this [`Room`].
///
/// # Errors
///
/// With `name = 'MediaConnections'` if [`RoomHandle::unmute_video()`] was
/// called while muting or a media server didn't approve this state
/// transition.
///
/// [`Room`]: room::Room
pub fn mute_video(&self, source_kind: Option<MediaSourceKind>) -> Promise {
let this = self.0.clone();
Expand All @@ -209,6 +226,12 @@ impl RoomHandle {

/// Unmutes outbound video in this [`Room`].
///
/// # Errors
///
/// With `name = 'MediaConnections'` if [`RoomHandle::mute_video()`] was
/// called while unmuting or a media server didn't approve this state
/// transition.
///
/// [`Room`]: room::Room
pub fn unmute_video(
&self,
Expand All @@ -226,6 +249,13 @@ impl RoomHandle {

/// Disables outbound audio in this [`Room`].
///
/// # Errors
///
/// With `name = 'MediaConnections'` if the target sender is configured as
/// `required` by a media server or [`RoomHandle::enable_audio()`] was
/// called while disabling or a media server didn't approve this state
/// transition.
///
/// [`Room`]: room::Room
pub fn disable_audio(&self) -> Promise {
let this = self.0.clone();
Expand All @@ -238,6 +268,15 @@ impl RoomHandle {

/// Enables outbound audio in this [`Room`].
///
/// # Errors
///
/// With `name = 'MediaConnections'` if [`RoomHandle::disable_audio()`] was
/// called while enabling or a media server didn't approve this state
/// transition.
///
/// With `name = 'MediaManagerError'` if media acquisition request to User
/// Agent failed.
///
/// [`Room`]: room::Room
pub fn enable_audio(&self) -> Promise {
let this = self.0.clone();
Expand All @@ -251,6 +290,13 @@ impl RoomHandle {
/// Disables outbound video.
///
/// Affects only video with a specific [`MediaSourceKind`] if specified.
///
/// # Errors
///
/// With `name = 'MediaConnections'` if the target sender is configured as
/// `required` by a media server or [`RoomHandle::enable_video()`] was
/// called while disabling or a media server didn't approve this state
/// transition.
pub fn disable_video(
&self,
source_kind: Option<MediaSourceKind>,
Expand All @@ -269,6 +315,15 @@ impl RoomHandle {
/// Enables outbound video.
///
/// Affects only video with a specific [`MediaSourceKind`] if specified.
///
/// # Errors
///
/// With `name = 'MediaConnections'` if [`RoomHandle::disable_video()`] was
/// called while enabling or a media server didn't approve this state
/// transition.
///
/// With `name = 'MediaManagerError'` if media acquisition request to User
/// Agent failed.
pub fn enable_video(
&self,
source_kind: Option<MediaSourceKind>,
Expand All @@ -285,6 +340,12 @@ impl RoomHandle {

/// Disables inbound audio in this [`Room`].
///
/// # Errors
///
/// With `name = 'MediaConnections'` if
/// [`RoomHandle::enable_remote_audio()`] was called while disabling or a
/// media server didn't approve this state transition.
///
/// [`Room`]: room::Room
pub fn disable_remote_audio(&self) -> Promise {
let this = self.0.clone();
Expand All @@ -299,6 +360,12 @@ impl RoomHandle {

/// Disables inbound video in this [`Room`].
///
/// # Errors
///
/// With `name = 'MediaConnections'` if
/// [`RoomHandle::enable_remote_video()`] was called while disabling or
/// a media server didn't approve this state transition.
///
/// [`Room`]: room::Room
pub fn disable_remote_video(&self) -> Promise {
let this = self.0.clone();
Expand All @@ -313,6 +380,12 @@ impl RoomHandle {

/// Enables inbound audio in this [`Room`].
///
/// # Errors
///
/// With `name = 'MediaConnections'` if
/// [`RoomHandle::disable_remote_audio()`] was called while enabling or a
/// media server didn't approve this state transition.
///
/// [`Room`]: room::Room
pub fn enable_remote_audio(&self) -> Promise {
let this = self.0.clone();
Expand All @@ -325,6 +398,12 @@ impl RoomHandle {

/// Enables inbound video in this [`Room`].
///
/// # Errors
///
/// With `name = 'MediaConnections'` if
/// [`RoomHandle::disable_remote_video()`] was called while enabling or a
/// media server didn't approve this state transition.
///
/// [`Room`]: room::Room
pub fn enable_remote_video(&self) -> Promise {
let this = self.0.clone();
Expand Down
Loading

0 comments on commit 1ff5d5f

Please sign in to comment.