setup method

Future<void> setup({
  1. required Map<String, dynamic Function(List<Object?>? arg)> onFunctions,
  2. required dynamic endpoint,
  3. dynamic runLogger = false,
  4. required Function getAuthToken,
  5. dynamic onClose({
    1. Exception? error,
    })?,
  6. dynamic onReconnected({
    1. String? connectionId,
    })?,
  7. dynamic onReconnecting({
    1. Exception? error,
    })?,
  8. required Map<String, List<Object>> invokes,
})

Implementation

Future<void> setup(
    {required Map<String, Function(List<Object?>? arg)> onFunctions,
    required endpoint,
    runLogger = false,
    required Function getAuthToken,
    Function({Exception? error})? onClose,
    Function({String? connectionId})? onReconnected,
    Function({Exception? error})? onReconnecting,
    required Map<String, List<Object>> invokes}) async {
  _invokes = invokes;
  _wsConnection = HubConnectionBuilder()
      .withUrl(endpoint,
          options: HttpConnectionOptions(
              logger: _getLogger(runLogger),
              logMessageContent: true,
              requestTimeout: 10000,
              accessTokenFactory: () => Future.value(getAuthToken()),
              transport: HttpTransportType.WebSockets))
      .withAutomaticReconnect()
      .build();
  if (onClose != null) _wsConnection!.onclose(onClose);
  if (onReconnected != null) _wsConnection!.onreconnected(onReconnected);
  if (onReconnecting != null) _wsConnection!.onreconnecting(onReconnecting);
  connectToChannels(channels: onFunctions, invokes: invokes);
}