startConnection method

void startConnection(
  1. dynamic options
)

Returns a PeerConnection object set up correctly (for data, media).

Implementation

void startConnection(dynamic options) async {
  final peerConnection = await _startPeerConnection();

  // Set the connection's PC.
  connection.peerConnection = peerConnection;

  if (connection.type == ConnectionType.Media.value && options['_stream'] != null) {
    _addTracksToConnection(options['_stream'], peerConnection);
  }

  // What do we need to do now?
  if (options?['originator'] == true) {
    final dataConnection = connection as DataConnection;

    final config = RTCDataChannelInit()..ordered = options['reliable'] ?? false;

    final dataChannel = await peerConnection.createDataChannel(
      dataConnection.label,
      config,
    );
    dataConnection.initializeDataChannel(dataChannel);

    _makeOffer();
  } else {
    handleSDP('OFFER', options['sdp']);
  }
}