|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +const Prism = require('prismjs'); |
| 4 | +const getSnippet = require('../../util/getsnippet'); |
| 5 | +const helpers = require('./helpers'); |
| 6 | +const createScreenTrack = helpers.createScreenTrack; |
| 7 | +const captureScreen = document.querySelector('button#capturescreen'); |
| 8 | +const screenPreview = document.querySelector('video#screenpreview'); |
| 9 | +const stopScreenCapture = document.querySelector('button#stopscreencapture'); |
| 10 | + |
| 11 | +(async function() { |
| 12 | + // Load the code snippet. |
| 13 | + const snippet = await getSnippet('./helpers.js'); |
| 14 | + const pre = document.querySelector('pre.language-javascript'); |
| 15 | + pre.innerHTML = Prism.highlight(snippet, Prism.languages.javascript); |
| 16 | + |
| 17 | + // Hide the "Stop Capture Screen" button. |
| 18 | + stopScreenCapture.style.display = 'none'; |
| 19 | + |
| 20 | + // The LocalVideoTrack for your screen. |
| 21 | + let screenTrack; |
| 22 | + |
| 23 | + captureScreen.onclick = async function() { |
| 24 | + try { |
| 25 | + // Create and preview your local screen. |
| 26 | + screenTrack = await createScreenTrack(720, 1280); |
| 27 | + screenTrack.attach(screenPreview); |
| 28 | + // Show the "Capture Screen" button after screen capture stops. |
| 29 | + screenTrack.on('stopped', toggleButtons); |
| 30 | + // Show the "Stop Capture Screen" button. |
| 31 | + toggleButtons(); |
| 32 | + } catch (e) { |
| 33 | + alert(e.message); |
| 34 | + } |
| 35 | + }; |
| 36 | + |
| 37 | + stopScreenCapture.onclick = function() { |
| 38 | + // Stop capturing your screen. |
| 39 | + screenTrack.stop(); |
| 40 | + } |
| 41 | +}()); |
| 42 | + |
| 43 | +function toggleButtons() { |
| 44 | + captureScreen.style.display = captureScreen.style.display === 'none' ? '' : 'none'; |
| 45 | + stopScreenCapture.style.display = stopScreenCapture.style.display === 'none' ? '' : 'none'; |
| 46 | +} |
0 commit comments