createPeerConnection function

Future<RTCPeerConnection> createPeerConnection (
  1. Map<String, dynamic> configuration,
  2. Map<String, dynamic> constraints
)

Implementation

Future<RTCPeerConnection> createPeerConnection(Map<String,dynamic> configuration, Map<String,dynamic> constraints) async {
  MethodChannel channel = WebRTC.methodChannel();

  Map<String, dynamic> defaultConstraints = {
      "mandatory": {},
      "optional": [
        {"DtlsSrtpKeyAgreement": true },
      ],
    };

    final Map<dynamic, dynamic> response = await channel.invokeMethod(
      'createPeerConnection',
      <String, dynamic>{
        'configuration': configuration,
        'constraints': constraints.length == 0? defaultConstraints : constraints
      },
    );

    String peerConnectionId = response['peerConnectionId'];
    return new RTCPeerConnection(peerConnectionId);
}