Skip to main content

streamdeck_client 0.5.0 copy "streamdeck_client: ^0.5.0" to clipboard
streamdeck_client: ^0.5.0 copied to clipboard

Pure Dart client for the Elgato Stream Deck WebSocket protocol. Handles connection, reconnection, and event parsing.

streamdeck_client #

Pure Dart client for the Elgato Stream Deck WebSocket protocol. Handles the connection, event parsing, and raw action/device state. No Flutter dependency. (Manifest models and device layout live in streamdeck_flutter, since they're rendering concerns.)

Usage #

The Stream Deck app launches your plugin with CLI args: -port, -pluginUUID, -registerEvent, -info. Parse them with RegistrationParameters.fromArgs, connect, and react to events.

import 'dart:convert';
import 'dart:io';

import 'package:streamdeck_client/streamdeck_client.dart';

Future<void> main(List<String> args) async {
  final client = Client(RegistrationParameters.fromArgs(args));

  // The Stream Deck app relaunches the plugin, so exit when the socket closes.
  client.state.where((state) => state == ClientState.disconnected).skip(1).listen((_) => exit(1));

  await client.connect();

  // Track which actions are visible on the device.
  client.actions.listen((actions) {
    for (final action in actions.values) {
      print('Active: ${action.action} at '
          '(${action.payload.coordinates.column}, '
          '${action.payload.coordinates.row})');
    }
  });

  // Listen to all events. StreamDeckEvent is sealed, so listing every event
  // without a default lets the compiler flag new ones.
  client.events.listen((event) {
    switch (event) {
      case WillAppearEvent():
        print('willAppear: ${event.action} controller=${event.payload.controller}');

      case WillDisappearEvent():
        print('willDisappear: ${event.context}');

      case KeyDownEvent():
        client.forAction(event.context).showAlert();

      case KeyUpEvent(:final payload):
        print('keyUp: state=${payload.state}');

      case DialRotateEvent(:final payload):
        print('dialRotate: ${payload.ticks} ticks');

      case TouchTapEvent(:final payload):
        print('touchTap: pos=${payload.tapPos}');

      case DidReceiveSettingsEvent(:final payload):
        print('settings: ${jsonEncode(payload.settings)}');

      default:
        break;
    }
  });
}

Client and ActionClient #

Client holds the connection and the plugin-wide commands: getGlobalSettings, setGlobalSettings, getSecrets, openUrl, logMessage, switchToProfile.

ActionClient talks to one action. Get one with client.forAction(context):

final action = client.forAction('some-context-id');

action.events.listen((event) {
  if (event case KeyDownEvent()) {
    action.setSettings(settings: {'count': 42});
    action.showOk();
  }
});

It has setImage, setFeedback, setSettings, getSettings, showAlert, showOk, setState, setResources, getResources, setTriggerDescription and sendToPropertyInspector. Use action.plugin to reach the Client.

Connection Lifecycle #

connect() → ClientState.connecting → ClientState.connected
                                           ↓ (socket closes)
                                     ClientState.disconnected

There is no reconnection. The Stream Deck app gives a plugin its port at launch and relaunches the plugin when needed, so exit when the socket closes. If connect() throws, the client goes back to disconnected and can try again.

client.state.listen((state) => print('State: $state'));

if (client.state.value == ClientState.connected) { ... }

Features #

  • Protocol coverage: all received events (keyDown, dialRotate, touchTap, willAppear, etc.) and most sent commands (setImage, setFeedback, setSettings, etc.). setTitle and setFeedbackLayout are not implemented.
  • Typed event models using freezed: toString, ==, hashCode, copyWith, fromJson/toJson. StreamDeckEvent and ActionEvent are sealed.
  • Names from Elgato's SDK where one exists: RegistrationParameters, RegistrationInfo, DeviceInfo, WillAppearEvent, Controller.
0
likes
130
points
46
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

Pure Dart client for the Elgato Stream Deck WebSocket protocol. Handles connection, reconnection, and event parsing.

Repository (GitHub)
View/report issues

Topics

#streamdeck #elgato #websocket

License

BSD-3-Clause (license)

Dependencies

freezed_annotation, json_annotation, logging, rxdart

More

Packages that depend on streamdeck_client