Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions examples/client/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -523,9 +523,7 @@ async fn process_invite(opt: &MediaSessionOption, dialog: ServerInviteDialog) ->
if opt.random_reject > 0 {
if rand::random::<u32>() % opt.random_reject == 0 {
info!("Randomly rejecting the call");
dialog
.reject(Some(rsip::StatusCode::BusyHere), Some("Busy here".into()))
.ok();
dialog.reject(Some(rsip::StatusCode::BusyHere), Some("Busy here".into()));
return Ok(());
}
}
Expand Down Expand Up @@ -597,7 +595,7 @@ async fn process_invite(opt: &MediaSessionOption, dialog: ServerInviteDialog) ->
info!("User answered the call");
} else if r == "r" {
info!("User rejected the call");
dialog.reject(Some(rsip::StatusCode::BusyHere), Some("Busy here".into())).ok();
dialog.reject(Some(rsip::StatusCode::BusyHere), Some("Busy here".into()));
rejected = true;
return;
} else {
Expand Down
34 changes: 17 additions & 17 deletions src/dialog/client_dialog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ impl ClientInviteDialog {
}

self.inner
.transition(DialogState::Terminated(self.id(), TerminatedReason::UacBye))?;
.transition(DialogState::Terminated(self.id(), TerminatedReason::UacBye));
Ok(())
}

