Skip to content

Commit ed1136b

Browse files
author
javiercordero
committed
Fix installer and dependencies
Former-commit-id: ed96a6748cea5a069d6a511cb6c5a10e7ab103a4 Former-commit-id: 512afb554b9876f2d2e01ede46674ee75a92644a [formerly 92a37dafe74b24fd5ef01d13ba6ab3b474a82ac7] [formerly c1c5d1c194c4d48d121a5c8700de1b4b8e61bf97 [formerly 3044a60]] Former-commit-id: 31103d7de94d800e6b666c57c942021d75b09716 [formerly b85e30ee0578363ebaa5be99827727d1daecfafd] Former-commit-id: df374cf2e95f01f9b18e4c07074b40bb19336099
1 parent 9b7b0cf commit ed1136b

File tree

4 files changed

+302
-68
lines changed

4 files changed

+302
-68
lines changed

.gitignore

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
**/.directory
2-
**/.DS_Store
3-
**/node_modules
4-
1+
**/.directory
2+
**/.DS_Store
3+
**/node_modules/**

instance.html

+197
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
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>

main.js

+97-63
Original file line numberDiff line numberDiff line change
@@ -114,67 +114,101 @@ function handleSquirrelEvent() {
114114
app.quit();
115115
return true;
116116
}
117+
}
117118

118-
// Quit when all windows are closed.
119-
app.on('window-all-closed', () => {
120-
// On macOS it is common for applications and their menu bar
121-
// to stay active until the user quits explicitly with Cmd + Q
122-
if (process.platform !== 'darwin') {
123-
app.quit();
124-
}
125-
});
126-
127-
// This method will be called when Electron has finished
128-
// initialization and is ready to create browser windows.
129-
app.on('ready', () => {
130-
// Create the browser window.
131-
mainWindow = new BrowserWindow({
132-
width: 1280,
133-
height: 800,
134-
javascritp: true,
135-
title: 'Teleprompter',
136-
useContentSize: true,
137-
nodeIntegration: true
138-
});
139-
140-
// and load the index.html of app.
141-
mainWindow.loadURL('file://' + __dirname + '/index.html');
142-
143-
// Disables menu in systems where it can be disabled.
144-
Menu.setApplicationMenu(null);
145-
146-
// Send a message to the renderer process...
147-
ipcMain.on('asynchronous-message', (event, arg) => {
148-
event.sender.send('asynchronous-reply', 'Done');
149-
});
150-
151-
// Register a 'F8' shortcut listener.
152-
let ret = globalShortcut.register('F8', () => {
153-
mainWindow.openDevTools();
154-
});
155-
156-
157-
if (!ret) {
158-
console.log('registration failed');
159-
}
160-
161-
// Check whether a shortcut is registered.
162-
console.log(globalShortcut.isRegistered('F8'));
163-
164-
app.on('will-quit', () => {
165-
// Unregister a shortcut.
166-
globalShortcut.unregister('F8');
167-
168-
// Unregister all shortcuts.
169-
globalShortcut.unregisterAll();
170-
});
171-
172-
// Emitted when the window is closed.
173-
mainWindow.on('closed', () => {
174-
// Dereference the windows object, usually you would store windows
175-
// in an array if your app supports multi windows, this is the time
176-
// when you should delete the corresponding element.
177-
mainWindow = null;
178-
});
179-
});
180-
}
119+
// This method will be called when Electron has finished
120+
// initialization and is ready to create browser windows.
121+
app.on('ready', () => {
122+
// Create the browser window.
123+
mainWindow = new BrowserWindow({width: 1280, height: 800, javascritp: true, title: 'Teleprompter', useContentSize: true, nodeIntegration: true});
124+
125+
// and load the index.html of app.
126+
mainWindow.loadURL('file://' + __dirname + '/index.html');
127+
128+
// Disables menu in systems where it can be disabled.
129+
Menu.setApplicationMenu(null);
130+
131+
function getIP() {
132+
var os = require('os');
133+
var nets = os.networkInterfaces();
134+
for ( var a in nets) {
135+
var ifaces = nets[a];
136+
for ( var o in ifaces) {
137+
if (ifaces[o].family == "IPv4" && !ifaces[o].internal) {
138+
return ifaces[o].address;
139+
}
140+
}
141+
}
142+
return null;
143+
}
144+
145+
function runSocket(event){
146+
var ip = getIP();
147+
if(ip){
148+
var app2 = require('express')();
149+
var http = require('http').Server(app2);
150+
var bonjour = require('bonjour')();
151+
152+
var io = require('socket.io')(http);
153+
io.sockets.on('connection', function (socket) {
154+
socket.on('command',function(res){
155+
if(res.hasOwnProperty('key') > 0){
156+
event.sender.send('asynchronous-reply',{'option':'command','data':res});
157+
}
158+
});
159+
socket.on('disconnect', function () {});
160+
});
161+
162+
http.listen(3000, function(){
163+
event.sender.send('asynchronous-reply',{'option':'qr','data':ip});
164+
//console.log('http://' + ip + ':3000/');
165+
});
166+
167+
bonjour.publish({ name: 'Teleprompter', type: 'http', port: 3000 });
168+
bonjour.find({ type: 'http' }, function (service) {
169+
//console.log('Found an HTTP server:'+ service);
170+
event.sender.send('asynchronous-reply',{'option':'qr','data':service.host});
171+
});
172+
}else{
173+
setTimeout(function(){
174+
runSocket(event);
175+
},1000);
176+
}
177+
}
178+
179+
// Send a message to the renderer process...
180+
ipcMain.on('asynchronous-message', (event, arg) => {
181+
if(arg === "network"){
182+
runSocket(event);
183+
}else
184+
event.sender.send('asynchronous-reply', 'Done');
185+
});
186+
187+
// Register a 'F8' shortcut listener.
188+
let ret = globalShortcut.register('F8', () => {
189+
mainWindow.openDevTools();
190+
});
191+
192+
if (!ret) {
193+
console.log('registration failed');
194+
}
195+
196+
// Check whether a shortcut is registered.
197+
console.log(globalShortcut.isRegistered('F8'));
198+
199+
app.on('will-quit', () => {
200+
// Unregister a shortcut.
201+
globalShortcut.unregister('F8');
202+
203+
// Unregister all shortcuts.
204+
globalShortcut.unregisterAll();
205+
});
206+
207+
// Emitted when the window is closed.
208+
mainWindow.on('closed', () =>{
209+
// Dereference the windows object, usually you would store windows
210+
// in an array if your app supports multi windows, this is the time
211+
// when you should delete the corresponding element.
212+
mainWindow = null;
213+
});
214+
});

package.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@
3333
"main": "main.js",
3434
"dependencies": {
3535
"shell": "^0.3.2",
36-
"electron-squirrel-startup": "^1.0.0"
36+
"electron-prebuilt": "^1.4.6",
37+
"electron-squirrel-startup": "^1.0.0",
38+
"socket.io": "*",
39+
"bonjour": "*",
40+
"express": "*"
3741
},
3842
"devDependencies": {
3943
"jquery-pep": "jquery/PEP",

0 commit comments

Comments
 (0)