Skip to content
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

fix/minor fixes #159

Merged
merged 5 commits into from
Nov 12, 2024
Merged
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
2 changes: 1 addition & 1 deletion e2e/tests/audiobridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use tokio::sync::mpsc::UnboundedReceiver;
async fn room_crud_e2e() {
let default_timeout = Duration::from_secs(4);
let handle = make_audiobridge_attachment().await.0;
let room_id = JanusId::Uint(rand::random());
let room_id = JanusId::Uint(rand::random::<u64>().into());

'before_creation: {
let exists = handle
Expand Down
3 changes: 3 additions & 0 deletions jarust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ tokio-rt = [
[dev-dependencies]
anyhow = "1.0.93"
async-trait.workspace = true
jarust_core = { version = "0.8.0", path = "../jarust_core" }
jarust_interface = { version = "0.8.0", path = "../jarust_interface" }
jarust_plugins = { version = "0.8.0", path = "../jarust_plugins" }
serde_json.workspace = true
serde.workspace = true
tokio = { workspace = true, features = ["macros", "rt-multi-thread"] }
Expand Down
8 changes: 5 additions & 3 deletions jarust/examples/streaming.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ async fn main() -> anyhow::Result<()> {
let env_filter = EnvFilter::from_default_env()
.add_directive("jarust_core=trace".parse()?)
.add_directive("jarust_plugins=trace".parse()?)
.add_directive("jarust_transport=trace".parse()?)
.add_directive("jarust_interface=trace".parse()?)
.add_directive("jarust_rt=trace".parse()?)
.add_directive(format!("{filename}=trace").parse()?);
tracing_subscriber::fmt().with_env_filter(env_filter).init();
Expand Down Expand Up @@ -44,7 +44,7 @@ async fn main() -> anyhow::Result<()> {
StreamingCreateParams {
mountpoint_type: StreamingMountpointType::RTP,
optional: StreamingCreateParamsOptional {
id: Some(JanusId::Uint(1337)),
id: Some(JanusId::Uint(1337.into())),
name: Some(String::from("stream name")),
description: Some(String::from("stream description")),
media: Some(vec![StreamingRtpMedia {
Expand All @@ -71,7 +71,9 @@ async fn main() -> anyhow::Result<()> {
let mountpoints = handle.list(timeout).await?;
tracing::info!("Mountpoints {:#?}", mountpoints);

let info = handle.info(JanusId::Uint(1337), None, timeout).await?;
let info = handle
.info(JanusId::Uint(1337.into()), None, timeout)
.await?;
tracing::info!("Info: {:#?}", info);

handle
Expand Down
2 changes: 1 addition & 1 deletion jarust/examples/video_room.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ async fn main() -> anyhow::Result<()> {
VideoRoomPublisherJoinParams {
room: room_id.clone(),
optional: VideoRoomPublisherJoinParamsOptional {
id: Some(JanusId::Uint(1337)),
id: Some(JanusId::Uint(1337.into())),
display: Some(String::from("Publisher name")),
token: None,
},
Expand Down
2 changes: 2 additions & 0 deletions jarust_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,7 @@ tokio-rt = ["jarust_rt/tokio-rt", "jarust_interface/tokio-rt"]

[dev-dependencies]
anyhow = "1.0.93"
jarust_interface = { version = "0.8.0", path = "../jarust_interface" }
jarust_rt = { version = "0.8.0", path = "../jarust_rt" }
tokio = { workspace = true, features = ["macros", "rt-multi-thread"] }
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
3 changes: 3 additions & 0 deletions jarust_plugins/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,8 @@ __experimental = []

[dev-dependencies]
anyhow = "1.0.93"
jarust_core = { version = "0.8.0", path = "../jarust_core" }
jarust_interface = { version = "0.8.0", path = "../jarust_interface" }
jarust_rt = { version = "0.8.0", path = "../jarust_rt" }
tokio = { workspace = true, features = ["time", "macros", "rt-multi-thread"] }
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
33 changes: 17 additions & 16 deletions jarust_plugins/src/audio_bridge/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ impl TryFrom<JaResponse> for PluginEvent {
mod tests {
use super::PluginEvent;
use crate::audio_bridge::events::AudioBridgeEvent;

use crate::JanusId;
use jarust_interface::japrotocol::JaHandleEvent;
use jarust_interface::japrotocol::JaResponse;
Expand All @@ -151,8 +152,8 @@ mod tests {
plugin: "janus.plugin.audiobridge".to_string(),
data: PluginInnerData::Data(json!({
"audiobridge": "joined",
"room": 684657u32,
"id": 751378u32,
"room": 684657u64,
"id": 751378u64,
"participants": []
})),
},
Expand All @@ -166,8 +167,8 @@ mod tests {
assert_eq!(
event,
PluginEvent::AudioBridgeEvent(AudioBridgeEvent::RoomJoined {
id: JanusId::Uint(751378u32),
room: JanusId::Uint(684657),
id: JanusId::Uint(751378u64.into()),
room: JanusId::Uint(684657.into()),
participants: vec![],
})
);
Expand All @@ -181,8 +182,8 @@ mod tests {
plugin: "janus.plugin.audiobridge".to_string(),
data: PluginInnerData::Data(json!({
"audiobridge": "joined",
"room": 684657u32,
"id": 751378u32,
"room": 684657u64,
"id": 751378u64,
"participants": []
})),
},
Expand All @@ -200,8 +201,8 @@ mod tests {
assert_eq!(
event,
PluginEvent::AudioBridgeEvent(AudioBridgeEvent::RoomJoinedWithEstabilshment {
id: JanusId::Uint(751378),
room: JanusId::Uint(684657),
id: JanusId::Uint(751378.into()),
room: JanusId::Uint(684657.into()),
participants: vec![],
jsep: Jsep {
jsep_type: JsepType::Answer,
Expand All @@ -220,8 +221,8 @@ mod tests {
plugin: "janus.plugin.audiobridge".to_string(),
data: PluginInnerData::Data(json!({
"audiobridge": "left",
"room": 684657u32,
"id": 751378u32
"room": 684657u64,
"id": 751378u64
})),
},
}),
Expand All @@ -234,8 +235,8 @@ mod tests {
assert_eq!(
event,
PluginEvent::AudioBridgeEvent(AudioBridgeEvent::RoomLeft {
id: JanusId::Uint(751378),
room: JanusId::Uint(684657),
id: JanusId::Uint(751378.into()),
room: JanusId::Uint(684657.into()),
})
);
}
Expand All @@ -248,8 +249,8 @@ mod tests {
plugin: "janus.plugin.audiobridge".to_string(),
data: PluginInnerData::Data(json!({
"audiobridge": "roomchanged",
"room": 61682u32,
"id": 38626u32,
"room": 61682u64,
"id": 38626u64,
"participants": []
})),
},
Expand All @@ -263,8 +264,8 @@ mod tests {
assert_eq!(
event,
PluginEvent::AudioBridgeEvent(AudioBridgeEvent::RoomChanged {
id: JanusId::Uint(38626),
room: JanusId::Uint(61682),
id: JanusId::Uint(38626.into()),
room: JanusId::Uint(61682.into()),
participants: vec![],
})
);
Expand Down
31 changes: 30 additions & 1 deletion jarust_plugins/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,34 @@ pub enum JanusId {
/// String Identifier
String(String),
/// Unsigned Integer Identifier
Uint(u32),
Uint(U63),
}

#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Serialize, Deserialize)]
pub struct U63(u64);

impl U63 {
pub const MAX: u64 = (1 << 63) - 1;

pub fn new(value: u64) -> Self {
Self::new_wrapping(value)
}

pub fn new_wrapping(value: u64) -> Self {
Self(value & U63::MAX)
}

pub fn new_saturating(value: u64) -> Self {
if value > U63::MAX {
Self(U63::MAX)
} else {
Self(value)
}
}
}

impl From<u64> for U63 {
fn from(value: u64) -> Self {
Self::new(value)
}
}
9 changes: 5 additions & 4 deletions jarust_plugins/src/streaming/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ impl TryFrom<JaResponse> for PluginEvent {
#[cfg(test)]
mod tests {
use super::PluginEvent;

use crate::streaming::events::StreamingEvent;
use crate::JanusId;
use jarust_interface::japrotocol::JaHandleEvent;
Expand All @@ -96,7 +97,7 @@ mod tests {
plugin: "janus.plugin.streaming".to_string(),
data: PluginInnerData::Data(json!({
"streaming": "created",
"id": 63807u32,
"id": 63807u64,
"type": "live",
})),
},
Expand All @@ -110,7 +111,7 @@ mod tests {
assert_eq!(
event,
PluginEvent::StreamingEvent(StreamingEvent::MountpointCreated {
id: JanusId::Uint(63807u32),
id: JanusId::Uint(63807u64.into()),
mountpoint_type: "live".to_string(),
})
);
Expand All @@ -124,7 +125,7 @@ mod tests {
plugin: "janus.plugin.streaming".to_string(),
data: PluginInnerData::Data(json!({
"streaming": "destroyed",
"id": 63807u32,
"id": 63807u64,
})),
},
}),
Expand All @@ -137,7 +138,7 @@ mod tests {
assert_eq!(
event,
PluginEvent::StreamingEvent(StreamingEvent::MountpointDestroyed {
id: JanusId::Uint(63807u32),
id: JanusId::Uint(63807u64.into()),
})
);
}
Expand Down
4 changes: 2 additions & 2 deletions jarust_plugins/src/streaming/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ make_dto!(
);

#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Serialize)]
#[serde(untagged, rename_all = "lowercase")]
#[serde(rename_all = "lowercase")]
pub enum StreamingMountpointType {
RTP,
LIVE,
Expand Down Expand Up @@ -59,7 +59,7 @@ make_dto!(
);

#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Serialize)]
#[serde(untagged, rename_all = "lowercase")]
#[serde(rename_all = "lowercase")]
pub enum StreamingRtpMediaType {
AUDIO,
VIDEO,
Expand Down
Loading
Loading