Expand Down Expand Up @@ -329,7 +329,7 @@ impl ClientInviteDialog {
if resp.status_code == StatusCode::OK {
let (handle, _) = TransactionHandle::new();
self.inner
.transition(DialogState::Updated(self.id(), request, handle))?;
.transition(DialogState::Updated(self.id(), request, handle));
}
}
_ => {}
Expand Down Expand Up @@ -620,7 +620,7 @@ impl ClientInviteDialog {
async fn handle_bye(&mut self, tx: &mut Transaction) -> Result<()> {
debug!(id = %self.id(), uri = %tx.original.uri, "received bye");
self.inner
.transition(DialogState::Terminated(self.id(), TerminatedReason::UasBye))?;
.transition(DialogState::Terminated(self.id(), TerminatedReason::UasBye));
tx.reply(rsip::StatusCode::OK).await?;
Ok(())
}
Expand All @@ -629,31 +629,31 @@ impl ClientInviteDialog {
debug!(id = %self.id(), uri = %tx.original.uri, "received info");
let (handle, rx) = TransactionHandle::new();
self.inner
.transition(DialogState::Info(self.id(), tx.original.clone(), handle))?;
.transition(DialogState::Info(self.id(), tx.original.clone(), handle));
self.inner.process_transaction_handle(tx, rx).await
}

async fn handle_options(&mut self, tx: &mut Transaction) -> Result<()> {
debug!(id = %self.id(), uri = %tx.original.uri, "received options");
let (handle, rx) = TransactionHandle::new();
self.inner
.transition(DialogState::Options(self.id(), tx.original.clone(), handle))?;
.transition(DialogState::Options(self.id(), tx.original.clone(), handle));
self.inner.process_transaction_handle(tx, rx).await
}

async fn handle_update(&mut self, tx: &mut Transaction) -> Result<()> {
debug!(id = %self.id(), uri = %tx.original.uri, "received update");
let (handle, rx) = TransactionHandle::new();
self.inner
.transition(DialogState::Updated(self.id(), tx.original.clone(), handle))?;
.transition(DialogState::Updated(self.id(), tx.original.clone(), handle));
self.inner.process_transaction_handle(tx, rx).await
}

async fn handle_reinvite(&mut self, tx: &mut Transaction) -> Result<()> {
debug!(id = %self.id(), uri = %tx.original.uri, "received reinvite");
let (handle, rx) = TransactionHandle::new();
self.inner
.transition(DialogState::Updated(self.id(), tx.original.clone(), handle))?;
.transition(DialogState::Updated(self.id(), tx.original.clone(), handle));

self.inner.process_transaction_handle(tx, rx).await?;

Expand All @@ -674,7 +674,7 @@ impl ClientInviteDialog {
debug!(id = %self.id(), uri = %tx.original.uri, "received refer");
let (handle, rx) = TransactionHandle::new();
self.inner
.transition(DialogState::Refer(self.id(), tx.original.clone(), handle))?;
.transition(DialogState::Refer(self.id(), tx.original.clone(), handle));

self.inner.process_transaction_handle(tx, rx).await
}
Expand All @@ -683,7 +683,7 @@ impl ClientInviteDialog {
debug!(id = %self.id(), uri = %tx.original.uri, "received message");
let (handle, rx) = TransactionHandle::new();
self.inner
.transition(DialogState::Message(self.id(), tx.original.clone(), handle))?;
.transition(DialogState::Message(self.id(), tx.original.clone(), handle));

self.inner.process_transaction_handle(tx, rx).await
}
Expand All @@ -692,15 +692,15 @@ impl ClientInviteDialog {
debug!(id = %self.id(), uri = %tx.original.uri, "received notify");
let (handle, rx) = TransactionHandle::new();
self.inner
.transition(DialogState::Notify(self.id(), tx.original.clone(), handle))?;
.transition(DialogState::Notify(self.id(), tx.original.clone(), handle));
self.inner.process_transaction_handle(tx, rx).await
}

pub async fn process_invite(
&self,
tx: &mut Transaction,
) -> Result<(DialogId, Option<Response>)> {
self.inner.transition(DialogState::Calling(self.id()))?;
self.inner.transition(DialogState::Calling(self.id()));
let mut auth_sent = false;
tx.send().await?;
let mut dialog_id = self.id();
Expand All @@ -712,13 +712,13 @@ impl ClientInviteDialog {
let status = resp.status_code.clone();

if status == StatusCode::Trying {
self.inner.transition(DialogState::Trying(self.id()))?;
self.inner.transition(DialogState::Trying(self.id()));
continue;
}

if matches!(status.kind(), rsip::StatusCodeKind::Provisional) {
self.inner.handle_provisional_response(&resp).await?;
self.inner.transition(DialogState::Early(self.id(), resp))?;
self.inner.transition(DialogState::Early(self.id(), resp));
continue;
}

Expand All @@ -732,7 +732,7 @@ impl ClientInviteDialog {
self.inner.transition(DialogState::Terminated(
self.id(),
TerminatedReason::ProxyAuthRequired,
))?;
));
break;
}
auth_sent = true;
Expand Down Expand Up @@ -761,7 +761,7 @@ impl ClientInviteDialog {
self.inner.transition(DialogState::Terminated(
self.id(),
TerminatedReason::ProxyAuthRequired,
))?;
));
continue;
}
}
Expand Down Expand Up @@ -797,13 +797,13 @@ impl ClientInviteDialog {
*self.inner.remote_uri.lock().unwrap() =
resp.remote_uri(tx.destination.as_ref())?;
self.inner
.transition(DialogState::Confirmed(dialog_id.clone(), resp))?;
.transition(DialogState::Confirmed(dialog_id.clone(), resp));
}
_ => {
self.inner.transition(DialogState::Terminated(
self.id(),
TerminatedReason::UasOther(resp.status_code.clone()),
))?;
));
}
}
break;
Expand Down
23 changes: 11 additions & 12 deletions src/dialog/dialog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ impl DialogInner {
self.transition(DialogState::Terminated(
id,
TerminatedReason::ProxyAuthRequired,
))?;
));
break;
}
auth_sent = true;
Expand All @@ -644,7 +644,7 @@ impl DialogInner {
self.transition(DialogState::Terminated(
id,
TerminatedReason::ProxyAuthRequired,
))?;
));
break;
}
}
Expand Down Expand Up @@ -935,7 +935,7 @@ impl DialogInner {
if method == Method::Invite {
self.handle_provisional_response(&resp).await?;
}
self.transition(DialogState::Early(self.id.lock().unwrap().clone(), resp))?;
self.transition(DialogState::Early(self.id.lock().unwrap().clone(), resp));
continue;
}

