pub struct ServerInviteDialog { /* private fields */ }Expand description
Server-side INVITE Dialog (UAS)
ServerInviteDialog represents a server-side INVITE dialog in SIP. This is used
when the local user agent acts as a User Agent Server (UAS) and receives
an INVITE transaction from a remote party to establish a session.
§Key Features
- Session Acceptance - Accepts or rejects incoming INVITE requests
- In-dialog Requests - Handles UPDATE, INFO, OPTIONS within established dialogs
- Session Termination - Handles BYE for ending sessions
- Re-INVITE Support - Supports session modification via re-INVITE
- ACK Handling - Properly handles ACK for 2xx responses
- State Management - Tracks dialog state transitions
§Dialog Lifecycle
- Creation - Dialog created when receiving INVITE
- Processing - Can send provisional responses (1xx)
- Decision - Accept (2xx) or reject (3xx-6xx) the INVITE
- Wait ACK - If accepted, wait for ACK from client
- Confirmed - ACK received, dialog established
- Active - Can handle in-dialog requests
- Termination - Receives BYE or sends BYE to end session
§Examples
§Basic Call Handling
// After receiving INVITE:
// Accept the call
dialog.accept(None, Some(answer_sdp))?;
// Or reject the call
dialog.reject(None, None)?;// End an established call
dialog.bye().await?;§Session Modification
// Send re-INVITE to modify session
let headers = vec![
rsip::Header::ContentType("application/sdp".into())
];
let response = dialog.reinvite(Some(headers), Some(new_sdp)).await?;§Thread Safety
ServerInviteDialog is thread-safe and can be cloned and shared across tasks. All operations are atomic and properly synchronized.
Implementations§
Source§impl ServerInviteDialog
impl ServerInviteDialog
Sourcepub fn id(&self) -> DialogId
pub fn id(&self) -> DialogId
Get the dialog identifier
Returns the unique DialogId that identifies this dialog instance. The DialogId consists of Call-ID, from-tag, and to-tag.
pub fn state(&self) -> DialogState
Sourcepub fn cancel_token(&self) -> &CancellationToken
pub fn cancel_token(&self) -> &CancellationToken
Get the cancellation token for this dialog
Returns a reference to the CancellationToken that can be used to cancel ongoing operations for this dialog.
Sourcepub fn initial_request(&self) -> Request
pub fn initial_request(&self) -> Request
Get the initial INVITE request
Returns a reference to the initial INVITE request that created this dialog. This can be used to access the original request headers, body, and other information.
pub fn ringing( &self, headers: Option<Vec<Header>>, body: Option<Vec<u8>>, ) -> Result<()>
Sourcepub fn accept(
&self,
headers: Option<Vec<Header>>,
body: Option<Vec<u8>>,
) -> Result<()>
pub fn accept( &self, headers: Option<Vec<Header>>, body: Option<Vec<u8>>, ) -> Result<()>
Accept the incoming INVITE request
Sends a 200 OK response to accept the incoming INVITE request. This establishes the dialog and transitions it to the WaitAck state, waiting for the ACK from the client.
§Parameters
headers- Optional additional headers to include in the responsebody- Optional message body (typically SDP answer)
§Returns
Ok(())- Response sent successfullyErr(Error)- Failed to send response or transaction terminated
§Examples
// Accept with SDP answer
let answer_sdp = b"v=0\r\no=- 123 456 IN IP4 192.168.1.1\r\n...";
let headers = vec![
rsip::Header::ContentType("application/sdp".into())
];
dialog.accept(Some(headers), Some(answer_sdp.to_vec()))?;Sourcepub fn accept_with_public_contact(
&self,
username: &str,
public_address: Option<HostWithPort>,
local_address: &SipAddr,
headers: Option<Vec<Header>>,
body: Option<Vec<u8>>,
) -> Result<()>
pub fn accept_with_public_contact( &self, username: &str, public_address: Option<HostWithPort>, local_address: &SipAddr, headers: Option<Vec<Header>>, body: Option<Vec<u8>>, ) -> Result<()>
Accept the incoming INVITE request with NAT-aware Contact header
Sends a 200 OK response to accept the incoming INVITE request, automatically adding a Contact header with the provided public address for proper NAT traversal. This is the recommended method when working with NAT environments.
§Parameters
username- SIP username for the Contact headerpublic_address- Optional public address discovered via registrationlocal_address- Local SIP address as fallbackheaders- Optional additional headers to includebody- Optional SDP answer body
§Returns
Ok(())- Response sent successfullyErr(Error)- Failed to send response or transaction terminated
§Examples
let public_addr = Some(rsip::HostWithPort {
host: IpAddr::V4(Ipv4Addr::new(203, 0, 113, 1)).into(),
port: Some(5060.into()),
});
let answer_sdp = b"v=0\r\no=- 123 456 IN IP4 203.0.113.1\r\n...";
let headers = vec![
rsip::Header::ContentType("application/sdp".into())
];
dialog.accept_with_public_contact(
"alice",
public_addr,
&local_addr,
Some(headers),
Some(answer_sdp.to_vec())
)?;Sourcepub fn reject(
&self,
code: Option<StatusCode>,
reason: Option<String>,
) -> Result<()>
pub fn reject( &self, code: Option<StatusCode>, reason: Option<String>, ) -> Result<()>
Reject the incoming INVITE request
Sends a reject response to reject the incoming INVITE request. Sends a 603 Decline by default, or a custom status code if provided. This terminates the dialog creation process.
§Returns
Ok(())- Response sent successfullyErr(Error)- Failed to send response or transaction terminated
§Examples
// Reject the incoming call
dialog.reject(Some(rsip::StatusCode::BusyHere), Some("Busy here".into()))?;Sourcepub async fn bye(&self) -> Result<()>
pub async fn bye(&self) -> Result<()>
Send a BYE request to terminate the dialog
Sends a BYE request to gracefully terminate an established dialog. This should only be called for confirmed dialogs. If the dialog is not confirmed, this method returns immediately without error.
§Returns
Ok(())- BYE was sent successfully or dialog not confirmedErr(Error)- Failed to send BYE request
§Examples
// End an established call
dialog.bye().await?;Sourcepub async fn reinvite(
&self,
headers: Option<Vec<Header>>,
body: Option<Vec<u8>>,
) -> Result<Option<Response>>
pub async fn reinvite( &self, headers: Option<Vec<Header>>, body: Option<Vec<u8>>, ) -> Result<Option<Response>>
Send a re-INVITE request to modify the session
Sends a re-INVITE request within an established dialog to modify the session parameters (e.g., change media, add/remove streams). This can only be called for confirmed dialogs.
§Parameters
headers- Optional additional headers to includebody- Optional message body (typically new SDP)
§Returns
Ok(Some(Response))- Response to the re-INVITEOk(None)- Dialog not confirmed, no request sentErr(Error)- Failed to send re-INVITE
§Examples
let new_sdp = b"v=0\r\no=- 123 456 IN IP4 192.168.1.1\r\n...";
let response = dialog.reinvite(None, Some(new_sdp.to_vec())).await?;Sourcepub async fn update(
&self,
headers: Option<Vec<Header>>,
body: Option<Vec<u8>>,
) -> Result<Option<Response>>
pub async fn update( &self, headers: Option<Vec<Header>>, body: Option<Vec<u8>>, ) -> Result<Option<Response>>
Send an UPDATE request to modify session parameters
Sends an UPDATE request within an established dialog to modify session parameters without the complexity of a re-INVITE. This is typically used for smaller session modifications.
§Parameters
headers- Optional additional headers to includebody- Optional message body (typically SDP)
§Returns
Ok(Some(Response))- Response to the UPDATEOk(None)- Dialog not confirmed, no request sentErr(Error)- Failed to send UPDATE
§Examples
let response = dialog.update(None, Some(sdp_body)).await?;Sourcepub async fn info(
&self,
headers: Option<Vec<Header>>,
body: Option<Vec<u8>>,
) -> Result<Option<Response>>
pub async fn info( &self, headers: Option<Vec<Header>>, body: Option<Vec<u8>>, ) -> Result<Option<Response>>
Send an INFO request for mid-dialog information
Sends an INFO request within an established dialog to exchange application-level information. This is commonly used for DTMF tones, but can carry any application-specific data.
§Parameters
headers- Optional additional headers to includebody- Optional message body (application-specific data)
§Returns
Ok(Some(Response))- Response to the INFOOk(None)- Dialog not confirmed, no request sentErr(Error)- Failed to send INFO
§Examples
// Send DTMF tone
let dtmf_body = b"Signal=1\r\nDuration=100\r\n";
let headers = vec![
rsip::Header::ContentType("application/dtmf-relay".into())
];
let response = dialog.info(Some(headers), Some(dtmf_body.to_vec())).await?;Sourcepub async fn request(
&self,
method: Method,
headers: Option<Vec<Header>>,
body: Option<Vec<u8>>,
) -> Result<Option<Response>>
pub async fn request( &self, method: Method, headers: Option<Vec<Header>>, body: Option<Vec<u8>>, ) -> Result<Option<Response>>
Send a generic in-dialog request
Sourcepub async fn notify(
&self,
headers: Option<Vec<Header>>,
body: Option<Vec<u8>>,
) -> Result<Option<Response>>
pub async fn notify( &self, headers: Option<Vec<Header>>, body: Option<Vec<u8>>, ) -> Result<Option<Response>>
Send a NOTIFY request
Sourcepub async fn refer(
&self,
refer_to: Uri,
headers: Option<Vec<Header>>,
body: Option<Vec<u8>>,
) -> Result<Option<Response>>
pub async fn refer( &self, refer_to: Uri, headers: Option<Vec<Header>>, body: Option<Vec<u8>>, ) -> Result<Option<Response>>
Send a REFER request
Sourcepub async fn notify_refer(
&self,
status: StatusCode,
sub_state: &str,
) -> Result<Option<Response>>
pub async fn notify_refer( &self, status: StatusCode, sub_state: &str, ) -> Result<Option<Response>>
Send a REFER progress notification (RFC 3515)
This is used by the REFER recipient to notify the sender about the progress of the referred action.
§Parameters
status- The status of the referred action (e.g., 100 Trying, 200 OK)sub_state- The subscription state (e.g., “active”, “terminated;reason=noresource”)
Sourcepub fn as_subscription(&self) -> ServerSubscriptionDialog
pub fn as_subscription(&self) -> ServerSubscriptionDialog
Convert this INVITE dialog to a subscription dialog
This is useful for handling implicit subscriptions created by REFER.
Sourcepub async fn message(
&self,
headers: Option<Vec<Header>>,
body: Option<Vec<u8>>,
) -> Result<Option<Response>>
pub async fn message( &self, headers: Option<Vec<Header>>, body: Option<Vec<u8>>, ) -> Result<Option<Response>>
Send a MESSAGE request
Sourcepub async fn handle(&mut self, tx: &mut Transaction) -> Result<()>
pub async fn handle(&mut self, tx: &mut Transaction) -> Result<()>
Handle incoming transaction for this dialog
Processes incoming SIP requests that are routed to this dialog. This method handles sequence number validation and dispatches to appropriate handlers based on the request method and dialog state.
§Parameters
tx- The incoming transaction to handle
§Returns
Ok(())- Request handled successfullyErr(Error)- Failed to handle request
§Supported Methods
ACK- Confirms 2xx response (transitions to Confirmed state)BYE- Terminates the dialogINFO- Handles information exchangeOPTIONS- Handles capability queriesUPDATE- Handles session updatesINVITE- Handles initial INVITE or re-INVITE
Trait Implementations§
Source§impl Clone for ServerInviteDialog
impl Clone for ServerInviteDialog
Source§fn clone(&self) -> ServerInviteDialog
fn clone(&self) -> ServerInviteDialog
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for ServerInviteDialog
impl !RefUnwindSafe for ServerInviteDialog
impl Send for ServerInviteDialog
impl Sync for ServerInviteDialog
impl Unpin for ServerInviteDialog
impl !UnwindSafe for ServerInviteDialog
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> PipeAsRef for T
impl<T> PipeAsRef for T
Source§impl<T> PipeBorrow for T
impl<T> PipeBorrow for T
Source§impl<T> PipeDeref for T
impl<T> PipeDeref for T
Source§impl<T> PipeRef for T
impl<T> PipeRef for T
Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap<F, R>(self, func: F) -> Selfwhere
F: FnOnce(&Self) -> R,
fn tap<F, R>(self, func: F) -> Selfwhere
F: FnOnce(&Self) -> R,
Source§fn tap_dbg<F, R>(self, func: F) -> Selfwhere
F: FnOnce(&Self) -> R,
fn tap_dbg<F, R>(self, func: F) -> Selfwhere
F: FnOnce(&Self) -> R,
tap in debug builds, and does nothing in release builds.Source§fn tap_mut<F, R>(self, func: F) -> Selfwhere
F: FnOnce(&mut Self) -> R,
fn tap_mut<F, R>(self, func: F) -> Selfwhere
F: FnOnce(&mut Self) -> R,
Source§fn tap_mut_dbg<F, R>(self, func: F) -> Selfwhere
F: FnOnce(&mut Self) -> R,
fn tap_mut_dbg<F, R>(self, func: F) -> Selfwhere
F: FnOnce(&mut Self) -> R,
tap_mut in debug builds, and does nothing in release builds.Source§impl<T, U> TapAsRef<U> for Twhere
U: ?Sized,
impl<T, U> TapAsRef<U> for Twhere
U: ?Sized,
Source§fn tap_ref<F, R>(self, func: F) -> Self
fn tap_ref<F, R>(self, func: F) -> Self
Source§fn tap_ref_dbg<F, R>(self, func: F) -> Self
fn tap_ref_dbg<F, R>(self, func: F) -> Self
tap_ref in debug builds, and does nothing in release builds.Source§fn tap_ref_mut<F, R>(self, func: F) -> Self
fn tap_ref_mut<F, R>(self, func: F) -> Self
Source§impl<T, U> TapBorrow<U> for Twhere
U: ?Sized,
impl<T, U> TapBorrow<U> for Twhere
U: ?Sized,
Source§fn tap_borrow<F, R>(self, func: F) -> Self
fn tap_borrow<F, R>(self, func: F) -> Self
Source§fn tap_borrow_dbg<F, R>(self, func: F) -> Self
fn tap_borrow_dbg<F, R>(self, func: F) -> Self
tap_borrow in debug builds, and does nothing in release builds.Source§fn tap_borrow_mut<F, R>(self, func: F) -> Self
fn tap_borrow_mut<F, R>(self, func: F) -> Self
Source§impl<T> TapDeref for T
impl<T> TapDeref for T
Source§fn tap_deref_dbg<F, R>(self, func: F) -> Self
fn tap_deref_dbg<F, R>(self, func: F) -> Self
tap_deref in debug builds, and does nothing in release builds.Source§fn tap_deref_mut<F, R>(self, func: F) -> Self
fn tap_deref_mut<F, R>(self, func: F) -> Self
self for modification.