Class WsConnection

java.lang.Object
com.alibaba.dashscope.transport.ws.WsConnection
All Implemented Interfaces:
AutoCloseable

public final class WsConnection extends Object implements AutoCloseable
A shared physical WebSocket multiplexing many tasks by header.task_id (audio design §7). One daemon reader thread (dashscope-ws-reader) demuxes inbound frames into per-task queues; user threads block on WsConnection.TaskHandle.recv(java.time.Duration). Binary frames carry no task id: the uplink is claimed by the first task to sendBinary, the downlink by claimBinaryDownlink(java.lang.String) (or implicitly when exactly one task is active). Viable mix: one ASR uplink + one TTS downlink + any number of pure-JSON tasks; two concurrent binary streams on one connection raise sdk.ws.BinaryOwnerConflict.
  • Constructor Details

  • Method Details

    • attach

      public WsConnection.TaskHandle attach(String taskId)
      Register a task on this connection. Duplicate task_id / connection already closed (by either side) → sdk.ws.IllegalState.
    • claimBinaryDownlink

      public void claimBinaryDownlink(String taskId)
      Explicitly claim the binary downlink for a task (TTS start does this automatically).
    • claimBinaryUplink

      public void claimBinaryUplink(String taskId)
      Explicitly claim the binary uplink before the first frame (ASR start does this).
    • close

      public void close()
      Broadcasts a connection-closed failure to all unfinished tasks and joins the reader (2s).
      Specified by:
      close in interface AutoCloseable