feat: upgrade buttplug package to protocol v4 and WASM v10
All checks were successful
Build and Push Docker Image to Gitea / build-and-push (push) Successful in 7m30s
All checks were successful
Build and Push Docker Image to Gitea / build-and-push (push) Successful in 7m30s
Upgrade the buttplug TypeScript client from class-based v3 protocol to interface-based v4 protocol, and the Rust/WASM server from the monolithic buttplug 9.0.9 crate to the split buttplug_core/buttplug_server/ buttplug_server_device_config 10.0.0 crates. TypeScript changes: - Messages are now plain interfaces with msgId()/setMsgId() helpers - ActuatorType → OutputType, SensorType → InputType - ScalarCmd/RotateCmd/LinearCmd → OutputCmd, SensorReadCmd → InputCmd - Client.ts → ButtplugClient.ts, new DeviceCommand/DeviceFeature files - Devices getter returns Map instead of array - Removed class-transformer/reflect-metadata dependencies Rust/WASM changes: - Split imports across buttplug_core, buttplug_server, buttplug_server_device_config - Removed ButtplugServerDowngradeWrapper (use ButtplugServer directly) - Replaced ButtplugFuture/ButtplugFutureStateShared with tokio::sync::oneshot - Updated Hardware::new for new 6-arg signature - Uses git fork (valknarthing/buttplug) to fix missing wasm deps in buttplug_core Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -8,12 +8,16 @@ mod webbluetooth;
|
||||
use js_sys;
|
||||
use tokio_stream::StreamExt;
|
||||
use crate::webbluetooth::{WebBluetoothCommunicationManagerBuilder};
|
||||
use buttplug::{
|
||||
core::message::{ButtplugServerMessageCurrent,serializer::vec_to_protocol_json},
|
||||
server::{ButtplugServerBuilder,ButtplugServerDowngradeWrapper,device::{ServerDeviceManagerBuilder,configuration::{DeviceConfigurationManager}}},
|
||||
util::async_manager, core::message::{BUTTPLUG_CURRENT_MESSAGE_SPEC_VERSION, ButtplugServerMessageVariant, serializer::{ButtplugSerializedMessage, ButtplugMessageSerializer, ButtplugServerJSONSerializer}},
|
||||
util::device_configuration::load_protocol_configs
|
||||
use buttplug_core::{
|
||||
message::{ButtplugServerMessageCurrent, BUTTPLUG_CURRENT_API_MAJOR_VERSION, serializer::{ButtplugSerializedMessage, ButtplugMessageSerializer}},
|
||||
util::async_manager,
|
||||
};
|
||||
use buttplug_server::{
|
||||
ButtplugServerBuilder, ButtplugServer,
|
||||
device::ServerDeviceManagerBuilder,
|
||||
message::{ButtplugServerMessageVariant, serializer::ButtplugServerJSONSerializer},
|
||||
};
|
||||
use buttplug_server_device_config::{DeviceConfigurationManager, load_protocol_configs};
|
||||
|
||||
type FFICallback = js_sys::Function;
|
||||
type FFICallbackContext = u32;
|
||||
@@ -33,16 +37,17 @@ use wasm_bindgen::prelude::*;
|
||||
use std::sync::Arc;
|
||||
use js_sys::Uint8Array;
|
||||
|
||||
pub type ButtplugWASMServer = Arc<ButtplugServerDowngradeWrapper>;
|
||||
pub type ButtplugWASMServer = Arc<ButtplugServer>;
|
||||
|
||||
pub fn send_server_message(
|
||||
message: &ButtplugServerMessageCurrent,
|
||||
callback: &FFICallback,
|
||||
) {
|
||||
let msg_array = [message.clone()];
|
||||
let json_msg = vec_to_protocol_json(&msg_array);
|
||||
let buf = json_msg.as_bytes();
|
||||
{
|
||||
let serializer = ButtplugServerJSONSerializer::default();
|
||||
serializer.force_message_version(&BUTTPLUG_CURRENT_API_MAJOR_VERSION);
|
||||
let json_msg = serializer.serialize(&[ButtplugServerMessageVariant::V4(message.clone())]);
|
||||
if let ButtplugSerializedMessage::Text(json) = json_msg {
|
||||
let buf = json.as_bytes();
|
||||
let this = JsValue::null();
|
||||
let uint8buf = unsafe { Uint8Array::new(&Uint8Array::view(buf)) };
|
||||
callback.call1(&this, &JsValue::from(uint8buf));
|
||||
@@ -50,10 +55,9 @@ pub fn send_server_message(
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub fn create_test_dcm(allow_raw_messages: bool) -> DeviceConfigurationManager {
|
||||
pub fn create_test_dcm(_allow_raw_messages: bool) -> DeviceConfigurationManager {
|
||||
load_protocol_configs(&None, &None, false)
|
||||
.expect("If this fails, the whole library goes with it.")
|
||||
.allow_raw_messages(allow_raw_messages)
|
||||
.finish()
|
||||
.expect("If this fails, the whole library goes with it.")
|
||||
}
|
||||
@@ -68,18 +72,17 @@ pub fn buttplug_create_embedded_wasm_server(
|
||||
let mut sdm = ServerDeviceManagerBuilder::new(dcm);
|
||||
sdm.comm_manager(WebBluetoothCommunicationManagerBuilder::default());
|
||||
let builder = ButtplugServerBuilder::new(sdm.finish().unwrap());
|
||||
let server = builder.finish().unwrap();
|
||||
let wrapper = Arc::new(ButtplugServerDowngradeWrapper::new(server));
|
||||
let event_stream = wrapper.server_version_event_stream();
|
||||
let server = Arc::new(builder.finish().unwrap());
|
||||
let event_stream = server.server_version_event_stream();
|
||||
let callback = callback.clone();
|
||||
async_manager::spawn(async move {
|
||||
pin_mut!(event_stream);
|
||||
while let Some(message) = event_stream.next().await {
|
||||
send_server_message(&ButtplugServerMessageCurrent::try_from(message).unwrap(), &callback);
|
||||
send_server_message(&message, &callback);
|
||||
}
|
||||
});
|
||||
|
||||
Box::into_raw(Box::new(wrapper))
|
||||
|
||||
Box::into_raw(Box::new(server))
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
@@ -106,15 +109,18 @@ pub fn buttplug_client_send_json_message(
|
||||
};
|
||||
let callback = callback.clone();
|
||||
let serializer = ButtplugServerJSONSerializer::default();
|
||||
serializer.force_message_version(&BUTTPLUG_CURRENT_MESSAGE_SPEC_VERSION);
|
||||
serializer.force_message_version(&BUTTPLUG_CURRENT_API_MAJOR_VERSION);
|
||||
let input_msg = serializer.deserialize(&ButtplugSerializedMessage::Text(std::str::from_utf8(buf).unwrap().to_owned())).unwrap();
|
||||
async_manager::spawn(async move {
|
||||
let msg = input_msg[0].clone();
|
||||
let response = server.parse_message(msg).await.unwrap();
|
||||
if let ButtplugServerMessageVariant::V3(response) = response {
|
||||
send_server_message(&response, &callback);
|
||||
let json_msg = serializer.serialize(&[response]);
|
||||
if let ButtplugSerializedMessage::Text(json) = json_msg {
|
||||
let buf = json.as_bytes();
|
||||
let this = JsValue::null();
|
||||
let uint8buf = unsafe { Uint8Array::new(&Uint8Array::view(buf)) };
|
||||
callback.call1(&this, &JsValue::from(uint8buf));
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user