toString method

  1. @override
String toString()
override

A string representation of this object.

Some classes have a default textual representation, often paired with a static parse function (like int.parse). These classes will provide the textual representation as their string representation.

Other classes have no meaningful textual representation that a program will care about. Such classes will typically override toString to provide useful information when inspecting the object, mainly for debugging or logging.

Implementation

@override
String toString() {
  String msg = '${SipMethodHelper.getName(method)} $ruri SIP/2.0\r\n';

  headers.forEach((String? headerName, dynamic headerValues) {
    headerValues.forEach((dynamic value) {
      msg += '$headerName: $value\r\n';
    });
  });

  for (dynamic header in extraHeaders) {
    msg += '${header.trim()}\r\n';
  }

  // Supported.
  List<dynamic> supported = <dynamic>[];

  switch (method) {
    case SipMethod.REGISTER:
      supported.add('path');
      supported.add('gruu');
      break;
    case SipMethod.INVITE:
      if (ua!.configuration!.sessionTimers) {
        supported.add('timer');
      }
      if (ua!.contact!.pub_gruu != null || ua!.contact!.temp_gruu != null) {
        supported.add('gruu');
      }
      supported.add('ice');
      supported.add('replaces');
      break;
    case SipMethod.UPDATE:
      if (ua!.configuration!.sessionTimers) {
        supported.add('timer');
      }
      supported.add('ice');
      break;
    default:
      break;
  }

  supported.add('outbound');

  String userAgent = ua!.configuration!.userAgent;

  // Allow.
  msg += 'Allow: ${DartSIP_C.ALLOWED_METHODS}\r\n';
  msg += 'Supported: ${supported.join(',')}\r\n';
  msg += 'User-Agent: $userAgent\r\n';

  if (body != null) {
    logger.debug('Outgoing Message: ' + body!);
    //Here we should calculate the real content length for UTF8
    List<int> encoded = utf8.encode(body!);
    int length = encoded.length;
    msg += 'Content-Length: $length\r\n\r\n';
    msg += body!;
  } else {
    msg += 'Content-Length: 0\r\n\r\n';
  }

  return msg;
}