sendMessage function

Future<void> sendMessage(
  1. Logger? logger,
  2. String transportName,
  3. SignalRHttpClient httpClient,
  4. String? url,
  5. AccessTokenFactory? accessTokenFactory,
  6. Object content,
  7. bool logMessageContent,
)

Implementation

Future<void> sendMessage(
    Logger? logger,
    String transportName,
    SignalRHttpClient httpClient,
    String? url,
    AccessTokenFactory? accessTokenFactory,
    Object content,
    bool logMessageContent) async {
  MessageHeaders headers = MessageHeaders();
  if (accessTokenFactory != null) {
    final token = await accessTokenFactory();
    if (!isStringEmpty(token)) {
      headers.setHeaderValue("Authorization", "Bearer $token");
    }
  }

  // logger.log(LogLevel.Trace, `(${transportName} transport) sending data. ${getDataDetail(content, logMessageContent)}.`);
  logger?.finest("($transportName transport) sending data.");

  //final responseType = content is String ? "arraybuffer" : "text";
  SignalRHttpRequest req =
      SignalRHttpRequest(content: content, headers: headers);
  final response = await httpClient.post(url, options: req);

  logger?.finest(
      "($transportName transport) request complete. Response status: ${response.statusCode}.");
}