Advertisement
Guest User

Untitled

a guest
Jul 5th, 2015
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.53 KB | None | 0 0
  1. <html>
  2. <head>
  3. <style>
  4. video {
  5. width: 200px;
  6. height: 150px;
  7. border: 1px solid gray;
  8. }
  9. .local {
  10. }
  11.  
  12. .remote {
  13. }
  14. </style>
  15. </head>
  16.  
  17. <body>
  18. <h2>Video</h2>
  19. <div id="log"></div>
  20.  
  21. <!-- Video -->
  22. <h3>Local video</h3>
  23. <video autoplay id="local"></video>
  24.  
  25. <h3>Remote video</h3>
  26. <video autoplay id="remote"></video>
  27.  
  28. <script src="http://cdn.peerjs.com/0.3/peer.min.js"></script>
  29.  
  30. <script>
  31. var myId = 'b';
  32. var otherId = 'a';
  33. var constraints = { video: true, audio: true };
  34. var peer = new Peer(myId, {host: '192.168.1.222', port: 9000, key: 'peerjs'});
  35. // var conn = peer.connect(otherId);
  36. var err = function(err) {
  37. console.log(err);
  38. }
  39. var $localVideo = document.getElementById('local');
  40. var $remoteVideo = document.getElementById('local');
  41.  
  42. // // send 'hi'
  43. // conn.on('open', function(){
  44. // conn.send('chao Cuong <3');
  45. // });
  46.  
  47. // // print message
  48. // peer.on('connection', function(conn) {
  49. // conn.on('data', function(data){
  50. // // Will print 'hi!'
  51. // console.log(data);
  52. // });
  53. // });
  54.  
  55. navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
  56.  
  57.  
  58. // Call
  59. navigator.getUserMedia(
  60. constraints,
  61.  
  62. function(localStream) {
  63. // render local stream in browser
  64. $localVideo.src = window.URL.createObjectURL(localStream);
  65.  
  66. var call = peer.call(otherId, localStream);
  67. console.log("Calling peer..");
  68. console.log(call);
  69. call.on('stream', function(remoteStream) {
  70. // Show stream in some video/canvas element.
  71. console.log("Receiving remote stream");
  72. // console.log(remoteStream);
  73. $remoteStream.src = window.URL.createObjectURL(remoteStream);
  74. });
  75. },
  76.  
  77. err
  78. )
  79.  
  80. // Answer
  81. peer.on('call', function(call) {
  82. navigator.getUserMedia(
  83. constraints,
  84.  
  85. function(stream) {
  86. console.log("Receiving a call..")
  87. call.answer(stream); // Answer the call with an A/V stream.
  88. call.on('stream', function(remoteStream) {
  89. // Show stream in some video/canvas element.
  90. console.log("Receiving remote stream");
  91. console.log("Inside receive");
  92. console.log(remoteStream);
  93. });
  94. },
  95.  
  96. err
  97. );
  98. });
  99.  
  100. </script>
  101. </body>
  102. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement