Skip to content

Module structure cleanup #31

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: trunk
Choose a base branch
from
Open
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
25 changes: 25 additions & 0 deletions arirs/src/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use thiserror::Error;
use tokio::task::JoinError;
use tokio_tungstenite::tungstenite;

pub type Result<T> = std::result::Result<T, AriError>;

#[derive(Debug, Error)]
pub enum AriError {
#[error("URL parsing error")]
UrlParseError(#[from] url::ParseError),
#[error("WebSocket error")]
TungsteniteError(#[from] tungstenite::Error),
#[error("HTTP Request error")]
ReqwestError(#[from] reqwest::Error),
#[error("Join Error")]
JoinError(#[from] JoinError),
#[error("Unknown error occurred: {0}")]
Unknown(String),
}

impl From<tungstenite::error::UrlError> for AriError {
fn from(err: tungstenite::error::UrlError) -> Self {
AriError::TungsteniteError(err.into())
}
}
20 changes: 20 additions & 0 deletions arirs/src/event.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use serde::{Deserialize, Serialize};

use crate::{channel::*, device::DeviceStateChanged};

#[derive(Serialize, Deserialize, Debug)]
#[serde(tag = "type")]
pub enum Event {
StasisStart(StasisStart),
StasisEnd(StasisEnd),
ChannelCreated(ChannelCreated),
ChannelDestroyed(ChannelDestroyed),
ChannelVarset(ChannelVarset),
ChannelHangupRequest(ChannelHangupRequest),
ChannelDialplan(ChannelDialplan),
ChannelStateChange(ChannelStateChange),
ChannelDtmfReceived(ChannelDtmfReceived),
DeviceStateChanged(DeviceStateChanged),
#[serde(other)]
Unknown,
}
51 changes: 4 additions & 47 deletions arirs/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
use channel::{
ChannelCreated, ChannelDestroyed, ChannelDialplan, ChannelDtmfReceived, ChannelHangupRequest, ChannelStateChange, ChannelVarset,
StasisEnd, StasisStart,
};
use device::DeviceStateChanged;
use serde::{Deserialize, Serialize};
use thiserror::Error;
use tokio::task::JoinError;
use tokio_tungstenite::tungstenite;

pub mod bridge;
pub mod channel;
pub mod client;
Expand All @@ -17,41 +7,8 @@ pub mod recording;
pub mod rtp_statistics;
pub mod variable;

pub type Result<T> = std::result::Result<T, AriError>;

#[derive(Debug, Error)]
pub enum AriError {
#[error("URL parsing error")]
UrlParseError(#[from] url::ParseError),
#[error("WebSocket error")]
TungsteniteError(#[from] tungstenite::Error),
#[error("HTTP Request error")]
ReqwestError(#[from] reqwest::Error),
#[error("Join Error")]
JoinError(#[from] JoinError),
#[error("Unknown error occurred: {0}")]
Unknown(String),
}

impl From<tungstenite::error::UrlError> for AriError {
fn from(err: tungstenite::error::UrlError) -> Self {
AriError::TungsteniteError(err.into())
}
}
mod error;
pub use error::{AriError, Result};

#[derive(Serialize, Deserialize, Debug)]
#[serde(tag = "type")]
pub enum Event {
StasisStart(StasisStart),
StasisEnd(StasisEnd),
ChannelCreated(ChannelCreated),
ChannelDestroyed(ChannelDestroyed),
ChannelVarset(ChannelVarset),
ChannelHangupRequest(ChannelHangupRequest),
ChannelDialplan(ChannelDialplan),
ChannelStateChange(ChannelStateChange),
ChannelDtmfReceived(ChannelDtmfReceived),
DeviceStateChanged(DeviceStateChanged),
#[serde(other)]
Unknown,
}
mod event;
pub use event::Event;