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.

95 lines
3.1 KiB

  1. var movim_getUserMedia = ( navigator.webkitGetUserMedia ||
  2. navigator.mozGetUserMedia ||
  3. navigator.msGetUserMedia ||
  4. navigator.getUserMedia );
  5. var movim_RTCPeerConnection = ( window.webkitRTCPeerConnection ||
  6. window.mozRTCPeerConnection ||
  7. window.RTCPeerConnection );
  8. var WEBRTC_SESSION_DESCRIPTION = ( window.mozRTCSessionDescription ||
  9. window.RTCSessionDescription );
  10. var WEBRTC_ICE_CANDIDATE = ( window.mozRTCIceCandidate ||
  11. window.RTCIceCandidate );
  12. function onIceCandidate(event) {
  13. /*if (event.candidate) {
  14. sendMessage({type: 'candidate',
  15. label: event.candidate.sdpMLineIndex,
  16. id: event.candidate.sdpMid,
  17. candidate: event.candidate.candidate});
  18. noteIceCandidate("Local", iceCandidateType(event.candidate.candidate));
  19. } else {
  20. console.log('End of candidates.');
  21. }*/
  22. console.log('onIceCandidate');
  23. console.log(event);
  24. }
  25. function onIceConnectionStateChanged(event) {
  26. console.log('onIceConnectionStateChanged');
  27. console.log(event);
  28. }
  29. function onSignalingStateChanged(event) {
  30. console.log('onSignalingStateChanged');
  31. console.log(event);
  32. }
  33. function init() {
  34. var configuration = {"iceServers":[{"url": "stun:stun.l.google.com:19302"}]};
  35. try {
  36. pc = new movim_RTCPeerConnection(configuration);
  37. pc.onicecandidate = onIceCandidate;
  38. pc.onsignalingstatechange = onSignalingStateChanged;
  39. pc.oniceconnectionstatechange = onIceConnectionStateChanged;
  40. } catch (e) {
  41. console.log('Failed to create PeerConnection, exception: ' + e.message);
  42. alert('Cannot create RTCPeerConnection object; \
  43. WebRTC is not supported by this browser.');
  44. return;
  45. }
  46. if(movim_getUserMedia) {
  47. if (movim_getUserMedia) {
  48. movim_getUserMedia = movim_getUserMedia.bind(navigator);
  49. }
  50. // Request the camera.
  51. movim_getUserMedia(
  52. // Constraints
  53. {
  54. video: true
  55. },
  56. // Success Callback
  57. function(localMediaStream) {
  58. // Get a reference to the video element on the page.
  59. //var vid = document.getElementById('camera-stream');
  60. // Create an object URL for the video stream and use this
  61. // to set the video source.
  62. //vid.src = window.URL.createObjectURL(localMediaStream);
  63. pc.addStream(localMediaStream);
  64. },
  65. // Error Callback
  66. function(err) {
  67. // Log the error to the console.
  68. console.log('The following error occurred when trying to use getUserMedia: ' + err);
  69. }
  70. );
  71. } else {
  72. alert('Sorry, your browser does not support getUserMedia');
  73. }
  74. //channel = pc.createDataChannel("visio");
  75. console.log(pc);
  76. //console.log(channel);
  77. }