From 21ddbf73170e4c2ce1cf3439c5a418ae504cd712 Mon Sep 17 00:00:00 2001 From: Ghamza-Jd Date: Wed, 26 Jun 2024 13:45:04 +0300 Subject: [PATCH 1/2] feat(core): added common traits on dtos --- jarust/src/error.rs | 2 +- jarust/src/jaconfig.rs | 4 ++-- jarust/src/japrotocol.rs | 22 +++++++++++----------- jarust/src/respones.rs | 4 ++-- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/jarust/src/error.rs b/jarust/src/error.rs index d1b56b2..63571d6 100644 --- a/jarust/src/error.rs +++ b/jarust/src/error.rs @@ -1,4 +1,4 @@ -#[derive(thiserror::Error, Debug)] +#[derive(Debug, thiserror::Error)] pub enum JaError { /* Transformed Errors */ #[error("Transport: {0}")] diff --git a/jarust/src/jaconfig.rs b/jarust/src/jaconfig.rs index 02cab26..ac4dd0b 100644 --- a/jarust/src/jaconfig.rs +++ b/jarust/src/jaconfig.rs @@ -1,4 +1,4 @@ -#[derive(Debug)] +#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)] pub struct JaConfig { pub(crate) url: String, pub(crate) apisecret: Option, @@ -6,7 +6,7 @@ pub struct JaConfig { pub(crate) capacity: usize, } -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)] pub enum TransportType { Ws, } diff --git a/jarust/src/japrotocol.rs b/jarust/src/japrotocol.rs index 751464c..e066769 100644 --- a/jarust/src/japrotocol.rs +++ b/jarust/src/japrotocol.rs @@ -4,7 +4,7 @@ use serde::Serialize; use serde_json::Value; /// The top-level response -#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)] +#[derive(Clone, PartialEq, Debug, Serialize, Deserialize)] pub struct JaResponse { #[serde(flatten)] pub janus: ResponseType, @@ -15,7 +15,7 @@ pub struct JaResponse { pub establishment_protocol: Option, } -#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)] +#[derive(Clone, PartialEq, Debug, Serialize, Deserialize)] #[serde(tag = "janus")] pub enum ResponseType { #[serde(rename = "error")] @@ -32,13 +32,13 @@ pub enum ResponseType { Event(JaHandleEvent), } -#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)] +#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Serialize, Deserialize)] pub struct ErrorResponse { pub code: u16, pub reason: String, } -#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)] +#[derive(Clone, PartialEq, Debug, Serialize, Deserialize)] #[serde(tag = "janus")] pub enum JaSuccessProtocol { #[serde(untagged)] @@ -55,13 +55,13 @@ pub struct JaData { pub id: u64, } -#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)] +#[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)] pub struct PluginData { pub plugin: String, pub data: Value, } -#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)] +#[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)] #[serde(tag = "janus")] pub enum JaHandleEvent { #[serde(rename = "event")] @@ -73,7 +73,7 @@ pub enum JaHandleEvent { GenericEvent(GenericEvent), } -#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)] +#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Serialize, Deserialize)] #[serde(tag = "janus")] pub enum GenericEvent { #[serde(rename = "detached")] @@ -96,7 +96,7 @@ pub enum GenericEvent { Trickle, } -#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)] +#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Serialize, Deserialize)] pub enum JsepType { #[serde(rename = "offer")] Offer, @@ -104,14 +104,14 @@ pub enum JsepType { Answer, } -#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)] +#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Serialize, Deserialize)] pub struct Jsep { #[serde(rename = "type")] pub jsep_type: JsepType, pub sdp: String, } -#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)] +#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Serialize, Deserialize)] pub struct RTP { pub ip: String, pub port: u64, @@ -123,7 +123,7 @@ pub struct RTP { pub fec: Option, } -#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)] +#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Serialize, Deserialize)] pub enum EstablishmentProtocol { #[serde(rename = "jsep")] JSEP(Jsep), diff --git a/jarust/src/respones.rs b/jarust/src/respones.rs index c96ef40..1be5fde 100644 --- a/jarust/src/respones.rs +++ b/jarust/src/respones.rs @@ -2,7 +2,7 @@ use serde::Deserialize; use serde::Serialize; use std::collections::HashMap; -#[derive(Clone, PartialEq, Debug, Serialize, Deserialize)] +#[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)] #[serde(rename_all = "kebab-case")] pub struct ServerInfoRsp { pub name: String, @@ -46,7 +46,7 @@ pub struct ServerInfoRsp { pub plugins: HashMap, } -#[derive(Clone, PartialEq, Debug, Serialize, Deserialize)] +#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Serialize, Deserialize)] pub struct MetaData { name: String, author: String, From 636adc5186c20042276bc819f057c7320487fe6d Mon Sep 17 00:00:00 2001 From: Ghamza-Jd Date: Wed, 26 Jun 2024 13:49:46 +0300 Subject: [PATCH 2/2] feat(plugins): added common traits on dtos --- jarust_plugins/src/audio_bridge/common.rs | 4 ++-- jarust_plugins/src/audio_bridge/events.rs | 6 +++--- jarust_plugins/src/audio_bridge/msg_opitons.rs | 12 ++++++------ jarust_plugins/src/audio_bridge/responses.rs | 16 ++++++++-------- jarust_plugins/src/echo_test/events.rs | 6 +++--- jarust_plugins/src/echo_test/msg_options.rs | 2 +- jarust_plugins/src/video_room/events.rs | 2 +- 7 files changed, 24 insertions(+), 24 deletions(-) diff --git a/jarust_plugins/src/audio_bridge/common.rs b/jarust_plugins/src/audio_bridge/common.rs index b6be7b2..4761226 100644 --- a/jarust_plugins/src/audio_bridge/common.rs +++ b/jarust_plugins/src/audio_bridge/common.rs @@ -4,7 +4,7 @@ use serde::Serialize; /// Rooms and Participants Identifier. /// /// Identifier should be by default unsigned integer, unless configured otherwise in the audiobridge config. -#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)] +#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Serialize, Deserialize)] #[serde(untagged)] pub enum Identifier { /// String Identifier @@ -13,7 +13,7 @@ pub enum Identifier { Uint(u64), } -#[derive(PartialEq, Debug, Deserialize)] +#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Deserialize)] pub struct Participant { pub id: Identifier, pub display: Option, diff --git a/jarust_plugins/src/audio_bridge/events.rs b/jarust_plugins/src/audio_bridge/events.rs index 696d834..57c208a 100644 --- a/jarust_plugins/src/audio_bridge/events.rs +++ b/jarust_plugins/src/audio_bridge/events.rs @@ -9,7 +9,7 @@ use jarust::japrotocol::ResponseType; use serde::Deserialize; use serde_json::from_value; -#[derive(Debug, PartialEq, Deserialize)] +#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Deserialize)] #[serde(tag = "audiobridge")] enum AudioBridgeEventDto { #[serde(rename = "joined")] @@ -36,13 +36,13 @@ enum AudioBridgeEventDto { }, } -#[derive(Debug, PartialEq)] +#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)] pub enum PluginEvent { AudioBridgeEvent(AudioBridgeEvent), GenericEvent(GenericEvent), } -#[derive(Debug, PartialEq)] +#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)] pub enum AudioBridgeEvent { RoomJoinedWithEstabilshment { id: Identifier, diff --git a/jarust_plugins/src/audio_bridge/msg_opitons.rs b/jarust_plugins/src/audio_bridge/msg_opitons.rs index e8bc6bf..e99ce00 100644 --- a/jarust_plugins/src/audio_bridge/msg_opitons.rs +++ b/jarust_plugins/src/audio_bridge/msg_opitons.rs @@ -1,7 +1,7 @@ use super::common::Identifier; use serde::Serialize; -#[derive(Serialize, Default)] +#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Default, Serialize)] pub struct CreateRoomOptions { /// unique numeric ID, chosen by plugin if missing #[serde(skip_serializing_if = "Option::is_none")] @@ -95,7 +95,7 @@ pub struct CreateRoomOptions { pub groups: Option>, } -#[derive(Serialize, Default)] +#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Default, Serialize)] pub struct EditRoomOptions { /// room secret, mandatory if configured #[serde(skip_serializing_if = "Option::is_none")] @@ -130,7 +130,7 @@ pub struct EditRoomOptions { pub permanent: Option, } -#[derive(Serialize, Default)] +#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Default, Serialize)] pub struct DestroyRoomMsg { #[serde(skip_serializing_if = "Option::is_none")] pub secret: Option, @@ -138,7 +138,7 @@ pub struct DestroyRoomMsg { pub permanent: Option, } -#[derive(Serialize, Default)] +#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Default, Serialize)] pub struct JoinRoomOptions { /// Unique ID to assign to the participant, assigned by the plugin if missing #[serde(skip_serializing_if = "Option::is_none")] @@ -236,7 +236,7 @@ pub struct JoinRoomOptions { pub generate_offer: Option, } -#[derive(Serialize)] +#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Serialize)] pub struct AllowedOptions { pub action: AllowAction, @@ -248,7 +248,7 @@ pub struct AllowedOptions { pub secret: Option, } -#[derive(Serialize)] +#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Serialize)] #[serde(rename_all = "lowercase")] pub enum AllowAction { Enable, diff --git a/jarust_plugins/src/audio_bridge/responses.rs b/jarust_plugins/src/audio_bridge/responses.rs index 4729497..ee27239 100644 --- a/jarust_plugins/src/audio_bridge/responses.rs +++ b/jarust_plugins/src/audio_bridge/responses.rs @@ -2,30 +2,30 @@ use super::common::Identifier; use super::common::Participant; use serde::Deserialize; -#[derive(Debug, Deserialize)] +#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Deserialize)] pub struct RoomCreatedRsp { pub room: Identifier, pub permanent: bool, } -#[derive(Debug, Deserialize)] +#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Deserialize)] pub struct RoomEditedRsp { pub room: Identifier, pub permanent: bool, } -#[derive(Debug, Deserialize)] +#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Deserialize)] pub struct RoomDestroyedRsp { pub room: Identifier, pub permanent: bool, } -#[derive(Debug, Deserialize)] +#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Deserialize)] pub struct ListRoomsRsp { pub list: Vec, } -#[derive(Debug, Deserialize)] +#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Deserialize)] pub struct Room { pub room: Identifier, pub description: String, @@ -37,19 +37,19 @@ pub struct Room { pub muted: bool, } -#[derive(Debug, Deserialize)] +#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Deserialize)] pub struct AllowedRsp { pub room: Identifier, pub allowed: Vec, } -#[derive(Debug, Deserialize)] +#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Deserialize)] pub struct ExistsRoomRsp { pub room: Identifier, pub exists: bool, } -#[derive(Debug, Deserialize)] +#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Deserialize)] pub struct ListParticipantsRsp { pub room: Identifier, pub participants: Vec, diff --git a/jarust_plugins/src/echo_test/events.rs b/jarust_plugins/src/echo_test/events.rs index c9d781a..15e3cce 100644 --- a/jarust_plugins/src/echo_test/events.rs +++ b/jarust_plugins/src/echo_test/events.rs @@ -7,19 +7,19 @@ use jarust::japrotocol::ResponseType; use serde::Deserialize; use serde_json::from_value; -#[derive(Debug, Deserialize, Clone)] +#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Deserialize)] enum EchoTestEventDto { #[serde(untagged)] Result { echotest: String, result: String }, } -#[derive(Debug, PartialEq)] +#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)] pub enum PluginEvent { EchoTestEvent(EchoTestEvent), GenericEvent(GenericEvent), } -#[derive(Debug, PartialEq)] +#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)] pub enum EchoTestEvent { Result { echotest: String, diff --git a/jarust_plugins/src/echo_test/msg_options.rs b/jarust_plugins/src/echo_test/msg_options.rs index e484106..8e08db9 100644 --- a/jarust_plugins/src/echo_test/msg_options.rs +++ b/jarust_plugins/src/echo_test/msg_options.rs @@ -1,6 +1,6 @@ use serde::Serialize; -#[derive(Serialize, Default)] +#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Default, Serialize)] pub struct StartOptions { pub audio: bool, pub video: bool, diff --git a/jarust_plugins/src/video_room/events.rs b/jarust_plugins/src/video_room/events.rs index 5cc5653..a5cf3cc 100644 --- a/jarust_plugins/src/video_room/events.rs +++ b/jarust_plugins/src/video_room/events.rs @@ -2,7 +2,7 @@ use jarust::error::JaError; use jarust::japrotocol::GenericEvent; use jarust::japrotocol::JaResponse; -#[derive(Debug, PartialEq)] +#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)] pub enum PluginEvent { GenericEvent(GenericEvent), }