WebSocket classabstract
A two-way HTTP communication object for client or server applications.
The stream exposes the messages received. A text message will be of typeString and a binary message will be of typeList<int>.
- Implemented types
Constructors
- WebSocket()
- WebSocket.fromUpgradedSocket(Socketsocket, {String?protocol,bool?serverSide,CompressionOptionscompression =CompressionOptions.compressionDefault})
- Creates a WebSocket from an already-upgraded socket.factory
Properties
- closeCode→int?
- The close code set when the WebSocket connection is closed. Ifthere is no close code available this property will be
nullno setter - closeReason→String?
- The close reason set when the WebSocket connection is closed. Ifthere is no close reason available this property will be
nullno setter - done→Future
- Return a future which is completed when theStreamSink is finished.no setterinherited
- extensions→String
- The extensions property is initially the empty string. After theWebSocket connection is established this string reflects theextensions used by the server.no setter
- first→Future
- The first element of this stream.no setterinherited
- hashCode→int
- The hash code for this object.no setterinherited
- isBroadcast→bool
- Whether this stream is a broadcast stream.no setterinherited
- isEmpty→Future<
bool> - Whether this stream contains any elements.no setterinherited
- last→Future
- The last element of this stream.no setterinherited
- length→Future<
int> - The number of elements in this stream.no setterinherited
- pingInterval↔Duration?
- The interval between ping signals.getter/setter pair
- protocol→String?
- The protocol property is initially the empty string. After theWebSocket connection is established the value is the subprotocolselected by the server. If no subprotocol is negotiated thevalue will remain
null.no setter - readyState→int
- Returns the current state of the connection.no setter
- runtimeType→Type
- A representation of the runtime type of the object.no setterinherited
- single→Future
- The single element of this stream.no setterinherited
Methods
- add(
dynamicdata)→ void - Sends data on the WebSocket connection. The data in
datamustbe either aString, or aList<int>holding bytes.override - addError(
Objecterror, [StackTrace?stackTrace])→ void - Adds an
errorto the sink.inherited - addStream(
Streamstream)→Future - Sends data from a stream on WebSocket connection. Each data event from
streamwill be send as a single WebSocket frame. The data fromstreammust be eitherStrings, orList<int>s holding bytes.override - addUtf8Text(
List< int> bytes)→ void - Sends a text message with the text represented by
bytes. - any(
booltest(dynamicelement))→Future< bool> - Checks whether
testaccepts any element provided by this stream.inherited - asBroadcastStream(
{voidonListen(StreamSubscriptionsubscription)?,voidonCancel(StreamSubscriptionsubscription)?})→Stream - Returns a multi-subscription stream that produces the same events as this.inherited
- asyncExpand<
E> (Stream< E> ?convert(dynamicevent))→Stream<E> - Transforms each element into a sequence of asynchronous events.inherited
- asyncMap<
E> (FutureOr< E> convert(dynamicevent))→Stream<E> - Creates a new stream with each data event of this stream asynchronouslymapped to a new event.inherited
- cast<
R> ()→Stream< R> - Adapt this stream to be a
Stream<R>.inherited - close(
[int?code,String?reason])→Future - Closes the WebSocket connection. Set the optional
codeandreasonarguments to send close information to the remote peer. If they areomitted, the peer will seeWebSocketStatus.noStatusReceived codewith no reason.override - contains(
Object?needle)→Future< bool> - Returns whether
needleoccurs in the elements provided by this stream.inherited - distinct(
[boolequals(dynamicprevious,dynamicnext)?])→Stream - Skips data events if they are equal to the previous data event.inherited
- drain<
E> ([E?futureValue])→Future< E> - Discards all data on this stream, but signals when it is done or an erroroccurred.inherited
- elementAt(
intindex)→Future - Returns the value of the
indexth data event of this stream.inherited - every(
booltest(dynamicelement))→Future< bool> - Checks whether
testaccepts all elements provided by this stream.inherited - expand<
S> (Iterable< S> convert(dynamicelement))→Stream<S> - Transforms each element of this stream into a sequence of elements.inherited
- firstWhere(
booltest(dynamicelement), {dynamicorElse()?})→Future - Finds the first element of this stream matching
test.inherited - fold<
S> (SinitialValue,Scombine(Sprevious,dynamicelement))→Future< S> - Combines a sequence of values by repeatedly applying
combine.inherited - forEach(
voidaction(dynamicelement))→Future< void> - Executes
actionon each element of this stream.inherited - handleError(
FunctiononError, {booltest(dynamicerror)?})→Stream - Creates a wrapper Stream that intercepts some errors from this stream.inherited
- join(
[Stringseparator =""])→Future< String> - Combines the string representation of elements into a single string.inherited
- lastWhere(
booltest(dynamicelement), {dynamicorElse()?})→Future - Finds the last element in this stream matching
test.inherited - listen(
voidonData(dynamicevent)?, {Function?onError,voidonDone()?,bool?cancelOnError})→StreamSubscription - Adds a subscription to this stream.inherited
- map<
S> (Sconvert(dynamicevent))→Stream< S> - Transforms each element of this stream into a new stream event.inherited
- noSuchMethod(
Invocationinvocation)→ dynamic - Invoked when a nonexistent method or property is accessed.inherited
- pipe(
StreamConsumerstreamConsumer)→Future - Pipes the events of this stream into
streamConsumer.inherited - reduce(
dynamiccombine(dynamicprevious,dynamicelement))→Future - Combines a sequence of values by repeatedly applying
combine.inherited - singleWhere(
booltest(dynamicelement), {dynamicorElse()?})→Future - Finds the single element in this stream matching
test.inherited - skip(
intcount)→Stream - Skips the first
countdata events from this stream.inherited - skipWhile(
booltest(dynamicelement))→Stream - Skip data events from this stream while they are matched by
test.inherited - take(
intcount)→Stream - Provides at most the first
countdata events of this stream.inherited - takeWhile(
booltest(dynamicelement))→Stream - Forwards data events while
testis successful.inherited - timeout(
DurationtimeLimit, {voidonTimeout(EventSinksink)?})→Stream - Creates a new stream with the same events as this stream.inherited
- toList(
)→Future< List> - Collects all elements of this stream in aList.inherited
- toSet(
)→Future< Set> - Collects the data of this stream in aSet.inherited
- toString(
)→String - A string representation of this object.inherited
- transform<
S> (StreamTransformer< dynamic,S> streamTransformer)→Stream<S> - Applies
streamTransformerto this stream.inherited - where(
booltest(dynamicevent))→Stream - Creates a new stream from this stream that discards some elements.inherited
Operators
- operator ==(
Objectother)→bool - The equality operator.inherited
Static Properties
Static Methods
- connect(
Stringurl, {Iterable< String> ?protocols,Map<String,dynamic> ?headers,CompressionOptionscompression =CompressionOptions.compressionDefault,HttpClient?customClient})→Future<WebSocket> - Create a new WebSocket connection. The URL supplied in
urlmust use the schemewsorwss.