+16
-1
crates/intiface_engine/src/engine.rs
+16
-1
crates/intiface_engine/src/engine.rs
···
114
114
.clone();
115
115
116
116
if let Some(rest_port) = options.rest_api_port() {
117
-
IntifaceRestServer::run(server).await;
117
+
select! {
118
+
_ = self.stop_token.cancelled() => {
119
+
info!("Owner requested process exit, exiting.");
120
+
}
121
+
res = IntifaceRestServer::run(rest_port, server) => {
122
+
info!("Rest API listener stopped, exiting.");
123
+
if let Err(e) = res {
124
+
error!("Error running Intiface Central RestAPI Server: {:?}", e);
125
+
}
126
+
}
127
+
};
128
+
if let Some(frontend) = &frontend {
129
+
frontend.send(EngineMessage::EngineStopped {}).await;
130
+
tokio::time::sleep(Duration::from_millis(100)).await;
131
+
frontend.disconnect();
132
+
}
118
133
return Ok(());
119
134
}
120
135
+9
-9
crates/intiface_engine/src/rest_server.rs
+9
-9
crates/intiface_engine/src/rest_server.rs
···
158
158
159
159
async fn set_device_output(
160
160
State(client): State<Arc<ButtplugClient>>,
161
-
Path((index, command, level)): Path<(u32, OutputType, f64)>,
161
+
Path((index, output_type, level)): Path<(u32, OutputType, f64)>,
162
162
) -> Result<(), IntifaceRestError> {
163
-
let cmd = ClientDeviceOutputCommand::from_command_value_float(command, level)
163
+
let cmd = ClientDeviceOutputCommand::from_command_value_float(output_type, level)
164
164
.map_err(IntifaceRestError::ButtplugClientError)?;
165
165
166
166
get_device(&client, index)?
···
171
171
172
172
async fn set_feature_output(
173
173
State(client): State<Arc<ButtplugClient>>,
174
-
Path((index, feature_index, command, level)): Path<(u32, u32, OutputType, f64)>,
174
+
Path((index, feature_index, output_type, level)): Path<(u32, u32, OutputType, f64)>,
175
175
) -> Result<(), IntifaceRestError> {
176
-
let cmd = ClientDeviceOutputCommand::from_command_value_float(command, level)
176
+
let cmd = ClientDeviceOutputCommand::from_command_value_float(output_type, level)
177
177
.map_err(IntifaceRestError::ButtplugClientError)?;
178
178
179
179
get_feature(&client, index, feature_index)?
···
256
256
257
257
async fn server_sse(
258
258
State(client): State<Arc<ButtplugClient>>,
259
-
) -> Sse<impl Stream<Item = Result<Event, Infallible>>> {
259
+
) -> Sse<impl Stream<Item = Result<Event, Infallible>>> {
260
260
let stream = client
261
261
.event_stream()
262
262
.map(|e| Ok(Event::default().data(format!("{:?}", e))));
···
265
265
}
266
266
267
267
impl IntifaceRestServer {
268
-
pub async fn run(server: ButtplugServer) -> Result<(), io::Error> {
268
+
pub async fn run(port: u16, server: ButtplugServer) -> Result<(), io::Error> {
269
269
let connector = ButtplugInProcessClientConnectorBuilder::default()
270
270
.server(server)
271
271
.finish();
···
285
285
.route("/devices/{index}/features", get(get_features))
286
286
.route("/devices/{index}/features/{index}/", put(get_feature_info))
287
287
.route(
288
-
"/devices/{index}/outputs/{command}/{level}",
288
+
"/devices/{index}/outputs/{output_type}/{level}",
289
289
put(set_device_output),
290
290
)
291
291
.route(
···
311
311
);
312
312
313
313
// write address like this to not make typos
314
-
let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
314
+
let addr = SocketAddr::from(([127, 0, 0, 1], port));
315
+
info!("Buttplug REST API Server now listening on {:?}", addr);
315
316
let listener = TcpListener::bind(addr).await?;
316
-
317
317
axum::serve(listener, app.into_make_service()).await?;
318
318
319
319
Ok(())