Skip to main content

MediaSession

Struct MediaSession 

Source
pub struct MediaSession {
    core: SfuCore,
    room: Arc<Room>,
    transport_user_key: TransportSessionKey,
    phase: SessionPhase,
    closed: bool,
}
Expand description

One admitted user connection in one room.

Room mutations revalidate the connection before committing room state. close cannot remove a replacement connection and drains connection-scoped staged media when this session is current.

Futures returned by establish, answer, publish, deactivate_publication, renegotiate, subscribe, update_info and close are not cancellation safe. Once polled, await them to completion. Negotiation can otherwise leave room and transport state out of step with the local phase. Other mutations can leave committed room state without its transport or output effects.

Call close before dropping the session. Drop performs no room or transport cleanup.

Fields§

§core: SfuCore§room: Arc<Room>§transport_user_key: TransportSessionKey§phase: SessionPhase§closed: bool

Implementations§

Source§

impl MediaSession

Source

pub async fn establish( &mut self, ) -> Result<Option<NegotiationOffer>, SessionError>

creates the first browser offer for this connection

returns Ok(None) after the initial offer has already been requested this lets reconnect or duplicate-start paths retry safely without creating a second initial offer

§Errors

returns SessionError::Core when the transport cannot create the initial offer

Source

pub async fn answer( &mut self, sdp: &str, ) -> Result<Option<NegotiationOffer>, SessionError>

accepts the answer for the pending offer and commits any ready room work

a rejection before the worker consumes its pending offer leaves the application round in place so a direct caller may retry it failures after the worker consumes that offer do not promise retry even when the RTC backend rejects the answer when queued publish intent needs another SDP round the returned offer must be sent to the client before the next answer

§Errors

returns SessionError::NoPendingRequest when no offer is pending returns SessionError::Core when answer application fails, capability projection fails or room state rejects the accepted answer as stale

Source

pub async fn publish( &mut self, intent: SourcePublishIntent, ) -> Result<Option<NegotiationOffer>, SessionError>

applies publish intent for one user stream

returns no offer when the intent is already queued, already active or must wait for an in-flight answer returns an offer when the browser must answer a new offer before the publication can commit

§Errors

returns SessionError::Core when the media backend cannot stage a publish that needs negotiation

Source

pub async fn deactivate_publication(&mut self, intent: SourceDeactivateIntent)

deactivates one publication without changing negotiated media

a queued first publication is cancelled a staged first publication is rolled back and its pending answer creates the cleanup offer a committed publication keeps its source identity, routes and negotiated MID until session teardown

Source

pub async fn close(&mut self) -> bool

closes this media session and removes its room connection if still current

the call is idempotent it returns true only when the room manager removed the current connection current-session cleanup drains connection-scoped staged media through room state stale sessions do not remove a replacement connection for the same user

Source

pub async fn renegotiate( &mut self, ) -> Result<Option<NegotiationOffer>, SessionError>

creates a refresh offer when the stable session needs renegotiation

returns Ok(None) before the initial offer, while an answer is pending or when the transport reports that the requested refresh is unsupported a call made while an answer is pending records that another offer should be created after the answer commits

§Errors

returns SessionError::Core when the transport rejects renegotiation

Source

pub async fn subscribe( &self, target_user_id: &UserId, intents: &BTreeMap<UserStreamId, SourceSubscriptionIntent>, ) -> Result<(), SessionError>

applies receiver intent for sources published by another user

subscription intent is remembered even when no producer is currently routable once negotiation makes the receiver consumable, room effects create the missing consumer routes

§Errors

returns SessionError::Core when room state rejects this connection as stale

Source

pub fn endpoint_health(&self) -> Option<TransportSessionHealth>

returns None when the transport has no endpoint for this session key

Source

pub fn user_id(&self) -> &UserId

Source

pub const fn connection_id(&self) -> ConnectionId

Source

pub fn room_id(&self) -> &str

Source

pub async fn is_current_connection(&self) -> bool

Source

pub fn available_features(&self) -> AvailableFeatures

Source

pub async fn recording_state(&self) -> RecordingState

Source

pub async fn peer_snapshots(&self) -> Vec<PeerSnapshot>

Returns snapshots for current room users other than this session’s user.

Source

fn room_operation(&self) -> RoomUserOperation<'_>

Source

async fn start_publish( &self, intent: &SourcePublishIntent, can_stage: bool, ) -> Result<PublishIntentOutcome, SfuCoreError>

Source

pub async fn update_info(&self, info: UserInfo)

Updates user information for this room connection.

Missing or stale connections are ignored. is_camera_on and is_screen_sharing_on are derived from publication state and discarded from info.

Source

pub async fn broadcast( &self, message: JsonPayload, ) -> Result<(), BroadcastPayloadError>

Broadcasts message to every other current room user.

Missing or stale sender connections return Ok(()) without delivery.

§Errors

Returns BroadcastPayloadError::TooLarge when the serialized payload exceeds the room broadcast limit. Returns BroadcastPayloadError::JsonSerialization when JSON serialization fails.

Source

pub async fn start_recording(&self, options: RecordingOptions) -> bool

Rejects recording start because no persistent recording backend is enabled.

options has no effect. The request records a rejection and returns false.

Source

pub async fn stop_recording(&self) -> bool

Rejects recording stop because no persistent recording backend is enabled.

The request records a rejection and returns false.

Source

async fn stage_queued_publishes( &self, queued: BTreeMap<UserStreamId, SourcePublishIntent>, ) -> Result<bool, SessionError>

Trait Implementations§

Source§

impl Debug for MediaSession

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> FutureExt for T

§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<T> CryptoSafe for T
where T: Send + Sync + Debug,

§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,