Getting Started
Prerequisites
Before you start using the StreamDock SDK, please ensure you have:
- Downloaded and installed StreamDock SDK
- Connected your StreamDock device to your computer
- Prepared the application you want to control
Starting the SDK
Method 1: Manual Startup
- Find the
WebsocketSDK.exefile - Double-click to run or execute in command line:(Where 9002 is the WebSocket port number, customizable)
WebsocketSDK.exe -port 9002
Method 2: Programmatic Startup
If you want to automatically start the SDK in your application, you can use the following code:
const { execFile } = require('child_process');
// Set WebSocket port number
const port = 9002;
execFile('WebsocketSDK.exe', ['-port', port], (error, stdout, stderr) => {
if (error) {
console.error('Startup failed:', error.message);
return;
}
console.log('SDK started');
});
Connecting to Device
After starting the SDK, you can control your StreamDock device through WebSocket connection.
JavaScript Example
const ws = new WebSocket('ws://127.0.0.1:9002');
let devicePath = null;
ws.onopen = () => {
console.log("WebSocket connection established");
};
ws.onmessage = (e) => {
const response = JSON.parse(e.data);
// Save device path
if (response.payload && response.payload.Path) {
devicePath = response.path;
}
console.log("Received message:", response);
// Handle device connection event
if (response.event === "deviceDidConnect") {
console.log("Device connected:", response.payload);
// After successful connection, send read event to listen for device operations
ws.send(JSON.stringify({
"event": "read",
"path": response.path
}));
}
// Handle key input event
if (response.event === "read") {
console.log("Key event:", response.payload);
}
};
ws.onerror = (error) => {
console.error("WebSocket error:", error);
};
ws.onclose = () => {
console.log("Connection closed");
};
Python Example
import asyncio
import websockets
import json
async def streamdock_client():
uri = "ws://127.0.0.1:9002"
async with websockets.connect(uri) as websocket:
# Receive messages
while True:
message = await websocket.recv()
data = json.loads(message)
print(f"Received message: {data}")
if data.get("event") == "deviceDidConnect":
path = data.get("path")
# Send read command
await websocket.send(json.dumps({
"event": "read",
"path": path
}))
# Run client
asyncio.get_event_loop().run_until_complete(streamdock_client())
Next Steps
After successful connection, you can:
- Set device background image
- Customize key icons
- Adjust device brightness
- Listen for key operations
For detailed operations, please refer to the Events Sent and Events Received documentation.
