@@ -100,7 +100,13 @@ private AudioTrack createAudioTrack(ReadableMap constraints) {
100100
101101 String id = UUID .randomUUID ().toString ();
102102 PeerConnectionFactory pcFactory = webRTCModule .mFactory ;
103- AudioSource audioSource = pcFactory .createAudioSource (webRTCModule .constraintsForOptions (audioConstraintsMap ));
103+ MediaConstraints peerConstraints = webRTCModule .constraintsForOptions (audioConstraintsMap );
104+
105+ //PeerConnectionFactory.createAudioSource will throw an error when mandatory constraints contain nulls.
106+ //so, let's check for nulls
107+ checkMandatoryConstraints (peerConstraints );
108+
109+ AudioSource audioSource = pcFactory .createAudioSource (peerConstraints );
104110 AudioTrack track = pcFactory .createAudioTrack (id , audioSource );
105111 tracks .put (
106112 id ,
@@ -109,6 +115,22 @@ private AudioTrack createAudioTrack(ReadableMap constraints) {
109115 return track ;
110116 }
111117
118+ private void checkMandatoryConstraints (MediaConstraints peerConstraints ) {
119+ ArrayList <MediaConstraints .KeyValuePair > valid = new ArrayList <>(peerConstraints .mandatory .size ());
120+
121+ for (MediaConstraints .KeyValuePair constraint : peerConstraints .mandatory ) {
122+ if (constraint .getValue () != null ) {
123+ valid .add (constraint );
124+ } else {
125+ Log .d (TAG , String .format ("constraint %s is null, ignoring it" ,
126+ constraint .getKey ()));
127+ }
128+ }
129+
130+ peerConstraints .mandatory .clear ();
131+ peerConstraints .mandatory .addAll (valid );
132+ }
133+
112134 ReadableArray enumerateDevices () {
113135 WritableArray array = Arguments .createArray ();
114136 String [] devices = cameraEnumerator .getDeviceNames ();
0 commit comments