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;
});
})
..onError(handler: ({required Error error}) {
print('error received! $error');
if (error 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.
- Implemented types
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 -
override
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
offConnection(
{required HostConnectionHandler handler}) → void -
inherited
-
offDiagnostic(
{required DiagnosticHandler handler}) → void -
inherited
-
offError(
{required ErrorHandler handler}) → void -
inherited
-
offReady(
{required HostReadyHandler handler}) → void -
inherited
-
onceConnection(
{required HostConnectionHandler handler}) → void -
inherited
-
onceDiagnostic(
{required DiagnosticHandler handler}) → void -
inherited
-
onceError(
{required ErrorHandler handler}) → void -
inherited
-
onceReady(
{required HostReadyHandler handler}) → void -
inherited
-
onConnection(
{required HostConnectionHandler handler}) → StreamSubscription< Map< HostEventType, dynamic> > -
inherited
-
onDiagnostic(
{required DiagnosticHandler handler}) → StreamSubscription< Map< HostEventType, dynamic> > -
inherited
-
onError(
{required ErrorHandler 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