subscribe method
Sends a subscription request for event
to the LCU. When that event is recieved in the future subscription
is launched.
behavior
and subscription
are optional parameters for complex logic flows where you want to send multiple events through one subscription
behavior
is a shortcut to passing itself to the subscription constructor.
subscription
, if null, is created and returned from the function. Else, it is returned from the function as is.
Implementation
EventSubscription subscribe(String event,
{EventSubscription? subscription, Handler? behavior}) {
EventSubscription _subscription = subscription ??
(behavior != null ? EventSubscription(behavior) : EventSubscription());
this._subscriptions.update(event, (list) => list + [_subscription],
ifAbsent: () {
this._websocket.add('[${EventCode.SUBSCRIBE}, "$event"]');
return [_subscription];
});
return _subscription;
}