CreatorCreator
Home
Getting Started
  • 中文简体
  • English
Home
Getting Started
  • 中文简体
  • English
  • Creator

    • Getting Started
  • Stream Dock

    • Plugin SDK
    • Icon Pack

      • Overview
      • Terminology
      • Creating an Icon Pack
      • Icon Specifications
    • Scene Configuration

      • What is a Scenario Configuration?
      • Exporting
      • Use Cases
  • mPanel

    • Plugin SDK
  • Cpp SDK

    • Overview
    • Dependency Installation
    • Device Manager
    • StreamDock Base Class
    • Communication Transport
    • Example
    • API Reference
    • Source Code
  • Python SDK

    • Overview
    • Dependency Installation
    • Device Manager
    • StreamDock Base Class
    • API Reference
    • Examples
    • Source Code
  • Windows-WebSocket SDK

    • Overview
    • Getting Started
    • Events Sent
    • Events Received
    • Source Code
  • Support

    • Help and Bug Reporting

Getting Started

Prerequisites

Before you start using the StreamDock SDK, please ensure you have:

  1. Downloaded and installed StreamDock SDK
  2. Connected your StreamDock device to your computer
  3. Prepared the application you want to control

Starting the SDK

Method 1: Manual Startup

  1. Find the WebsocketSDK.exe file
  2. Double-click to run or execute in command line:
    WebsocketSDK.exe -port 9002
    
    (Where 9002 is the WebSocket port number, customizable)

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:

  1. Set device background image
  2. Customize key icons
  3. Adjust device brightness
  4. Listen for key operations

For detailed operations, please refer to the Events Sent and Events Received documentation.

Last Updated:
Contributors: JKWTCN
Prev
Overview
Next
Events Sent