Expand All @@ -952,7 +952,7 @@ impl DialogInner {
self.transition(DialogState::Terminated(
id,
TerminatedReason::ProxyAuthRequired,
))?;
));
break;
}
auth_sent = true;
Expand All @@ -972,7 +972,7 @@ impl DialogInner {
self.transition(DialogState::Terminated(
id,
TerminatedReason::ProxyAuthRequired,
))?;
));
continue;
}
}
Expand Down Expand Up @@ -1170,7 +1170,7 @@ impl DialogInner {
version: Version::V2,
}
}
pub(super) fn transition(&self, state: DialogState) -> Result<()> {
pub(super) fn transition(&self, state: DialogState) {
// Try to send state update, but don't fail if channel is closed
self.state_sender.send(state.clone()).ok();

Expand All @@ -1179,7 +1179,7 @@ impl DialogInner {
| DialogState::Notify(_, _, _)
| DialogState::Info(_, _, _)
| DialogState::Options(_, _, _) => {
return Ok(());
return;
}
_ => {}
}
Expand All @@ -1191,17 +1191,16 @@ impl DialogInner {
target = %state,
"dialog already terminated, ignoring transition"
);
return Ok(());
return;
}
(DialogState::Confirmed(_, _), DialogState::WaitAck(_, _)) => {
warn!(target = %state, "dialog already confirmed, ignoring transition");
return Ok(());
return;
}
_ => {}
}
debug!(from = %old_state, to = %state, "transitioning state");
*old_state = state;
Ok(())
}

pub async fn process_transaction_handle(
Expand Down Expand Up @@ -1400,9 +1399,9 @@ impl Dialog {
match self {
Dialog::ServerInvite(d) => d.bye().await,
Dialog::ClientInvite(d) => d.hangup().await,
Dialog::ServerSubscription(d) => d.unsubscribe().await,
Dialog::ServerSubscription(d) => Ok(d.unsubscribe().await),
Dialog::ClientSubscription(d) => d.unsubscribe().await,
Dialog::ServerPublication(d) => d.close().await,
Dialog::ServerPublication(d) => Ok(d.close().await),
Dialog::ClientPublication(d) => d.close().await,
}
}
Expand Down
23 changes: 8 additions & 15 deletions src/dialog/publication.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ impl ClientPublicationDialog {
}
self.request(Method::Publish, Some(headers), None).await?;
self.inner
.transition(DialogState::Terminated(self.id(), TerminatedReason::UacBye))?;
.transition(DialogState::Terminated(self.id(), TerminatedReason::UacBye));
Ok(())
}

Expand Down Expand Up @@ -116,11 +116,8 @@ impl ClientPublicationDialog {
match tx.original.method {
Method::Publish => {
let (handle, rx) = TransactionHandle::new();
self.inner.transition(DialogState::Publish(
self.id(),
tx.original.clone(),
handle,
))?;
self.inner
.transition(DialogState::Publish(self.id(), tx.original.clone(), handle));
self.inner.process_transaction_handle(tx, rx).await
}
_ => Ok(()),
Expand Down Expand Up @@ -181,14 +178,13 @@ impl ServerPublicationDialog {
.tu_sender
.send(TransactionEvent::Respond(resp.clone()))?;
self.inner
.transition(DialogState::Confirmed(self.id(), resp))?;
.transition(DialogState::Confirmed(self.id(), resp));
Ok(())
}

pub async fn close(&self) -> Result<()> {
pub async fn close(&self) {
self.inner
.transition(DialogState::Terminated(self.id(), TerminatedReason::UasBye))?;
Ok(())
.transition(DialogState::Terminated(self.id(), TerminatedReason::UasBye));
}

pub async fn request(
Expand Down Expand Up @@ -235,11 +231,8 @@ impl ServerPublicationDialog {
match tx.original.method {
Method::Publish => {
let (handle, rx) = TransactionHandle::new();
self.inner.transition(DialogState::Publish(
self.id(),
tx.original.clone(),
handle,
))?;
self.inner
.transition(DialogState::Publish(self.id(), tx.original.clone(), handle));
self.inner.process_transaction_handle(tx, rx).await
}
_ => Ok(()),
Expand Down
Loading