Skip to content

Commit 9b602cd

Browse files
committed
Add new input endpoints
1 parent fabf52b commit 9b602cd

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

lighthouse-client/src/lighthouse.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::{collections::HashMap, fmt::Debug, sync::{atomic::{AtomicI32, Ordering}
22

33
use async_tungstenite::tungstenite::{Message, self};
44
use futures::{prelude::*, channel::mpsc::{Sender, self}, stream::{SplitSink, SplitStream}, lock::Mutex};
5-
use lighthouse_protocol::{Authentication, ClientMessage, DirectoryTree, Frame, LaserMetrics, Model, ServerMessage, Value, Verb};
5+
use lighthouse_protocol::{Authentication, ClientMessage, DirectoryTree, Frame, InputEvent, LaserMetrics, Model, ServerMessage, Value, Verb};
66
use serde::{Deserialize, Serialize};
77
use stream_guard::GuardStreamExt;
88
use tracing::{warn, error, debug, info};
@@ -130,6 +130,25 @@ impl<S> Lighthouse<S>
130130
self.stream(&["user".into(), username, "model".into()], ()).await
131131
}
132132

133+
/// Sends an input event to the user's input endpoint.
134+
///
135+
/// Note that this is the new API which not all clients may support.
136+
pub async fn put_input(&self, payload: InputEvent) -> Result<ServerMessage<()>> {
137+
let username = self.authentication.username.clone();
138+
self.put(&["user".into(), username, "input".into()], payload).await
139+
}
140+
141+
/// Streams input events from the user's input endpoint.
142+
///
143+
/// Note that this is the new API which not all clients may support (in LUNA
144+
/// disabling the legacy mode will send events to this endpoint). If your
145+
/// client or library does not support this, you may need to `stream_model`
146+
/// and parse `LegacyInputEvent`s from there.
147+
pub async fn stream_input(&self) -> Result<impl Stream<Item = Result<ServerMessage<InputEvent>>>> {
148+
let username = self.authentication.username.clone();
149+
self.stream(&["user".into(), username, "input".into()], ()).await
150+
}
151+
133152
/// Fetches lamp server metrics.
134153
pub async fn get_laser_metrics(&self) -> Result<ServerMessage<LaserMetrics>> {
135154
self.get(&["metrics", "laser"]).await

0 commit comments

Comments
 (0)