UhstHost class
UhstHost in UHST is a peer which every other peer (UhstSocket) connects to. This concept is similar to listen-server in multiplayer games.
UhstHost used to:
- listen messages from UhstSocket
- broadcast messages to all subscsribed Client UhstSocket
The simplest way to create a new host is:
var host = uhst.host("testHost");
host?.disconnect();
host = uhst?.host(hostId: _hostIdController.text);
host
?..onReady(handler: ({required String hostId}) {
setState(() {
hostMessages.add('Host Ready! Using $hostId');
print('host is ready!');
_hostIdController.text = hostId;
});
})
..onException(handler: ({required dynamic exception}) {
print('exception received! $exception');
if (exception is HostIdAlreadyInUse) {
// this is expected if you refresh the page
// connection is still alive on the meeting point
// just need to wait
setState(() {
hostMessages
.add('HostId already in use, retrying in 15 seconds...!');
});
} else {
setState(() {
hostMessages.add(error.toString());
});
}
})
..onConnection(handler: ({required UhstSocket uhstSocket}) {
uhstSocket.onDiagnostic(handler: ({required String message}) {
setState(() {
hostMessages.add(message);
});
});
uhstSocket.onMessage(handler: ({required message}) {
setState(() {
hostMessages.add("Host received: ${message.toString()}");
host?.broadcastString(message: message);
});
});
uhstSocket.onOpen(handler: () {
// uhstSocket.sendString(message: 'Host sent message!');
});
});
Note that your requested host id may not be accepted
by the signalling server, you should always use the hostId
you get after receiving a UhstHost().onReady()
event
when connecting to the host.
!Important
Remember to call .dispose()
to cancel all subscriptions and
disconnect host socket from server, client from host.
In Flutter you can add such methods in dispose override.
@override
void dispose() {
client?.dispose();
host?.dispose();
super.dispose();
}
- Implemented types
Constructors
- UhstHost.create({required UhstRelayClient relayClient, required UhstSocketProvider socketProvider, required bool debug, String? hostId})
-
Public factory
factory
Properties
Methods
-
broadcastArrayBuffer(
{required ByteBuffer arrayBuffer}) → void -
same as sendByteBufer as ByteBufer == ArrayBuffer
override
-
broadcastArrayBufferView(
{required TypedData arrayBufferView}) → void -
same as sendTypedData as TypedData == ArrayBufferView
override
-
broadcastBlob(
{required Blob blob}) → void -
override
-
broadcastByteBufer(
{required ByteBuffer byteBuffer}) → void -
ByteBufer == ArrayBuffer
see https://github.com/dart-lang/sdk/issues/12688
override
-
broadcastString(
{required String message}) → void -
override
-
broadcastTypedData(
{required TypedData typedData}) → void -
TypedData == ArrayBufferView
override
-
disconnect(
) → 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
-
offConnection(
{required HostConnectionHandler handler}) → void -
inherited
-
offDiagnostic(
{required DiagnosticHandler handler}) → void -
inherited
-
offException(
{required ExceptionHandler handler}) → void -
inherited
-
offReady(
{required HostReadyHandler handler}) → void -
inherited
-
onceClose(
{required CloseHandler handler}) → void -
inherited
-
onceConnection(
{required HostConnectionHandler handler}) → void -
inherited
-
onceDiagnostic(
{required DiagnosticHandler handler}) → void -
inherited
-
onceException(
{required ExceptionHandler handler}) → void -
inherited
-
onceReady(
{required HostReadyHandler handler}) → void -
inherited
-
onClose(
{required CloseHandler handler}) → StreamSubscription< Map< HostEventType, dynamic> > -
inherited
-
onConnection(
{required HostConnectionHandler handler}) → StreamSubscription< Map< HostEventType, dynamic> > -
inherited
-
onDiagnostic(
{required DiagnosticHandler handler}) → StreamSubscription< Map< HostEventType, dynamic> > -
inherited
-
onException(
{required ExceptionHandler handler}) → StreamSubscription< Map< HostEventType, dynamic> > -
inherited
-
onReady(
{required HostReadyHandler handler}) → StreamSubscription< Map< HostEventType, dynamic> > -
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited