Skip to content

Commit

Permalink
update dependencies, move to use es6 modules imports, bind /data/vide…
Browse files Browse the repository at this point in the history
…o to /video for easier video displaying
  • Loading branch information
reaby committed May 23, 2022
1 parent 88dbbaa commit 04af038
Show file tree
Hide file tree
Showing 28 changed files with 3,517 additions and 1,657 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,4 @@ data/*.log
data/template.json
!data/bundles/default
!data/bundles/default/*
data/video/*.mp4
93 changes: 53 additions & 40 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,50 @@
let config = require("./config.js");
let express = require('express');
let createError = require('http-errors');
let logger = require('morgan');
let lessMiddleware = require('less-middleware');
let path = require('path');
let PluginManager = require("./modules/pluginManager");
const EventEmitter = require('events');

let cookieParser = require('cookie-parser')(config.sessionKey);

import EventEmitter from 'events';
class Dispatcher extends EventEmitter { }

const eventDispatcher = new Dispatcher();

let app = express();
let server = require('http').Server(app);
let io = require('socket.io')(server);

let i18next = require("i18next");
let FilesystemBackend = require("i18next-node-fs-backend");
let i18nextMiddleware = require("i18next-express-middleware");

let passport = require('passport');
let LocalStrategy = require('passport-local').Strategy;
let User = require("./modules/db.js");
import config from './config.js';
import express from 'express';
import createError from 'http-errors';
import logger from 'morgan';
import lessMiddleware from 'less-middleware';
import path from 'path';
import PluginManager from './modules/pluginManager.js';
const app = express();
const server = Http.Server(app);
const io = new SocketIO(server);

const pluginManager = new PluginManager(app, io, eventDispatcher);
import WebSocket from './modules/websocket.js';
const websocket = WebSocket(pluginManager, io, eventDispatcher);
import routerIndex from './routes/index.js';
const indexRouter = routerIndex(pluginManager, websocket, eventDispatcher);
import routerAdmin from './routes/admin.js';
const adminRouter = routerAdmin(pluginManager, websocket, eventDispatcher);
import routerAuth from './routes/auth.js';
const authRouter = routerAuth(websocket, eventDispatcher);

import CookieParser from 'cookie-parser';
import Http from 'http';
import { Server as SocketIO } from 'socket.io';
import i18next from 'i18next';
import FilesystemBackend from 'i18next-node-fs-backend';
import i18nextMiddleware from 'i18next-http-middleware';
import passport from 'passport';
import passportlocal from 'passport-local';
import NodeMediaServer from 'node-media-server';
import expressSession from 'express-session';
import sqlite3 from 'connect-sqlite3';
const SQLiteStore = sqlite3(expressSession);
const cookieParser = CookieParser(config.sessionKey);


const LocalStrategy = passportlocal.Strategy;
import User from './modules/db.js';

import { fileURLToPath } from 'url'
import { dirname } from 'path'
const __filename = fileURLToPath(import.meta.url)
const __dirname = dirname(__filename)

passport.serializeUser(function (user, cb) {
cb(null, user.id);
Expand Down Expand Up @@ -57,8 +78,6 @@ passport.use("local", new LocalStrategy({
}));

if (config.mediaServer) {
const NodeMediaServer = require('node-media-server');

const nodeServerConfig = {
logtype: 2,
rtmp: {
Expand All @@ -76,11 +95,11 @@ if (config.mediaServer) {
api: true,
api_user: config.admins[0].username,
api_pass: config.admins[0].password,

}
};

let nms = new NodeMediaServer(nodeServerConfig);
const nms = new NodeMediaServer(nodeServerConfig);
nms.run();
}

Expand Down Expand Up @@ -135,9 +154,8 @@ app.use(express.urlencoded({
app.use(cookieParser);
app.use(lessMiddleware(path.join(__dirname, 'public')));
app.use(express.static(path.join(__dirname, 'public')));
app.use("/video/",express.static(path.join(__dirname, 'data','video')));

var expressSession = require('express-session');
var SQLiteStore = require('connect-sqlite3')(expressSession);
var sessionStore = new SQLiteStore({
dir: "./data",
db: "sessions.db"
Expand Down Expand Up @@ -188,12 +206,6 @@ function onAuthorizeFail(data, message, error, accept) {
}
*/

let pluginManager = new PluginManager(app, io, eventDispatcher);
let websocket = require("./modules/websocket")(pluginManager, io, eventDispatcher);
let indexRouter = require('./routes/index.js')(pluginManager, websocket, eventDispatcher);
let adminRouter = require('./routes/admin.js')(pluginManager, websocket, eventDispatcher);
let authRouter = require('./routes/auth.js')(websocket, eventDispatcher);

app.use('/', authRouter);
app.use('/', indexRouter);
app.use('/admin', adminRouter);
Expand All @@ -214,9 +226,10 @@ app.use(function (err, req, res, next) {
res.render('error');
});

