2019-12-18 09:48:23 +00:00
|
|
|
|
|
|
|
const express = require('express'),
|
|
|
|
app = express(),
|
|
|
|
server = require('http').Server(app),
|
|
|
|
io = require('socket.io')(server),
|
|
|
|
fs = require('fs'),
|
|
|
|
watch = require('node-watch')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let LocalServer = (config) => {
|
|
|
|
|
|
|
|
let ls = {
|
|
|
|
express: express,
|
|
|
|
app: app,
|
|
|
|
server: server,
|
|
|
|
io: io
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
app.use(express.static(config.frontend_folder))
|
|
|
|
|
|
|
|
io.on('connection', function(socket){
|
|
|
|
console.log('client connected')
|
|
|
|
socket.emit('connection')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// FRAME ANIMATION /////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
socket.on('animationInit', function(){
|
|
|
|
fs.readdir(config.frames_folder, (err, files) => {
|
2020-01-23 12:24:53 +00:00
|
|
|
files = files.filter(file => file.endsWith('.jpg'))
|
2019-12-18 09:48:23 +00:00
|
|
|
socket.emit('frameData', {frames: files})
|
|
|
|
console.log('starting animation')
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
watch(config.frames_folder, function(e, name){
|
|
|
|
fs.readdir(config.frames_folder, (err, files) => {
|
2020-01-23 12:24:53 +00:00
|
|
|
files = files.filter(file => file.endsWith('.jpg'))
|
2019-12-18 09:48:23 +00:00
|
|
|
socket.emit('frameData', {frames: files})
|
|
|
|
console.log(`frames changed => ${name}`)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
ls.start = () => {
|
|
|
|
server.listen(config.port, function(){
|
|
|
|
console.log(`node server listening on port ${config.port}`)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return ls
|
|
|
|
|
|
|
|
}
|
|
|
|
module.exports = LocalServer
|