webrtcapi-custom.html 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8"/>
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  6. <title>WebRTC webcam</title>
  7. <style>
  8. button {
  9. padding: 8px 16px;
  10. }
  11. video {
  12. width: 100%;
  13. }
  14. .option {
  15. margin-bottom: 8px;
  16. }
  17. #media {
  18. max-width: 1280px;
  19. }
  20. </style>
  21. </head>
  22. <body>
  23. <div class="option">
  24. <input id="use-stun" type="checkbox"/>
  25. <label for="use-stun">Use STUN server</label>
  26. </div>
  27. <button id="start" onclick="start()">Start</button>
  28. <button id="stop" style="display: none" onclick="stop()">Stop</button>
  29. <input type="hidden" id="sessionid" value="0">
  30. <form class="form-inline" id="echo-form">
  31. <div class="form-group">
  32. <p>input text</p>
  33. <textarea cols="2" rows="3" style="width:600px;height:50px;" class="form-control" id="message">test</textarea>
  34. </div>
  35. <button type="submit" class="btn btn-default">Send</button>
  36. </form>
  37. <div id="media">
  38. <h2>Media</h2>
  39. <audio id="audio" autoplay="true"></audio>
  40. <video id="video" style="width:600px;" autoplay="true" playsinline="true"></video>
  41. </div>
  42. <button id="custom" onclick="custom()">切换视频</button>
  43. <input type="text" id="audiotype" value="0">
  44. <script src="client.js"></script>
  45. <script type="text/javascript" src="http://cdn.sockjs.org/sockjs-0.3.4.js"></script>
  46. <script type="text/javascript" src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
  47. </body>
  48. <script type="text/javascript" charset="utf-8">
  49. function custom() {
  50. fetch('/set_audiotype', {
  51. body: JSON.stringify({
  52. audiotype: parseInt(document.getElementById('audiotype').value),
  53. reinit: false,
  54. sessionid:parseInt(document.getElementById('sessionid').value),
  55. }),
  56. headers: {
  57. 'Content-Type': 'application/json'
  58. },
  59. method: 'POST'
  60. });
  61. }
  62. $(document).ready(function() {
  63. // var host = window.location.hostname
  64. // var ws = new WebSocket("ws://"+host+":8000/humanecho");
  65. // //document.getElementsByTagName("video")[0].setAttribute("src", aa["video"]);
  66. // ws.onopen = function() {
  67. // console.log('Connected');
  68. // };
  69. // ws.onmessage = function(e) {
  70. // console.log('Received: ' + e.data);
  71. // data = e
  72. // var vid = JSON.parse(data.data);
  73. // console.log(typeof(vid),vid)
  74. // //document.getElementsByTagName("video")[0].setAttribute("src", vid["video"]);
  75. // };
  76. // ws.onclose = function(e) {
  77. // console.log('Closed');
  78. // };
  79. $('#echo-form').on('submit', function(e) {
  80. e.preventDefault();
  81. var message = $('#message').val();
  82. console.log('Sending: ' + message);
  83. console.log('sessionid: ',document.getElementById('sessionid').value);
  84. fetch('/human', {
  85. body: JSON.stringify({
  86. text: message,
  87. type: 'echo',
  88. interrupt: true,
  89. sessionid:parseInt(document.getElementById('sessionid').value),
  90. }),
  91. headers: {
  92. 'Content-Type': 'application/json'
  93. },
  94. method: 'POST'
  95. });
  96. //ws.send(message);
  97. $('#message').val('');
  98. });
  99. });
  100. </script>
  101. </html>