You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
2.0 KiB

  1. var turnUrl = 'https://computeengineondemand.appspot.com/turn?username=93773443&key=4080218913';
  2. var turnDone = false;
  3. function maybeRequestTurn() {
  4. if (turnUrl == '') {
  5. turnDone = true;
  6. }
  7. for (var i = 0, len = configuration.iceServers.length; i < len; i++) {
  8. if (configuration.iceServers[i].url.substr(0, 5) === 'turn:') {
  9. turnDone = true;
  10. }
  11. }
  12. var currentDomain = document.domain;
  13. if (currentDomain.search('localhost') === -1 &&
  14. currentDomain.search('apprtc') === -1) {
  15. // Not authorized domain. Try with default STUN instead.
  16. turnDone = true;
  17. }
  18. // No TURN server. Get one from computeengineondemand.appspot.com.
  19. xmlhttp = new XMLHttpRequest();
  20. xmlhttp.onreadystatechange = onTurnResult;
  21. xmlhttp.open('GET', turnUrl, true);
  22. xmlhttp.send();
  23. /*for (i = 0; i < VISIO_TURN_LIST.uris.length; i++) {
  24. var iceServer = createIceServer(VISIO_TURN_LIST.uris[i],
  25. VISIO_TURN_LIST.username,
  26. VISIO_TURN_LIST.password);
  27. if (iceServer !== null) {
  28. configuration.iceServers.push(iceServer);
  29. }
  30. }*/
  31. }
  32. function onTurnResult() {
  33. if (xmlhttp.readyState === 4 && xmlhttp.status === 200) {
  34. var turnServer = JSON.parse(xmlhttp.responseText);
  35. for (i = 0; i < turnServer.uris.length; i++) {
  36. // Create a turnUri using the polyfill (adapter.js).
  37. var iceServer = createIceServer(turnServer.uris[i],
  38. turnServer.username,
  39. turnServer.password);
  40. if (iceServer !== null) {
  41. configuration.iceServers.push(iceServer);
  42. }
  43. }
  44. } /*else {
  45. console.log(
  46. 'Error: Status '
  47. + xmlhttp.status
  48. + ', State '
  49. + xmlhttp.readyState);
  50. }*/
  51. // If TURN request failed, continue the call with default STUN.
  52. turnDone = true;
  53. }