PoC.html 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <button id="btn-start-recording">Start</button>
  2. <button id="btn-stop-recording" disabled>Stop</button>
  3. <script src="https://www.WebRTC-Experiment.com/RecordRTC.js"></script>
  4. <script>
  5. var wsUri = getWebSocketEndpoint() + "/system/file_system/lowmemUpload?filename=" + encodeURIComponent(new Date().toLocaleString().replaceAll(" ","").replaceAll("/","").replaceAll(":","").replaceAll(",","")) + ".webm&path=user%3A%2F";
  6. var video = document.querySelector('video');
  7. var websocket;
  8. function getWebSocketEndpoint(){
  9. let protocol = "wss://";
  10. if (location.protocol !== 'https:') {
  11. protocol = "ws://";
  12. }
  13. let port = window.location.port;
  14. if (window.location.port == ""){
  15. if (location.protocol !== 'https:') {
  16. port = "80";
  17. }else{
  18. port = "443";
  19. }
  20. }
  21. let wsept = (protocol + window.location.hostname + ":" + port);
  22. return wsept;
  23. }
  24. function captureCamera(callback) {
  25. navigator.mediaDevices.getDisplayMedia({
  26. displaySurface: 'monitor',
  27. logicalSurface: true,
  28. cursor: 'always'
  29. }).then(function(camera) {
  30. callback(camera);
  31. }).catch(function(error) {
  32. alert('Unable to capture your camera. Please check console logs.');
  33. console.error(error);
  34. });
  35. }
  36. function stopRecordingCallback() {
  37. recorder.camera.stop();
  38. recorder = null;
  39. }
  40. var recorder;
  41. document.getElementById('btn-start-recording').onclick = function() {
  42. this.disabled = true;
  43. websocket = new WebSocket(wsUri);
  44. //websocket.binaryType = 'blob';
  45. captureCamera(function(camera) {
  46. recorder = RecordRTC(camera, {
  47. recorderType: MediaStreamRecorder,
  48. mimeType: 'video/webm',
  49. timeSlice: 100, // pass this parameter
  50. getNativeBlob: true,
  51. ondataavailable: function(blob) {
  52. websocket.send(blob);
  53. }
  54. });
  55. recorder.startRecording();
  56. // release camera on stopRecording
  57. recorder.camera = camera;
  58. document.getElementById('btn-stop-recording').disabled = false;
  59. });
  60. };
  61. document.getElementById('btn-stop-recording').onclick = function() {
  62. this.disabled = true;
  63. recorder.stopRecording(stopRecordingCallback);
  64. websocket.send("done");
  65. };
  66. </script>
  67. <footer style="margin-top: 20px;"><small id="send-message"></small></footer>
  68. <script src="https://www.webrtc-experiment.com/common.js"></script>