getHttpUrlFromWebSocketUrl method

Uri getHttpUrlFromWebSocketUrl(
  1. String relayUrl
)

Changes the protocol of a websocket url to http.

Implementation

Uri getHttpUrlFromWebSocketUrl(String relayUrl) {
  assert(
    relayUrl.startsWith('ws://') || relayUrl.startsWith('wss://'),
    'invalid relay url',
  );

  try {
    var removeWebsocketSign = relayUrl.replaceFirst('ws://', 'http://');
    removeWebsocketSign =
        removeWebsocketSign.replaceFirst('wss://', 'https://');
    return Uri.parse(removeWebsocketSign);
  } catch (e) {
    utils.log(
      'error while getting http url from websocket url: $relayUrl',
      e,
    );

    rethrow;
  }
}