Struct SipManager

Source
pub struct SipManager { /* private fields */ }
Expand description

Represents an SIP session. SipManager is used to instantiate the SIP connection make / receive calls.

Calling start connects to the SIP Server and starts listening and handling SIP messages.

§Examples

 use std::net::SocketAddr;
 use std::str::FromStr;
 use simple_sip_rs::config::Config;
 use simple_sip_rs::manager::SipManager;

 async fn start_sip() {
    let config = Config {
        server_addr: SocketAddr::from_str("192.168.1.100:5060").unwrap(),
        own_addr: SocketAddr::from_str("192.168.1.2").unwrap(),
        username: "username".to_string(),
        password: "password".to_string(),
        rtp_port_start: 20480,
        rtp_port_end: 20490,
    };


    let mut sip_manager = SipManager::from_config(config).await.unwrap();
    sip_manager.start().await.unwrap();

    let outgoing_call = sip_manager.call("1000".to_string());
}

Implementations§

Source§

impl SipManager

Source

pub async fn from_config(config: Config) -> Result<Self>

Create SipManager from the config

Source

pub async fn start(&mut self) -> Result<()>

Starts the registration on the SIP server and starts listening to SIP messages. This function is non-blocking

§Errors

This function will return an error in the following cases:

  • Failed to establish the underlying TCP connection
  • Failed to authenticate
Source

pub fn stop(&mut self)

Stops the underlying SIP socket. This effectively disconnects you from the server.

Source

pub async fn is_running(&self) -> bool

Checks if the connection is alive.

Source

pub fn take_incoming_call_receiver(&mut self) -> Option<IncomingCallReceiver>

Takes the incoming call receiver. This is useful if you want to handle incoming calls in another task / thread.

Will return None if the receiver was already taken.

Source

pub fn give_incoming_call_receiver(&mut self, receiver: IncomingCallReceiver)

Give back the incoming call receiver.

Source

pub async fn recv_incoming_call(&mut self) -> Result<Option<IncomingCall>>

Get the next incoming call in the queue.

§Errors

Errors if the receiver was previously taken.

Source

pub async fn call(&self, to: String) -> Result<OutgoingCall>

Initiate a call to the given destination.

§Arguments
  • to: Extension number to call. Ex: "1000".
§Errors

This function will return an error in the following cases:

  • You are not connected to the server
  • Failure to send the Invite message

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.

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> 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.
Source§

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

Source§

fn vzip(self) -> V

Source§

impl<T> ErasedDestructor for T
where T: 'static,