Skip to content

Refactor: Extract shared WebSocket lifecycle from Gateway/Node clients #63

@shanselman

Description

@shanselman

OpenClawGatewayClient and WindowsNodeClient share ~200 lines of duplicated WebSocket lifecycle code:

After PR #62, the two clients are closer in quality but still duplicate the connection lifecycle.

Proposed approach

Extract shared WebSocket lifecycle into a base class or helper, parameterized by:

  • Buffer size (16KB for Gateway, 64KB for Node)
  • Message processing (sync ProcessMessage vs async ProcessMessageAsync)
  • Post-connect setup (Gateway resets unsupported method flags)
  • Connection state tracking (Gateway uses _pendingRequests, Node uses _isConnected)

Complexity

Moderate-to-high. The two clients have diverged enough that a naive base class extraction risks subtle regressions. Recommend extracting incrementally (e.g., ConnectAsync setup first, then SendRawAsync, then listen loop).

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions