title: How can I use the constraints in native webrtc?
body: <p>I finally have an app that can make a connection with the other peer and both peers receive audio and video from the remote. It is an <code>iOS</code> app using the native <code>RTC</code> <code>API</code>. I am now trying out what I can do to improve the quality so I started looking for options in for the media constraints.  </p>
  
  <p>This is my initialization code:  </p>
  
  <pre><code>//init
  peerConnectionFactory = [[RTCPeerConnectionFactory alloc] init];
  [RTCPeerConnectionFactory initializeSSL];
  
  //set 2 arrays to be used for the media constraints
  NSMutableArray *m = [[NSMutableArray alloc] init];
  NSMutableArray *o = [[NSMutableArray alloc] init];
  
  //add stuff to the mandatory array
  [m addObject:[[RTCPair alloc] initWithKey:@"OfferToReceiveAudio" value:@"true"]];
  [m addObject:[[RTCPair alloc] initWithKey:@"OfferToReceiveVideo" value:@"true"]];
  
  //add stuff to the optional array
  //these lines are disabled for now, because my colleague working on the Android version does not support dtls yet
  //[o addObject:[[RTCPair alloc] initWithKey:@"internalSctpDataChannels" value:@"true"]];
  //[o addObject:[[RTCPair alloc] initWithKey:@"DtlsSrtpKeyAgreement" value:@"true"]];
  
  //use the 2 arrays to init the media constraints
  constraints = [[RTCMediaConstraints alloc] initWithMandatoryConstraints:m optionalConstraints:o];
  
  //init stun and turn servers
  RTCICEServer *turn = [[RTCICEServer alloc] initWithURI:[NSURL URLWithString:@"turn:numb.viagenie.ca:3478"] username:@"*" password:@"*"];
  RTCICEServer *stun = [[RTCICEServer alloc] initWithURI:[NSURL URLWithString:@"stun:stun.l.google.com:19302"] username:@"" password:@""];
  NSArray *iceServers = [[NSArray alloc] initWithObjects:turn, stun, nil];
  
  //init the peerconnection object
  peerConnection = [peerConnectionFactory peerConnectionWithICEServers:nil
                                                           constraints:constraints
                                                              delegate:self];
  </code></pre>
  
  <p>I tried to set the following RTCPairs:  </p>
  
  <p>First I tried these, just to see what it would do.</p>
  
  <pre><code>[o addObject:[[RTCPair alloc] initWithKey:@"minWidth" value:@"1280"]];
  [o addObject:[[RTCPair alloc] initWithKey:@"minHeight" value:@"720"]];
  </code></pre>
  
  <p>It did nothing.<br>
  Then I tried these lines (without the previous 2).</p>
  
  <pre><code>[m addObject:[[RTCPair alloc] initWithKey:@"minWidth" value:@"1280"]];
  [m addObject:[[RTCPair alloc] initWithKey:@"minHeight" value:@"720"]];
  </code></pre>
  
  <p>this causes the app to get stuck at generating ice candidates.<br>
  thinking the device might not support such high resolutions I tried the following.</p>
  
  <pre><code>[o addObject:[[RTCPair alloc] initWithKey:@"maxWidth" value:@"320"]];
  [o addObject:[[RTCPair alloc] initWithKey:@"maxHeight" value:@"180"]];
  </code></pre>
  
  <p>no effect again.  </p>
  
  <p>I tried some more combinations I can't remember, but to me it seems like adding anything except <code>OfferToReceiveAudio</code> and <code>OfferToReceiveVideo</code> to the mandatory array just breaks the entire process and adding anything to the optional array is ignored (although setting the <code>dtls</code> thing makes it impossible to connect to the <code>Android</code> version).</p>