Transport constructor

Transport(
  1. dynamic sockets, [
  2. Map<String, int> recovery_options = C.recovery_options
])

Implementation

Transport(dynamic sockets,
    [Map<String, int> recovery_options = C.recovery_options]) {
  logger.debug('new()');

  status = C.STATUS_DISCONNECTED;

  // Current socket.
  socket = null;

  // Socket collection.
  _socketsMap = <Map<String, dynamic>>[];

  _recovery_options = recovery_options;
  _recover_attempts = 0;
  _recovery_timer = null;

  _close_requested = false;

  if (sockets == null) {
    throw Exceptions.TypeError('Invalid argument. null \'sockets\' argument');
  }

  if (sockets is! List) {
    sockets = <WebSocketInterface>[sockets];
  }

  sockets.forEach((dynamic socket) {
    if (!Socket.isSocket(socket)) {
      throw Exceptions.TypeError(
          'Invalid argument. invalid \'DartSIP.Socket\' instance');
    }

    if (socket.weight != null && socket.weight is! num) {
      throw Exceptions.TypeError(
          'Invalid argument. \'weight\' attribute is not a number');
    }

    _socketsMap.add(<String, dynamic>{
      'socket': socket,
      'weight': socket.weight ?? 0,
      'status': C.SOCKET_STATUS_READY
    });
  });

  // Get the socket with higher weight.
  _getSocket();
}