pub struct Clasp { /* private fields */ }Expand description
A Clasp client
Implementations§
Source§impl Clasp
impl Clasp
Sourcepub fn new(
url: &str,
name: String,
features: Vec<String>,
token: Option<String>,
reconnect: bool,
reconnect_interval_ms: u64,
) -> Self
pub fn new( url: &str, name: String, features: Vec<String>, token: Option<String>, reconnect: bool, reconnect_interval_ms: u64, ) -> Self
Create a new client (use builder for more options)
Sourcepub fn builder(url: &str) -> ClaspBuilder
pub fn builder(url: &str) -> ClaspBuilder
Create a builder
Sourcepub async fn connect_to(url: &str) -> Result<Self>
pub async fn connect_to(url: &str) -> Result<Self>
Connect to server (convenience method)
Sourcepub fn start_reconnect_loop(self: &Arc<Self>)
pub fn start_reconnect_loop(self: &Arc<Self>)
Start the reconnect loop (call after initial connect)
Sourcepub fn is_connected(&self) -> bool
pub fn is_connected(&self) -> bool
Check if connected
Sourcepub fn session_id(&self) -> Option<String>
pub fn session_id(&self) -> Option<String>
Get session ID
Sourcepub async fn subscribe<F>(&self, pattern: &str, callback: F) -> Result<u32>
pub async fn subscribe<F>(&self, pattern: &str, callback: F) -> Result<u32>
Subscribe to an address pattern
Sourcepub async fn unsubscribe(&self, id: u32) -> Result<()>
pub async fn unsubscribe(&self, id: u32) -> Result<()>
Unsubscribe
Sourcepub async fn set(&self, address: &str, value: impl Into<Value>) -> Result<()>
pub async fn set(&self, address: &str, value: impl Into<Value>) -> Result<()>
Set a parameter value
Sourcepub async fn set_locked(
&self,
address: &str,
value: impl Into<Value>,
) -> Result<()>
pub async fn set_locked( &self, address: &str, value: impl Into<Value>, ) -> Result<()>
Set with lock
Sourcepub async fn set_unlocked(
&self,
address: &str,
value: impl Into<Value>,
) -> Result<()>
pub async fn set_unlocked( &self, address: &str, value: impl Into<Value>, ) -> Result<()>
Set and unlock (release a previously held lock)
Sourcepub async fn stream(&self, address: &str, value: impl Into<Value>) -> Result<()>
pub async fn stream(&self, address: &str, value: impl Into<Value>) -> Result<()>
Send stream sample
Sourcepub async fn gesture(
&self,
address: &str,
id: u32,
phase: GesturePhase,
payload: impl Into<Value>,
) -> Result<()>
pub async fn gesture( &self, address: &str, id: u32, phase: GesturePhase, payload: impl Into<Value>, ) -> Result<()>
Send gesture input
Gestures are phased input streams for touch/pen/motion input. Each gesture has a stable ID and goes through phases:
Start: Begin a new gestureMove: Update position/state (may be coalesced by router)End: Complete the gesture normallyCancel: Abort the gesture
§Example
// Start a touch gesture
client.gesture("/input/touch", 1, GesturePhase::Start, json!({"x": 0.5, "y": 0.3})).await?;
// Move updates
client.gesture("/input/touch", 1, GesturePhase::Move, json!({"x": 0.6, "y": 0.4})).await?;
// End the gesture
client.gesture("/input/touch", 1, GesturePhase::End, json!({"x": 0.7, "y": 0.5})).await?;Sourcepub async fn timeline(
&self,
address: &str,
timeline_data: TimelineData,
) -> Result<()>
pub async fn timeline( &self, address: &str, timeline_data: TimelineData, ) -> Result<()>
Publish timeline automation
Timelines are pre-computed automation curves with keyframes. Once published, timelines are immutable - to modify, publish a new one.
§Arguments
address- The parameter address this timeline controlstimeline- The timeline data with keyframes
§Example
use clasp_core::{TimelineData, TimelineKeyframe, EasingType, Value};
let timeline = TimelineData::new(vec![
TimelineKeyframe { time: 0, value: Value::Float(0.0), easing: EasingType::Linear, bezier: None },
TimelineKeyframe { time: 1_000_000, value: Value::Float(1.0), easing: EasingType::EaseOut, bezier: None },
]);
client.timeline("/lights/master/dimmer", timeline).await?;Sourcepub async fn bundle_at(&self, messages: Vec<Message>, time: u64) -> Result<()>
pub async fn bundle_at(&self, messages: Vec<Message>, time: u64) -> Result<()>
Send scheduled bundle
Sourcepub fn signals(&self) -> Vec<SignalDefinition>
pub fn signals(&self) -> Vec<SignalDefinition>
Get all announced signals
Sourcepub fn query_signals(&self, pattern: &str) -> Vec<SignalDefinition>
pub fn query_signals(&self, pattern: &str) -> Vec<SignalDefinition>
Query signals matching a pattern
Sourcepub fn last_error(&self) -> Option<ErrorMessage>
pub fn last_error(&self) -> Option<ErrorMessage>
Get the last error received from server
Sourcepub fn clear_error(&self)
pub fn clear_error(&self)
Clear the last error