Class WsSession

java.lang.Object
com.alibaba.dashscope.transport.ws.WsSession
All Implemented Interfaces:
TaskChannel, AutoCloseable

public final class WsSession extends Object implements TaskChannel
A single task over a dedicated WebSocket (audio design §3). No SDK-spawned threads: OkHttp's socket reader hands events into a queue and recv(java.time.Duration) blocks the caller's thread on it. Events whose task_id differs from this session's task are protocol errors.
  • Field Details

    • DEFAULT_CONNECT_TIMEOUT

      public static final Duration DEFAULT_CONNECT_TIMEOUT
      Handshake (ws upgrade) timeout; audio design §5.
  • Constructor Details

  • Method Details

    • taskId

      public String taskId()
      Specified by:
      taskId in interface TaskChannel
    • sendText

      public void sendText(String json)
      Description copied from interface: TaskChannel
      Send a text frame (already-serialized JSON). Full upstream queue → SdkException.
      Specified by:
      sendText in interface TaskChannel
    • sendBinary

      public void sendBinary(ByteBuffer data)
      Description copied from interface: TaskChannel
      Send a raw binary frame (no header; ownership rules apply on shared connections).
      Specified by:
      sendBinary in interface TaskChannel
    • recv

      public TaskEvent recv(Duration timeout)
      Description copied from interface: TaskChannel
      Next inbound item for this task, blocking up to timeout; null on timeout. FAILURE events throw their carried exception.
      Specified by:
      recv in interface TaskChannel
    • close

      public void close()
      Idempotent: graceful 1000 close. Safe to call from any thread, any number of times.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface TaskChannel
    • mapFailure

      public static RuntimeException mapFailure(Throwable t, okhttp3.Response response)
      Maps a websocket failure to the exception family; reused by the realtime session.