Headless mode, bi-atch. Allows multiple clients to use a single server instance (synchronization is a bit messy still, to be continued)
This commit is contained in:
parent
93c9056c1b
commit
651c0499dc
8 changed files with 266 additions and 144 deletions
16
app/browser/index-headless.html
Normal file
16
app/browser/index-headless.html
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=yes"/>
|
||||
<link rel="stylesheet" href="fonts/font-awesome.min.css"/>
|
||||
<link rel="stylesheet" href="css/style.css"/>
|
||||
<script src="/js/browser-headless.js"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="lobby"></div>
|
||||
<div id="container"></div>
|
||||
<div id="sidepanel"></div>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
|
@ -33,7 +33,7 @@ ipc.on('listSessions',function(data){
|
|||
$('#lobby .list').append('<a class="btn browse">...</a>')
|
||||
$('#lobby .load').click(function(e){
|
||||
e.stopPropagation()
|
||||
openSession($(this).data('session'))
|
||||
ipc.send('openSession',$(this).data('session'))
|
||||
})
|
||||
$('#lobby a span').click(function(e){
|
||||
e.stopPropagation()
|
||||
|
|
@ -44,7 +44,23 @@ ipc.on('listSessions',function(data){
|
|||
e.stopPropagation()
|
||||
ipc.send('browseSessions')
|
||||
})
|
||||
ipc.off('listSession')
|
||||
})
|
||||
|
||||
ipc.on('openSession',function(data){
|
||||
openSession(data)
|
||||
var error = data.error,
|
||||
path = data.path,
|
||||
session = JSON.parse(data.session)
|
||||
|
||||
if (!error) {
|
||||
ipc.send('addSessionToHistory',path)
|
||||
$('#lobby').hide()
|
||||
$('#container').append('<div id="loading"><div class="spinner"></div></div>')
|
||||
setTimeout(function(){
|
||||
init(session,function(){$('#loading').hide()})
|
||||
},1)
|
||||
ipc.off('openSession')
|
||||
} else {
|
||||
createPopup(icon('warning')+' Error: invalid session file',error)
|
||||
}
|
||||
})
|
||||
|
|
|
|||
|
|
@ -53,9 +53,6 @@ init = function(session,callback) {
|
|||
$('.tablist li:first-child a').click()
|
||||
|
||||
|
||||
// get current webFrame
|
||||
var webFrame = require('web-frame');
|
||||
|
||||
// horizontal scrolling & zoom with mousewheel
|
||||
// if shift is pressed (native), or if there is no vertical scrollbar,
|
||||
// or if mouse is on h-scrollbar
|
||||
|
|
@ -67,7 +64,7 @@ init = function(session,callback) {
|
|||
e.preventDefault()
|
||||
var d = -e.originalEvent.deltaY/Math.abs(e.originalEvent.deltaY)/10,
|
||||
s = d+webFrame.getZoomFactor()
|
||||
webFrame.setZoomFactor(s);
|
||||
ipc.send('setZoomFactor',s)
|
||||
|
||||
} else {
|
||||
if ($(this).height()>$(this).get(0).scrollHeight) {
|
||||
|
|
@ -95,7 +92,7 @@ init = function(session,callback) {
|
|||
|
||||
// reset zoom
|
||||
$(document).on('keydown.resetzoom', function(e){
|
||||
if (e.keyCode==96||e.keyCode==48) webFrame.setZoomFactor(1)
|
||||
if (e.keyCode==96||e.keyCode==48) ipc.send('setZoomFactor',1)
|
||||
})
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -41,37 +41,6 @@ setState = function(preset){
|
|||
|
||||
|
||||
|
||||
openSession = function(path){
|
||||
var fs = require('fs'),
|
||||
data = fs.readFileSync(path,'utf8'),
|
||||
vm = require('vm'),
|
||||
session,
|
||||
error
|
||||
|
||||
try {
|
||||
session = vm.runInNewContext(data)
|
||||
} catch(err) {
|
||||
error = err
|
||||
}
|
||||
|
||||
if (!error) {
|
||||
ipc.send('addSessionToHistory',path)
|
||||
|
||||
$('#lobby').hide()
|
||||
$('#container').append('<div id="loading"><div class="spinner"></div></div>')
|
||||
setTimeout(function(){
|
||||
init(session,function(){$('#loading').hide()})
|
||||
},1)
|
||||
|
||||
} else {
|
||||
createPopup(icon('warning')+' Error: invalid session file',error)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
icon = function(i) {
|
||||
return `<i class="fa fa-fw fa-${i}"></i>`
|
||||
|
|
|
|||
22
app/browser/js/browser-headless.js
Normal file
22
app/browser/js/browser-headless.js
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
|
||||
// mainProcess & renderProcess communication engine
|
||||
// electron's ipc module is not available here, we use socket.io as a replacement
|
||||
socket = require('socket.io-client')
|
||||
|
||||
ipc=socket.connect();
|
||||
ipc.send = ipc.emit
|
||||
|
||||
|
||||
// jquery
|
||||
|
||||
window.$ = window.jQuery = require('./jquery/jquery.min.js')
|
||||
|
||||
|
||||
// third-party js libraries
|
||||
require('./jquery/jquery.drag.js')
|
||||
require('./jquery/jquery.resize.js')
|
||||
|
||||
// main js
|
||||
require('./app/app.js')
|
||||
|
||||
ipc.send('ready')
|
||||
|
|
@ -2,9 +2,6 @@
|
|||
// mainProcess & renderProcess communication engine
|
||||
ipc = require('ipc')
|
||||
|
||||
// filesystem
|
||||
fs = require('fs')
|
||||
|
||||
// jquery
|
||||
window.$ = window.jQuery = require('./jquery/jquery.min.js')
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue