isSocket function

bool isSocket(
  1. dynamic socket
)

Implementation

bool isSocket(dynamic socket) {
  // Ignore if an array is given.
  if (socket is List) {
    return false;
  }

  if (socket == null) {
    logger.error('null DartSIP.Socket instance');
    return false;
  }

  // Check Properties.
  try {
    if (!Utils.isString(socket.url)) {
      logger.error('missing or invalid DartSIP.Socket url property');
      throw Error();
    }

    if (!Utils.isString(socket.via_transport)) {
      logger.error('missing or invalid DartSIP.Socket via_transport property');
      throw Error();
    }

    if (Grammar.parse(socket.sip_uri, 'SIP_URI') == -1) {
      logger.error('missing or invalid DartSIP.Socket sip_uri property');
      throw Error();
    }
  } catch (e) {
    return false;
  }

  if (socket is! Socket) {
    return false;
  }

  // Check Methods.
  if (socket.connect == null)
    return false;
  else if (socket.disconnect == null)
    return false;
  else if (socket.send == null) {
    return false;
  }

  return true;
}