module.exports = {
app: app,
server: server,
io: io,
eventDispatcher: eventDispatcher

export {
app,
server,
io,
eventDispatcher
};
7 changes: 4 additions & 3 deletions bin/daemon → bin/daemon.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
#!/usr/bin/env node

var fs = require('fs');
import fs from 'fs';
import { daemon } from 'daemon';
var stdoutFd = fs.openSync('./data/output.log', 'a');
var stderrFd = fs.openSync('./data/errors.log', 'a');
var proc2 = require('daemon').daemon("./bin/infoscreen3",
var proc2 = daemon("./bin/infoscreen3",
"",
{
cwd: process.cwd(),
stdout: stdoutFd,
stderr: stderrFd,
stderr: stderrFd,
});

console.log(proc2.pid);
10 changes: 4 additions & 6 deletions bin/infoscreen3 → bin/infoscreen3.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
/**
* Module dependencies.
*/
let cli = require('../modules/cli');
let chalk = require('chalk');
let debug = require('debug')('screen-info:server');
let config = require('../config.js');
let app = require('../app').app;
import cli from '../modules/cli.js';
import chalk from 'chalk';
import config from '../config.js';
import { app, server } from "../app.js";


/**
Expand All @@ -21,7 +20,6 @@ app.set('port', port);
* Create HTTP server.
*/

let server = require("../app").server;

/**
* Listen on provided port, on all network interfaces.
Expand Down
20 changes: 14 additions & 6 deletions config-default.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
let displays = require(`./data/displays.json`);

module.exports = {
export default {
"serverListenPort": process.env.PORT || 8000,
"serverHost": process.env.HOST || "127.0.0.1",
"serverUrl": "http://" + (process.env.HOST || "127.0.0.1"), // used for web client
Expand All @@ -10,8 +8,8 @@ module.exports = {
"mediaServer": false, // local streaming server for rtmp, see docs how to use
"defaultLocale": "en", // currently supported values are: "en","fi"

/*
* Plugins
/*
* Plugins
*/
"plugins": [
"profiler", // display memory statistics at console.
Expand Down Expand Up @@ -46,5 +44,15 @@ module.exports = {
}
}
],
"displays": displays
"displays":
[
{
"name": "Main Screen",
"bundle": "default"
},
{
"name": "Secondary Screen",
"bundle": "default"
},
]
};
14 changes: 0 additions & 14 deletions data/displays.json

This file was deleted.

Empty file added data/video/.gitkeep
Empty file.
46 changes: 20 additions & 26 deletions modules/admin.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
let fs = require("fs");
let config = require(`../config.js`);
let cli = require(`./cli.js`);

import fs from 'fs';
import config from '../config.js';
import cli from './cli.js';

/** Generate an uuid
* @url https://stackoverflow.com/questions/105034/create-guid-uuid-in-javascript#2117523 **/
Expand All @@ -15,7 +14,7 @@ function uuidv4() {
/**
*
*/
class admin {
export default class admin {

/**
* @param sharedIO
Expand Down Expand Up @@ -225,11 +224,11 @@ class admin {
self.screenView.overrideSlide(data.json, null, data.duration, data.transition);
}
});

socket.on('admin.overrideVideo', function (data) {
if (data.displayId === null) {
if (data.displayId === null) {
dispatcher.emit("all.override", data);
} else {
} else {
self.screenView.overrideSlide(data.json, null, data.json.duration, null);
}
});
Expand Down Expand Up @@ -315,8 +314,8 @@ class admin {
}
socket.emit("callback.webpage", {bundleData: bundleData, json: json});
});


socket.on('edit.saveLink', function (data) {

let filename = data.filename;
Expand Down Expand Up @@ -379,16 +378,16 @@ class admin {
}
socket.emit("callback.video", {bundleData: bundleData, json: json});
});


socket.on('edit.saveVideo', function (data) {

let filename = data.filename;
if (filename === "") {
filename = uuidv4();
}
if (data.duration === "") {

if (data.duration === "") {
socket.emit("callback.saveVideo", {erro: "Video duration is not known. Remember to load metadata!"});
return;
}
Expand All @@ -398,8 +397,8 @@ class admin {

let template = {
uuid: filename,
name: data.name,
duration: data.duration,
name: data.name,
duration: data.duration,
enabled: true,
displayTime: data.displayTime,
type: "video",
Expand All @@ -415,8 +414,8 @@ class admin {
bundle.allSlides.push(template);
} else {
obj.url = data.url;
obj.name = data.name;
obj.duration = data.duration;
obj.name = data.name;
obj.duration = data.duration;
obj.displayTime = data.displayTime;
obj.mute = data.mute;
obj.loop = data.loop;
Expand Down Expand Up @@ -476,11 +475,11 @@ class admin {
});

socket.on('edit.saveTemplate', function (data) {
let templates = {};
let templates = {};

if (fs.existsSync("./data/template.json")) {
templates = JSON.parse(fs.readFileSync("./data/template.json").toString());
}
}
templates[data.name] = data.json;
try {
fs.writeFileSync("./data/template.json", JSON.stringify(templates));
Expand Down Expand Up @@ -683,8 +682,3 @@ class admin {

// admin
}

/**
* @type {admin}
*/
module.exports = admin;
18 changes: 7 additions & 11 deletions modules/adminLobby.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
let cli = require(`./cli.js`);
import cli from './cli.js'

class adminLobby {
export default class adminLobby {

/**
* @param sharedIO
Expand Down Expand Up @@ -66,11 +66,11 @@ class adminLobby {
cli.error("error while duplicating slide", err);
}
});

socket.on('admin.moveSlide', function (data) {
try {
let bundle = bundleManager.moveSlide(data.from, data.to, data.uuid, data.position);
socket.emit("callback.updateBundleData");
try {
let bundle = bundleManager.moveSlide(data.from, data.to, data.uuid, data.position);
socket.emit("callback.updateBundleData");
updateSlides(data.from, bundle);
} catch (err) {
cli.error("error while moving slide", err);
Expand All @@ -83,7 +83,7 @@ class adminLobby {
let bundle = bundleManager.getBundle(data.bundleName);
bundle.setName(data.uuid, data.name);
updateSlides(data.bundleName, bundle);
socket.emit("callback.updateBundleData");
socket.emit("callback.updateBundleData");
} catch (err) {
cli.error("error while renaming slide", err);
}
Expand Down Expand Up @@ -144,7 +144,3 @@ class adminLobby {
}

}

module.exports = adminLobby;


Loading

0 comments on commit 04af038

Please sign in to comment.