Skip to content

List the messages of a WebSocket and of an event stream - #12

Merged
tonytonycoder11 merged 6 commits into
mainfrom
websocket-and-event-messages
Oct 24, 2026
Merged

tonytonycoder11 merged 6 commits into
mainfrom
websocket-and-event-messages

Conversation

@tonytonycoder11

Copy link
Copy Markdown
Contributor

A WebSocket used to end its call as soon as the upgrade went through, and an event stream was one long response body. Both are now conversations: the call stays open, lists its messages as they cross, and gets a Messages or Events tab.

WebSockets. The capture wraps the socket that dart:io detaches after the handshake and reads the frames of both directions from the bytes that cross it. Fragmented messages are joined, permessage-deflate messages are decompressed (with or without a window kept between messages, as the handshake agreed), and ping, pong and close frames are listed as messages of their own. A reader that meets bytes it cannot make sense of stops and says nothing more, and it never changes what the app reads or writes. The call ends when both sides have sent a close frame, when the other side stops sending, when the socket is destroyed or when it fails. It is not cancelled when the app closes the client that opened it, which apps do once the handshake is over.

Event streams. A text/event-stream response is parsed as it arrives, by the rules of the HTML standard, and each complete event becomes a message. The raw stream is still the body of the response.

What a call keeps. The latest thousand messages and a megabyte of payload, each message cut at maxBodyBytes, with the real size and the count of everything that came before. Text goes through the redaction like a body does. The address of a WebSocket is recorded as the app wrote it, wss://host/path, and not as the HTTP request the handshake is.

Where it shows:

  • A Messages or Events tab with a direction filter. It follows the newest message while the call runs, and a message opens in the body viewer, so a JSON message is a tree.
  • A badge in the list and a line in the overview.
  • The HAR export, with _webSocketMessages the way Chrome writes it and _eventSourceMessages for streams, and the text export.
  • The messages are kept on disk with the call and counted in the memory and disk budgets.

A WebSocket is not offered for sending again, because its handshake is not a request that stands alone.

One limit, written in the package README: dart:io makes one client for every WebSocket the first time one is opened, so a WebSocket opened before Flutwire.init is not seen. On the web nothing is recorded, because the browser opens WebSockets itself.

I tried it on an Android emulator with the example app, which has a new Streams section: a WebSocket against an echo server, with text, JSON and binary messages and the close frame, and an event stream from a public feed. All four suites pass, flutter analyze --fatal-infos is clean and the example builds for the web.

Targets 0.2.0, Tier 2, M16.

A WebSocket upgrade used to end the call at once. The capture now wraps the
detached socket and reads the frames in both directions, joining fragments,
decompressing permessage-deflate messages and listing ping, pong and close
frames as messages of their own. The call stays open until both sides have
said goodbye, the other side stops sending, or the socket is destroyed or
fails, and it keeps going when the app closes the client that opened it.

A text/event-stream response is parsed as it arrives, one event per blank
line. Either way a call keeps the latest thousand messages and a megabyte of
payload, applies the redaction to text, and counts all of them. The address
of a WebSocket is recorded as the app wrote it, with ws or wss.
The memory budget counts them, a finished call writes them next to its bodies
in a file of its own, a restart finds them again, and they are released and
read back with the bodies. A line a crash left damaged is skipped.
A Messages or Events tab lists each message with its direction, kind, size
and the moment it crossed, filters by direction, follows the newest while the
call runs, and opens a message in the viewer that fits its payload. The list
badges the call, the overview counts it, and a WebSocket is not offered for
sending again. English and Italian.
HAR carries a WebSocket as Chrome does, with the opcode of each frame, and
the events of a stream under their own key. The text export lists them with
their direction and offset.
@tonytonycoder11 tonytonycoder11 moved this to In progress in Flutwire Oct 24, 2026
@trueup-by-nacode-studios

Copy link
Copy Markdown

This pull request adds no capability the code did not already have.

38 files read · 2653 ms · against 36d8943 · engine 1.4.1

@tonytonycoder11
tonytonycoder11 merged commit 8bee0b0 into main Oct 24, 2026
6 checks passed
@tonytonycoder11
tonytonycoder11 deleted the websocket-and-event-messages branch October 24, 2026 10:40
@tonytonycoder11 tonytonycoder11 moved this from In progress to Shipped in Flutwire Oct 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Shipped

Development

Successfully merging this pull request may close these issues.

1 participant