Skip to content

Commit

Permalink
Make SignalR public & document
Browse files Browse the repository at this point in the history
  • Loading branch information
LJ authored and LJ committed Jul 28, 2024
1 parent 0ea65b9 commit 60b8cae
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .config/extra.dic
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,5 @@ async
mutex
RPC
HTTPS
enum
cancelling
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub mod util;
// The models are split into slightly smaller files in order to avoid a really
// long single file.
mod assets;
mod signalr;
pub mod signalr;

// They are re-exported at the top level though to make importing them easier /
// less confusing.
Expand Down
2 changes: 1 addition & 1 deletion src/query/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! Models for querying the Resonite API
//! Models for querying the Resonite API via the HTTP/REST API

// Everything is based on Resonite's models, so not much can be done
#![allow(clippy::struct_excessive_bools)]
Expand Down
23 changes: 23 additions & 0 deletions src/signalr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,51 +29,64 @@ pub enum Message {
/// RPC call
Invocation {
#[serde(rename = "type")]
/// A hack to force serde to have this as `"type":1`
num: VariantNumber<1>,
#[serde(flatten)]
/// The data for the invocation
data: Invocation,
},
/// Data
StreamItem {
#[serde(rename = "type")]
/// A hack to force serde to have this as `"type":2`
num: VariantNumber<2>,
#[serde(flatten)]
/// The data for the stream item
data: serde_json::Value,
},
/// Invocation completed
Completion {
#[serde(rename = "type")]
/// A hack to force serde to have this as `"type":3`
num: VariantNumber<3>,
#[serde(flatten)]
/// The data for the invocation completion
data: serde_json::Value,
},
/// RPC call with streaming
StreamInvocation {
#[serde(rename = "type")]
/// A hack to force serde to have this as `"type":4`
num: VariantNumber<4>,
#[serde(flatten)]
/// The data for the stream invocation
data: serde_json::Value,
},
/// Cancel RPC call
CancelInvocation {
#[serde(rename = "type")]
/// A hack to force serde to have this as `"type":5`
num: VariantNumber<5>,
#[serde(flatten)]
/// The data for the invocation cancelling
data: CancelInvocation,
},
/// Keep the connection alive
Ping {
#[serde(rename = "type")]
/// A hack to force serde to have this as `"type":6`
num: VariantNumber<6>,
},
/// Closes connection
Close {
#[serde(rename = "type")]
/// A hack to force serde to have this as `"type":7`
num: VariantNumber<7>,
},
}

#[derive(Debug, Clone, Hash, PartialEq, Eq)]
/// A hack to force serde to accept numbers as enum tags
pub struct VariantNumber<const V: u8>;

impl<const V: u8> Serialize for VariantNumber<V> {
Expand Down Expand Up @@ -110,16 +123,21 @@ fn message_serde() {
}

#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
/// Invocation cancellation
pub struct CancelInvocation {
/// The ID of the invocation
pub invocation_id: String,
}

#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
/// An invocation
pub struct Invocation {
#[serde(skip_serializing_if = "Option::is_none")]
/// The ID of the invocation
pub invocation_id: Option<String>,
#[serde(flatten)]
/// Data of the invocation
pub data: InvocationData,
}

Expand All @@ -136,10 +154,15 @@ pub struct Invocation {
strum::VariantNames,
)]
#[serde(tag = "target", content = "arguments")]
/// Data of an invocation
pub enum InvocationData {
/// Data about a session update
ReceiveSessionUpdate((Box<crate::model::SessionInfo>,)),
/// Debug data
Debug((String,)),
/// Session removal data
RemoveSession((crate::id::Session, OffsetDateTime)),
/// Not yet supported or failed serde parsing of the invocation
#[serde(untagged)]
Unknown(serde_json::Value),
}
Expand Down

0 comments on commit 60b8cae

Please sign in to comment.