Skip to content

A WebSocket and SSE API shared by WO and ng #90

Open

Description

@hugithordarson

WO apps get WebSockets and SSE from wo-adaptor-jetty-push (about 1,000 lines). ng should offer the same API so push code moves between the frameworks unchanged: one framework-neutral library both can use, with a thin shim on each side.

The neutral core (no framework dependency)

  • WebSocket session: send text or binary, close, attributes, remote address. WOWebSocketSession is already neutral apart from its name.
  • Handler: an interface with default no-op methods (onConnect, onTextMessage, onBinaryMessage, onClose, onError). It replaces the abstract WOWebSocketHandler.
    • application() isn't needed; both frameworks have a static one.
    • Heartbeat becomes a small utility instead of an executor in the base class.
  • Handshake: a small record (path, query, headers, cookies, remote address) passed to onConnect instead of a framework request.
  • SSE: SSEStream (event formatting, keep-alive, the blocking stream) and SSEHub. Both are neutral except SSEStream.response().
  • No registration mechanism: each framework maps endpoints its own way.

Both adaptors are on Jetty 12.1.13, so the Jetty WebSocket glue (listener, session wrapper) can be shared too.

WO shim (in wo-adaptor-jetty-push)

ng shim

  • WebSocket endpoints are routes: mapped in routes(), with the upgrade wired in ng-adaptor-jetty.
  • The handshake offers the request and its context, so context.session() ties a socket to a session.
  • An SSEStream → NGResponse adapter. It needs lengthless streaming responses (Streaming responses without a known length #89).
  • Remove the experimental Jakarta WebSocket support in ng-adaptor-jetty-servlet (NGWebSocketEndpoint) in favour of this.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions