Skip to content

Commit

Permalink
feat: added From<u64> to U63
Browse files Browse the repository at this point in the history
  • Loading branch information
Ghamza-Jd committed Nov 12, 2024
1 parent 7910fef commit e69db98
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 31 deletions.
3 changes: 1 addition & 2 deletions e2e/tests/audiobridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use jarust::plugins::audio_bridge::params::AudioBridgeDestroyParams;
use jarust::plugins::audio_bridge::params::AudioBridgeEditParams;
use jarust::plugins::audio_bridge::params::AudioBridgeEditParamsOptional;
use jarust::plugins::audio_bridge::params::AudioBridgeExistsParams;
use jarust::plugins::common::U63;
use jarust::plugins::JanusId;
use std::time::Duration;
use tokio::sync::mpsc::UnboundedReceiver;
Expand All @@ -20,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(U63::new(rand::random()));
let room_id = JanusId::Uint(rand::random::<u64>().into());

'before_creation: {
let exists = handle
Expand Down
5 changes: 2 additions & 3 deletions jarust/examples/streaming.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use jarust::core::connect;
use jarust::core::jaconfig::JaConfig;
use jarust::core::jaconfig::JanusAPI;
use jarust::interface::tgenerator::RandomTransactionGenerator;
use jarust::plugins::common::U63;
use jarust::plugins::streaming::jahandle_ext::Streaming;
use jarust::plugins::streaming::params::*;
use jarust::plugins::JanusId;
Expand Down Expand Up @@ -45,7 +44,7 @@ async fn main() -> anyhow::Result<()> {
StreamingCreateParams {
mountpoint_type: StreamingMountpointType::RTP,
optional: StreamingCreateParamsOptional {
id: Some(JanusId::Uint(U63::new(1337))),
id: Some(JanusId::Uint(1337.into())),
name: Some(String::from("stream name")),
description: Some(String::from("stream description")),
media: Some(vec![StreamingRtpMedia {
Expand Down Expand Up @@ -73,7 +72,7 @@ async fn main() -> anyhow::Result<()> {
tracing::info!("Mountpoints {:#?}", mountpoints);

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

Expand Down
3 changes: 1 addition & 2 deletions jarust/examples/video_room.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use jarust::core::jaconfig::JanusAPI;
use jarust::interface::japrotocol::Jsep;
use jarust::interface::japrotocol::JsepType;
use jarust::interface::tgenerator::RandomTransactionGenerator;
use jarust::plugins::common::U63;
use jarust::plugins::video_room::jahandle_ext::VideoRoom;
use jarust::plugins::video_room::params::*;
use jarust::plugins::JanusId;
Expand Down Expand Up @@ -127,7 +126,7 @@ async fn main() -> anyhow::Result<()> {
VideoRoomPublisherJoinParams {
room: room_id.clone(),
optional: VideoRoomPublisherJoinParamsOptional {
id: Some(JanusId::Uint(U63::new(1337))),
id: Some(JanusId::Uint(1337.into())),
display: Some(String::from("Publisher name")),
token: None,
},
Expand Down
18 changes: 9 additions & 9 deletions jarust_plugins/src/audio_bridge/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ impl TryFrom<JaResponse> for PluginEvent {
mod tests {
use super::PluginEvent;
use crate::audio_bridge::events::AudioBridgeEvent;
use crate::common::U63;

use crate::JanusId;
use jarust_interface::japrotocol::JaHandleEvent;
use jarust_interface::japrotocol::JaResponse;
Expand Down Expand Up @@ -167,8 +167,8 @@ mod tests {
assert_eq!(
event,
PluginEvent::AudioBridgeEvent(AudioBridgeEvent::RoomJoined {
id: JanusId::Uint(U63::new(751378u64)),
room: JanusId::Uint(U63::new(684657)),
id: JanusId::Uint(751378u64.into()),
room: JanusId::Uint(684657.into()),
participants: vec![],
})
);
Expand Down Expand Up @@ -201,8 +201,8 @@ mod tests {
assert_eq!(
event,
PluginEvent::AudioBridgeEvent(AudioBridgeEvent::RoomJoinedWithEstabilshment {
id: JanusId::Uint(U63::new(751378)),
room: JanusId::Uint(U63::new(684657)),
id: JanusId::Uint(751378.into()),
room: JanusId::Uint(684657.into()),
participants: vec![],
jsep: Jsep {
jsep_type: JsepType::Answer,
Expand Down Expand Up @@ -235,8 +235,8 @@ mod tests {
assert_eq!(
event,
PluginEvent::AudioBridgeEvent(AudioBridgeEvent::RoomLeft {
id: JanusId::Uint(U63::new(751378)),
room: JanusId::Uint(U63::new(684657)),
id: JanusId::Uint(751378.into()),
room: JanusId::Uint(684657.into()),
})
);
}
Expand Down Expand Up @@ -264,8 +264,8 @@ mod tests {
assert_eq!(
event,
PluginEvent::AudioBridgeEvent(AudioBridgeEvent::RoomChanged {
id: JanusId::Uint(U63::new(38626)),
room: JanusId::Uint(U63::new(61682)),
id: JanusId::Uint(38626.into()),
room: JanusId::Uint(61682.into()),
participants: vec![],
})
);
Expand Down
10 changes: 8 additions & 2 deletions jarust_plugins/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ impl U63 {
pub const MAX: u64 = (1 << 63) - 1;

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

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

Expand All @@ -37,3 +37,9 @@ impl U63 {
}
}
}

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

use crate::streaming::events::StreamingEvent;
use crate::JanusId;
use jarust_interface::japrotocol::JaHandleEvent;
Expand Down Expand Up @@ -111,7 +111,7 @@ mod tests {
assert_eq!(
event,
PluginEvent::StreamingEvent(StreamingEvent::MountpointCreated {
id: JanusId::Uint(U63::new(63807u64)),
id: JanusId::Uint(63807u64.into()),
mountpoint_type: "live".to_string(),
})
);
Expand All @@ -138,7 +138,7 @@ mod tests {
assert_eq!(
event,
PluginEvent::StreamingEvent(StreamingEvent::MountpointDestroyed {
id: JanusId::Uint(U63::new(63807u64)),
id: JanusId::Uint(63807u64.into()),
})
);
}
Expand Down
20 changes: 10 additions & 10 deletions jarust_plugins/src/video_room/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ impl TryFrom<JaResponse> for PluginEvent {
#[cfg(test)]
mod tests {
use super::PluginEvent;
use crate::common::U63;

use crate::video_room::events::VideoRoomEvent;
use crate::video_room::responses::ConfiguredStream;
use crate::JanusId;
Expand Down Expand Up @@ -429,8 +429,8 @@ mod tests {
assert_eq!(
event,
PluginEvent::VideoRoomEvent(VideoRoomEvent::RoomJoined {
id: JanusId::Uint(U63::new(638074)),
room: JanusId::Uint(U63::new(88120664)),
id: JanusId::Uint(638074.into()),
room: JanusId::Uint(88120664.into()),
display: Some("Joiner McJoinface".to_string()),
})
);
Expand Down Expand Up @@ -463,7 +463,7 @@ mod tests {
assert_eq!(
event,
PluginEvent::VideoRoomEvent(VideoRoomEvent::RoomJoinedWithEst {
id: JanusId::Uint(U63::new(8146468u64)),
id: JanusId::Uint(8146468.into()),
display: Some("Joiner McJoinface".to_string()),
jsep: Jsep {
jsep_type: JsepType::Answer,
Expand Down Expand Up @@ -495,7 +495,7 @@ mod tests {
assert_eq!(
event,
PluginEvent::VideoRoomEvent(VideoRoomEvent::RoomDestroyed {
room: JanusId::Uint(U63::new(8146468u64)),
room: JanusId::Uint(8146468.into()),
})
)
}
Expand All @@ -522,7 +522,7 @@ mod tests {
assert_eq!(
event,
PluginEvent::VideoRoomEvent(VideoRoomEvent::NewPublisher {
room: JanusId::Uint(U63::new(8146468u64)),
room: JanusId::Uint(8146468.into()),
publishers: vec![]
})
);
Expand Down Expand Up @@ -554,9 +554,9 @@ mod tests {
assert_eq!(
event,
PluginEvent::VideoRoomEvent(VideoRoomEvent::PublisherJoined {
room: JanusId::Uint(U63::new(8146468u64)),
room: JanusId::Uint(8146468.into()),
description: Some("A brand new description!".to_string()),
id: JanusId::Uint(U63::new(1337)),
id: JanusId::Uint(1337.into()),
private_id: 4113762326,
publishers: vec![],
attendees: vec![]
Expand Down Expand Up @@ -613,7 +613,7 @@ mod tests {
assert_eq!(
event,
PluginEvent::VideoRoomEvent(VideoRoomEvent::LeftRoom {
room: JanusId::Uint(U63::new(8146468u64)),
room: JanusId::Uint(8146468.into()),
participant: JanusId::String("ok".to_string())
})
)
Expand Down Expand Up @@ -664,7 +664,7 @@ mod tests {
assert_eq!(
event,
PluginEvent::VideoRoomEvent(VideoRoomEvent::ConfiguredWithEst {
room: JanusId::Uint(U63::new(8146468u64)),
room: JanusId::Uint(8146468.into()),
audio_codec: Some("opus".to_string()),
video_codec: Some("h264".to_string()),
streams: vec![
Expand Down

0 comments on commit e69db98

Please sign in to comment.