RelaySocket class
UhstSocket is similar to the HTML5 WebSocket interface, but instead of a dedicated server, one peer acts as a host for other peers to join.
Once a client and a host have connected they can exchange messages asynchronously.
UhstSocket used to:
To connect to a host from another browser use the same hostId
you received after UhstSocket().onReady()
event:
var client = uhst.join("testHost");
client?.close();
client
?..onOpen(handler: () {
setState(() {
client?.sendString(message: 'Hello host!');
});
})
..onMessage(handler: ({required message}) {
setState(() {
clientMessages.add('Client received: $message');
});
})
..onException(handler: ({required dynamic exception}) {
if (exception is InvalidHostId || exception is InvalidClientOrHostId) {
setState(() {
clientMessages.add('Invalid hostId!');
});
} else {
setState(() {
clientMessages.add(exception.toString());
});
}
})
..onDiagnostic(handler: ({required String message}) {
setState(() {
clientMessages.add(message);
});
});
The UHST client interface is similar to the HTML5 WebSocket interface, but instead of a dedicated server, one peer acts as a host for other peers to join.
Once a client and a host have connected they can exchange messages asynchronously. Arbitrary number of clients can connect to the same host but clients cannot send messages to each other, they can only communicate with the host.
- Implemented types
Constructors
- RelaySocket.create({required UhstRelayClient relayClient, required bool debug, ClientSocketParams? clientParams, HostSocketParams? hostParams})
-
factory
Properties
Methods
-
close(
) → void -
This method is using to close EventSource.
Before close will be fired onClose onceClose
will be called, if any provided
override
-
dispose(
) → void -
This method should be called during dispose method in Flutter widget
or any another cases that require to cancel all subscriptions and
all methods
override
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
offClose(
{required CloseHandler handler}) → void -
inherited
-
offDiagnostic(
{required DiagnosticHandler handler}) → void -
inherited
-
offException(
{required ExceptionHandler handler}) → void -
inherited
-
offMessage(
{required MessageHandler handler}) → void -
inherited
-
offOpen(
{required OpenHandler handler}) → void -
inherited
-
onceClose(
{required CloseHandler handler}) → void -
inherited
-
onceDiagnostic(
{required DiagnosticHandler handler}) → void -
inherited
-
onceException(
{required ExceptionHandler handler}) → void -
inherited
-
onceMessage(
{required MessageHandler handler}) → void -
inherited
-
onceOpen(
{required OpenHandler handler}) → void -
inherited
-
onClientMessage(
{required Message message}) → void -
override
-
onClose(
{required CloseHandler handler}) → StreamSubscription< Map< UhstSocketEventType, dynamic> > -
inherited
-
onDiagnostic(
{required DiagnosticHandler handler}) → StreamSubscription< Map< UhstSocketEventType, dynamic> > -
inherited
-
onException(
{required ExceptionHandler handler}) → StreamSubscription< Map< UhstSocketEventType, dynamic> > -
inherited
-
onMessage(
{required MessageHandler handler}) → StreamSubscription< Map< UhstSocketEventType, dynamic> > -
inherited
-
onOpen(
{required OpenHandler handler}) → StreamSubscription< Map< UhstSocketEventType, dynamic> > -
inherited
-
sendArrayBuffer(
{required ByteBuffer arrayBuffer}) → void -
same as sendByteBufer as ByteBufer == ArrayBuffer
override
-
sendArrayBufferView(
{required TypedData arrayBufferView}) → void -
same as sendTypedData as TypedData == ArrayBufferView
override
-
sendBlob(
{required Blob blob}) → void -
override
-
sendByteBufer(
{required ByteBuffer byteBuffer}) → void -
ByteBufer == ArrayBuffer
see https://github.com/dart-lang/sdk/issues/12688
override
-
sendString(
{required String message}) → void -
override
-
sendTypedData(
{required TypedData typedData}) → void -
TypedData == ArrayBufferView
override
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited