start method

  1. @override
void start()
override

Start listening for incoming clients.

Implementation

@override
void start() {
  clientStream.listen((client) {
    var peer = _peer = json_rpc_2.Peer(client);

    peer.registerMethod('publish', (json_rpc_2.Parameters params) async {
      var requestId = params['request_id'].asString;
      var clientId = _getClientId(params);
      var eventName = params['event_name'].asString;
      var value = params['value'].value;
      var rq = _JsonRpc2PublishRequestImpl(
          requestId, clientId, eventName, value, peer);
      _onPublish.add(rq);
    });

    peer.registerMethod('subscribe', (json_rpc_2.Parameters params) async {
      var requestId = params['request_id'].asString;
      var clientId = _getClientId(params);
      var eventName = params['event_name'].asString;
      var rq = _JsonRpc2SubscriptionRequestImpl(
          clientId, eventName, requestId, peer, _uuid);
      _onSubscribe.add(rq);
    });

    peer.registerMethod('unsubscribe', (json_rpc_2.Parameters params) async {
      var requestId = params['request_id'].asString;
      var clientId = _getClientId(params);
      var subscriptionId = params['subscription_id'].asString;
      var rq = _JsonRpc2UnsubscriptionRequestImpl(
          clientId, subscriptionId, peer, requestId);
      _onUnsubscribe.add(rq);
    });

    peer.listen();
  });
}