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: boolImplementations§
Source§impl MediaSession
impl MediaSession
Sourcepub async fn establish(
&mut self,
) -> Result<Option<NegotiationOffer>, SessionError>
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
Sourcepub async fn answer(
&mut self,
sdp: &str,
) -> Result<Option<NegotiationOffer>, SessionError>
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
Sourcepub async fn publish(
&mut self,
intent: SourcePublishIntent,
) -> Result<Option<NegotiationOffer>, SessionError>
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
Sourcepub async fn deactivate_publication(&mut self, intent: SourceDeactivateIntent)
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
Sourcepub async fn close(&mut self) -> bool
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
Sourcepub async fn renegotiate(
&mut self,
) -> Result<Option<NegotiationOffer>, SessionError>
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
Sourcepub async fn subscribe(
&self,
target_user_id: &UserId,
intents: &BTreeMap<UserStreamId, SourceSubscriptionIntent>,
) -> Result<(), SessionError>
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
Sourcepub fn endpoint_health(&self) -> Option<TransportSessionHealth>
pub fn endpoint_health(&self) -> Option<TransportSessionHealth>
returns None when the transport has no endpoint for this session key
pub fn user_id(&self) -> &UserId
pub const fn connection_id(&self) -> ConnectionId
pub fn room_id(&self) -> &str
pub async fn is_current_connection(&self) -> bool
pub fn available_features(&self) -> AvailableFeatures
pub async fn recording_state(&self) -> RecordingState
Sourcepub async fn peer_snapshots(&self) -> Vec<PeerSnapshot>
pub async fn peer_snapshots(&self) -> Vec<PeerSnapshot>
Returns snapshots for current room users other than this session’s user.
fn room_operation(&self) -> RoomUserOperation<'_>
async fn start_publish( &self, intent: &SourcePublishIntent, can_stage: bool, ) -> Result<PublishIntentOutcome, SfuCoreError>
Sourcepub async fn update_info(&self, info: UserInfo)
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.
Sourcepub async fn broadcast(
&self,
message: JsonPayload,
) -> Result<(), BroadcastPayloadError>
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.
Sourcepub async fn start_recording(&self, options: RecordingOptions) -> bool
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.
Sourcepub async fn stop_recording(&self) -> bool
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.
async fn stage_queued_publishes( &self, queued: BTreeMap<UserStreamId, SourcePublishIntent>, ) -> Result<bool, SessionError>
Trait Implementations§
Auto Trait Implementations§
impl Freeze for MediaSession
impl !RefUnwindSafe for MediaSession
impl Send for MediaSession
impl Sync for MediaSession
impl Unpin for MediaSession
impl UnsafeUnpin for MediaSession
impl !UnwindSafe for MediaSession
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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