MockWebSocket class final
One connection opened through a MockWebSocketTransport: the client uses it as its WebSocketSession, and the test plays the server with the other members.
The test reads what the client sent (sent, sentJson, onSent), sends it messages (push, pushJson) and ends the connection cleanly (closeFromServer) or abruptly (drop).
final server = await sockets.nextConnection;
expect(server.headers['Authorization'], 'Bearer t0k3n');
server.push('welcome');
await server.closeFromServer(CloseStatus.goingAway);
- Implemented types
Properties
- acceptedProtocol → String?
-
The subprotocol the two sides agreed on in the handshake, or
nullwhen none was asked for or accepted.no setteroverride - closedByClient → bool
-
Whether the client closed it (rather than the test, with
closeFromServer or drop).
no setter
- closeStatus → CloseStatus?
-
How the connection was closed, by either side: the code and reason
of the close frame.
nullwhile it is open.no setteroverride - hashCode → int
-
The hash code for this object.
no setterinherited
- headers → HttpHeaders
-
The headers the client sent with the handshake (a copy).
final
- isClosed → bool
-
Whether the connection is closed, by either side.
no setter
- isOpen → bool
-
Whether messages can still be sent:
falseonce either side has started to close the connection.no setteroverride -
messages
→ Stream<
Object> -
The incoming messages: a
Stringfor each text frame, aUint8Listfor each binary one. It can be listened to once, and it is done when the connection closes, whichever side closed it.no setteroverride -
onSent
→ Stream<
Object> -
Each message the client sends from now on, as it is sent; ends when
the connection closes. Use it to wait for a message.
no setter
-
protocols
→ List<
String> -
The sub-protocols the client offered, in order; the first one is
taken as the acceptedProtocol.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
sent
→ List<
Object> -
Every message the client sent, in order: a
Stringfor a text message, aUint8Listfor a binary one.no setter -
sentJson
→ List<
Object?> -
The text messages the client sent that are JSON, decoded. Other text
and binary messages are left out (see sent), and so is a message
that is the JSON
null.no setter - uri → Uri
-
The URL the client connected to.
final
Methods
-
close(
[CloseStatus status = CloseStatus.normal]) → Future< void> -
Closes the connection, sending
status(CloseStatus.normal by default) to the other side. The future completes when the connection is closed.override -
closeFromServer(
[CloseStatus status = CloseStatus.normal]) → Future< void> -
Closes the connection as the server would, with
status(1000, normal, by default); the client sees it as a clean close. -
drop(
) → Future< void> - Loses the connection without a close handshake, as a network failure does: the close status is CloseStatus.noCloseFrame (1006). Use it to test that the client reconnects.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
push(
Object message) → void -
Sends the client a text (
String) or binary (List<int>) message, as the server would. Throws aStateErroronce the connection is closed. -
pushJson(
Object? json) → void -
Sends the client
json, encoded, as a text message. -
sendMessage(
Object message) → void -
Sends
messageas a text frame when it is aString, or as a binary frame when it is aList<int>. Throws a WebSocketException when the session is no longer open, and an ArgumentError for any other type. It does not wait for the frame to leave: the message waits in memory until the network takes it. Ondart:ioa session whose other side takes nothing gives up past its limits (512 KB waiting, or 10 seconds) and drops the connection, andIoWebSocketSession.flushwaits until what was sent has left; seeIoWebSocketSession.override -
toString(
) → String -
A string representation of this object.
override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited