|
| 1 | +<!DOCTYPE html> |
| 2 | +<html> |
| 3 | +<head> |
| 4 | + <meta charset="utf-8"> |
| 5 | + <title>Teleprompter Instance</title> |
| 6 | + <link rel="icon" href="favicon.ico" type="image/x-icon"> |
| 7 | + <link rel="stylesheet" href="css/reset.css"> |
| 8 | + <style type="text/css"> |
| 9 | +html, body { |
| 10 | + width: 100%; |
| 11 | + height: 100%; |
| 12 | + margin: 0px; |
| 13 | +} |
| 14 | +img { |
| 15 | + width: 100%; |
| 16 | + height: auto; |
| 17 | +} |
| 18 | +video { |
| 19 | + bottom: 0; |
| 20 | + position: fixed; |
| 21 | + border-top-style: solid; |
| 22 | + border-top-width: 2pt; |
| 23 | + border-top-color: #000; |
| 24 | +} |
| 25 | + </style> |
| 26 | +</head> |
| 27 | +<body> |
| 28 | + <canvas id="canvas" width="480" height="360"></canvas> |
| 29 | + <video autoplay width="100%" height="50%"></video> |
| 30 | +</body> |
| 31 | +<script type="text/javascript"> |
| 32 | +(function() { |
| 33 | + // Use JavaScript Strict Mode. |
| 34 | + "use strict"; |
| 35 | + |
| 36 | + // VARIABLES |
| 37 | + // DOM Objects |
| 38 | + var debug=true, canvas, ctx, promptImage, video, |
| 39 | + // Global variables |
| 40 | + prompt, stream, timeoutStatus, DOMURL; |
| 41 | + |
| 42 | + // FUNCTIONS |
| 43 | + // Main program |
| 44 | + function init() { |
| 45 | + // Get canvas. |
| 46 | + canvas = document.getElementsByTagName("CANVAS")[0]; |
| 47 | + video = document.getElementsByTagName("VIDEO")[0]; |
| 48 | + if (canvas.getContext) |
| 49 | + ctx = canvas.getContext('2d'); |
| 50 | + |
| 51 | + // Get data to display in canvas. |
| 52 | + var data = '<svg xmlns="http://www.w3.org/2000/svg" width="1366" height="1080" >' + /*width="480" height="360" viewBox="0 0 480 360" preserveAspectRatio="xMinYMax slice"*/ |
| 53 | + '<foreignObject width="100%" height="100%">' + |
| 54 | + '<div xmlns="http://www.w3.org/1999/xhtml" style="font-size:12vw">' + |
| 55 | + 'Welcome to ' + |
| 56 | + '<span style="color:white; text-shadow:0 0 2px blue;">' + |
| 57 | + 'Teleprompter</span> by <em>Imaginary Sense</em>' + |
| 58 | + 'Welcome to ' + |
| 59 | + '<span style="color:white; text-shadow:0 0 2px blue;">' + |
| 60 | + 'Teleprompter</span> by <em>Imaginary Sense</em>' + |
| 61 | + 'Welcome to ' + |
| 62 | + '<span style="color:white; text-shadow:0 0 2px blue;">' + |
| 63 | + 'Teleprompter</span> by <em>Imaginary Sense</em>' + |
| 64 | + 'Welcome to ' + |
| 65 | + '<span style="color:white; text-shadow:0 0 2px blue;">' + |
| 66 | + 'Teleprompter</span> by <em>Imaginary Sense</em>' + |
| 67 | + 'Welcome to ' + |
| 68 | + '<span style="color:white; text-shadow:0 0 2px blue;">' + |
| 69 | + 'Teleprompter</span> by <em>Imaginary Sense</em>' + |
| 70 | + 'Welcome to ' + |
| 71 | + '<span style="color:white; text-shadow:0 0 2px blue;">' + |
| 72 | + 'Teleprompter</span> by <em>Imaginary Sense</em>' + |
| 73 | + 'Welcome to ' + |
| 74 | + '<span style="color:white; text-shadow:0 0 2px blue;">' + |
| 75 | + 'Teleprompter</span> by <em>Imaginary Sense</em>' + |
| 76 | + 'Welcome to ' + |
| 77 | + '<span style="color:white; text-shadow:0 0 2px blue;">' + |
| 78 | + 'Teleprompter</span> by <em>Imaginary Sense</em>' + |
| 79 | + '</div>' + |
| 80 | + '</foreignObject>' + |
| 81 | + '</svg>'; |
| 82 | + // Create canvas content's. |
| 83 | + DOMURL = window.URL || window.webkitURL || window; |
| 84 | + var promptImageContents = new Blob([data], {type: 'image/svg+xml'}), |
| 85 | + promptImageURL = DOMURL.createObjectURL(promptImageContents); |
| 86 | + promptImage = new Image(); |
| 87 | + //promptImage.style.backgroundColor; |
| 88 | + // Set canvas up. |
| 89 | + canvasResize(); |
| 90 | + |
| 91 | + // a few minutes later |
| 92 | + timeout(2000, function() { |
| 93 | + return 0; |
| 94 | + }); |
| 95 | + |
| 96 | + // Begin prompting. |
| 97 | + promptImage.onload = function () { |
| 98 | + startPrompting(); |
| 99 | + startBroadcast(); |
| 100 | + } |
| 101 | + |
| 102 | + promptImage.src = promptImageURL; |
| 103 | + |
| 104 | + } |
| 105 | + |
| 106 | + // Operations to execute on window orientation change and resize. |
| 107 | + function canvasResize() { |
| 108 | + // Set canvas to window's size. |
| 109 | + ctx.canvas.width = window.innerWidth; |
| 110 | + ctx.canvas.height = window.innerHeight/2; |
| 111 | + |
| 112 | + // Update canvas contents. |
| 113 | + updateAnimation(); |
| 114 | + } |
| 115 | + |
| 116 | + function startPrompting() { |
| 117 | + updateAnimation(); |
| 118 | + } |
| 119 | + |
| 120 | + function updateAnimation() { |
| 121 | + if (promptImage.src!=="") |
| 122 | + animate(); |
| 123 | + //ctx.drawImage(promptImage, 0, 0); |
| 124 | + //DOMURL.revokeObjectURL(promptImageURL); |
| 125 | + } |
| 126 | + |
| 127 | + function animate() { |
| 128 | + var interval = setInterval(function() { |
| 129 | + var x = 0, y = 0; |
| 130 | + |
| 131 | + return function () { |
| 132 | + ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height); |
| 133 | + ctx.drawImage(promptImage, x, y); |
| 134 | + //ctx.fillRect(x, y, 150, 300); |
| 135 | + |
| 136 | + y -= 1; |
| 137 | + if (y > ctx.canvas.height) { |
| 138 | + y = 0; |
| 139 | + } |
| 140 | + }; |
| 141 | + }(), 1000/16.66666); |
| 142 | + } |
| 143 | + |
| 144 | + function startBroadcast() { |
| 145 | + // Web RTC |
| 146 | + stream = canvas.captureStream(29.97); |
| 147 | + console.log(stream); |
| 148 | + var source = DOMURL.createObjectURL(stream); |
| 149 | + console.log(source); |
| 150 | + video.src = source; |
| 151 | + } |
| 152 | + |
| 153 | + function timeout( time, func ) { |
| 154 | + // If a timeout is already executing, reset it. |
| 155 | + if (timeoutStatus) |
| 156 | + window.clearTimeout(timeoutStatus); |
| 157 | + // Set: Wait time second before resuming animation |
| 158 | + timeoutStatus = window.setTimeout(func, time); |
| 159 | + } |
| 160 | + |
| 161 | + // EVENTS |
| 162 | + // On window resize or orientation change, resize canvas. |
| 163 | + window.addEventListener("resize", canvasResize, false); |
| 164 | + window.addEventListener("orientationchange", canvasResize, false); |
| 165 | + |
| 166 | + // START PROGRAM |
| 167 | + // Initialize objects after DOM is loaded |
| 168 | + if (document.readyState === "interactive" || document.readyState === "complete") |
| 169 | + // Call init if the DOM (interactive) or document (complete) is ready. |
| 170 | + init(); |
| 171 | + else |
| 172 | + // Set init as a listener for the DOMContentLoaded event. |
| 173 | + document.addEventListener("DOMContentLoaded", init); |
| 174 | +}()); |
| 175 | +/* |
| 176 | + REFERENCE CODE |
| 177 | +Draw HTML into canvas |
| 178 | + https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API/Drawing_DOM_objects_into_a_canvas |
| 179 | +Animating images in HTML5 and canvas |
| 180 | + http://stackoverflow.com/questions/9791904/animating-images-in-html5-and-canvas |
| 181 | +SVG Scaling |
| 182 | + https://codepen.io/jonitrythall/post/preserveaspectratio-in-svg |
| 183 | + https://css-tricks.com/scale-svg/ |
| 184 | +RTC |
| 185 | + https://github.com/webrtc/samples/blob/gh-pages/src/content/capture/canvas-pc/js/main.js |
| 186 | + https://w3c.github.io/mediacapture-fromelement/ |
| 187 | +https://cdn.rawgit.com/uysalere/js-demos/master/intro.html |
| 188 | +https://www.html5rocks.com/en/tutorials/streaming/screenshare/ |
| 189 | +https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toDataURL |
| 190 | +https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/captureStream |
| 191 | +https://codepen.io/jonitrythall/post/preserveaspectratio-in-svg |
| 192 | +http://stackoverflow.com/questions/19484707/how-can-i-make-an-svg-scale-with-its-parent-container |
| 193 | +Alternative |
| 194 | + https://github.com/rafaelw/mutation-summary |
| 195 | +*/ |
| 196 | +</script> |
| 197 | +</html> |
0 commit comments