openClient method

  1. @override
Future<int> openClient(
  1. String host,
  2. AppInfo appInfo,
  3. Function notification
)
override

Piggyback Capture's openClient and use parameters and interfaces unique to http connections Implement JSON Rpc protocols.

Implementation

@override

/// Piggyback Capture's openClient and use parameters and interfaces unique to http connections
/// Implement JSON Rpc protocols.
Future<int> openClient(
    String host, AppInfo appInfo, Function notification) async {
  final JRpcRequest jsonRpc =
      JRpcRequest(id: _getJsonRpcId(), method: 'openclient', params: appInfo);

  final RegExp exp = RegExp(r'(http|ftp|https):');
  this.host = '$host/Capture/v1/api';
  hostWebsocket = host.replaceAll(exp, 'ws:');

  onEventNotification = notification as void Function(dynamic p1, int p2)?;

  try {
    final JRpcResponse response = await sendRequest(jsonRpc);
    final CaptureResult? result = response.captureResult;
    if (result != null) {
      return result.handle;
    } else {
      throw CaptureException(SktErrors.ESKT_NOERROR, 'No error.');
    }
  } on CaptureException {
    rethrow;
  } catch (ex) {
    throw CaptureException(SktErrors.ESKT_COMMUNICATIONERROR,
        'There was an error during communication.', ex.toString());
  }
}