WebSocketInterface constructor

WebSocketInterface(
  1. String url, [
  2. WebSocketSettings? webSocketSettings
])

Implementation

WebSocketInterface(String url, [WebSocketSettings? webSocketSettings]) {
  logger.debug('new() [url:' + url + ']');
  _url = url;
  dynamic parsed_url = Grammar.parse(url, 'absoluteURI');
  if (parsed_url == -1) {
    logger.error('invalid WebSocket URI: $url');
    throw AssertionError('Invalid argument: $url');
  } else if (parsed_url.scheme != 'wss' && parsed_url.scheme != 'ws') {
    logger.error('invalid WebSocket URI scheme: ${parsed_url.scheme}');
    throw AssertionError('Invalid argument: $url');
  } else {
    String transport_scheme = webSocketSettings != null &&
            webSocketSettings.transport_scheme != null
        ? webSocketSettings.transport_scheme!.toLowerCase()
        : parsed_url.scheme;

    String port = parsed_url.port != null ? ':${parsed_url.port}' : '';
    _sip_uri = 'sip:${parsed_url.host}$port;transport=$transport_scheme';
    logger.debug('SIP URI: $_sip_uri');
    _via_transport = transport_scheme.toUpperCase();
  }
  _webSocketSettings = webSocketSettings ?? WebSocketSettings();
}