69 lines
1.3 KiB
JavaScript
69 lines
1.3 KiB
JavaScript
|
|
||
|
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) => {
|
||
|
socket.emit('frameData', {frames: files})
|
||
|
console.log('starting animation')
|
||
|
})
|
||
|
})
|
||
|
|
||
|
watch(config.frames_folder, function(e, name){
|
||
|
fs.readdir(config.frames_folder, (err, files) => {
|
||
|
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
|