@@ -2,7 +2,7 @@ use std::{collections::HashMap, fmt::Debug, sync::{atomic::{AtomicI32, Ordering}
22
33use async_tungstenite:: tungstenite:: { Message , self } ;
44use 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 } ;
66use serde:: { Deserialize , Serialize } ;
77use stream_guard:: GuardStreamExt ;
88use 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