call method

Stream<Result> call(
  1. String procedure, {
  2. List? arguments,
  3. Map<String, dynamic>? argumentsKeywords,
  4. CallOptions? options,
  5. Completer<String>? cancelCompleter,
})

This calls a procedure with the given arguments and/or argumentsKeywords with the given options. The WAMP router will either respond with one or more results or the caller may cancel the call by calling cancelCompleter.complete().

Implementation

Stream<Result> call(String procedure,
    {List<dynamic>? arguments,
    Map<String, dynamic>? argumentsKeywords,
    CallOptions? options,
    Completer<String>? cancelCompleter}) async* {
  var callArguments = arguments;
  var callArgumentsKeywords = argumentsKeywords;

  if (options?.pptScheme == 'wamp') {
    // It's E2EE payload
    callArguments =
        E2EEPayload.packE2EEPayload(arguments, argumentsKeywords, options!);
    callArgumentsKeywords = null;
  } else if (options?.pptScheme != null) {
    // It's some variation of PPT
    callArguments =
        PPTPayload.packPPTPayload(arguments, argumentsKeywords, options!);
    callArgumentsKeywords = null;
  }

  var call = Call(nextCallId++, procedure,
      arguments: callArguments,
      argumentsKeywords: callArgumentsKeywords,
      options: options);
  _transport.send(call);
  if (cancelCompleter != null) {
    unawaited(cancelCompleter.future.then((cancelMode) {
      CancelOptions? options;
      if (CancelOptions.modeKillNoWait == cancelMode ||
          CancelOptions.modeKill == cancelMode ||
          CancelOptions.modeSkip == cancelMode) {
        options = CancelOptions();
        options.mode = cancelMode;
      }
      var cancel = Cancel(call.requestId, options: options);
      _transport.send(cancel);
    }));
  }
  await for (AbstractMessageWithPayload result
      in _openSessionStreamController.stream.where((message) =>
          (message is Result && message.callRequestId == call.requestId) ||
          (message is Error &&
              message.requestTypeId == MessageTypes.codeCall &&
              message.requestId == call.requestId))) {
    if (result is Result) {
      yield result;
      if (!result.isProgressive()) {
        break;
      }
    } else if (result is Error) {
      throw result;
    }
  }
}