mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 10:37:34 +00:00
2025 update!
This commit is contained in:
parent
1df7258b56
commit
e6089687ed
6 changed files with 2487 additions and 358 deletions
|
|
@ -1,105 +1,74 @@
|
||||||
define([
|
define([
|
||||||
'http',
|
'express',
|
||||||
'node-static',
|
'http',
|
||||||
|
'path',
|
||||||
'Server/Api',
|
'Server/Api',
|
||||||
'fs'
|
'fs'
|
||||||
],
|
],
|
||||||
|
|
||||||
function (http, nodeStatic, Api, fs) {
|
function (express, http, path, Api, fs) {
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
function HttpServer (options, coordinator) {
|
function HttpServer (options, coordinator) {
|
||||||
options.port = options.port || 1234;
|
options.port = options.port || 1234;
|
||||||
options.caching = typeof options.caching != 'undefined' ? options.caching : 3600;
|
|
||||||
options.rootDirectory = options.rootDirectory || './';
|
options.rootDirectory = options.rootDirectory || './';
|
||||||
|
|
||||||
this.server = null;
|
|
||||||
this.api = new Api(coordinator);
|
this.api = new Api(coordinator);
|
||||||
|
this.app = express();
|
||||||
|
this.server = http.createServer(this.app);
|
||||||
this.init(options);
|
this.init(options);
|
||||||
}
|
}
|
||||||
|
|
||||||
HttpServer.prototype.init = function (options) {
|
HttpServer.prototype.init = function (options) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
var app = this.app;
|
||||||
|
|
||||||
//gzip true serves gzip file if there is one with .gz next to the original && if browser supports it
|
// Serve static files
|
||||||
var fileServer = new nodeStatic.Server(options.rootDirectory, { cache: options.caching, gzip: true });
|
app.use('/static', express.static(path.join(options.rootDirectory, 'static')));
|
||||||
|
app.use('/app', express.static(path.join(options.rootDirectory, 'app')));
|
||||||
|
|
||||||
this.server = http.createServer(
|
// Serve index.html at root
|
||||||
function (req, res) {
|
app.get('/', function(req, res) {
|
||||||
|
res.sendFile(path.resolve(options.rootDirectory, 'static/html/index.html'));
|
||||||
var fullBody = '';
|
});
|
||||||
req.addListener('data', function(chunk) { // doesn't work on Jeenas computer without this
|
|
||||||
fullBody += chunk.toString();
|
|
||||||
});
|
|
||||||
|
|
||||||
req.addListener('error', function(err) {
|
// Serve client.js and minified version
|
||||||
console.log('');
|
app.get('/client.js', function(req, res) {
|
||||||
});
|
if (process.env.NODE_ENV === 'production' && fs.existsSync(path.resolve(options.rootDirectory, 'build/client.min.js'))) {
|
||||||
|
res.sendFile(path.resolve(options.rootDirectory, 'build/client.min.js'));
|
||||||
|
} else {
|
||||||
req.addListener('end', function () {
|
res.sendFile(path.resolve(options.rootDirectory, 'client.js'));
|
||||||
|
|
||||||
switch(true) {
|
|
||||||
case req.url == '/':
|
|
||||||
fileServer.serveFile('./static/html/index.html', 200, {}, req, res);
|
|
||||||
console.checkpoint('HTTP Server serves index');
|
|
||||||
break;
|
|
||||||
|
|
||||||
case req.url == '/client.js':
|
|
||||||
fs.exists('./build/client.min.js', function (exists) {
|
|
||||||
if (process.env.NODE_ENV && process.env.NODE_ENV == 'production' && exists) {
|
|
||||||
fileServer.serveFile('./build/client.min.js', 200, {}, req, res);
|
|
||||||
} else {
|
|
||||||
fileServer.serveFile('./client.js', 200, {}, req, res);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
break;
|
|
||||||
|
|
||||||
case req.url == '/client.min.js':
|
|
||||||
fileServer.serveFile('./build/client.min.js', 200, {}, req, res);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case req.url == '/require.js':
|
|
||||||
fileServer.serveFile('./node_modules/requirejs/require.js', 200, {}, req, res);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case req.url == '/screenfull.js':
|
|
||||||
fileServer.serveFile('./node_modules/screenfull/dist/screenfull.js', 200, {}, req, res);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case req.url == '/chart.js':
|
|
||||||
fileServer.serveFile('./node_modules/chart.js/Chart.js', 200, {}, req, res);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case req.url == '/api':
|
|
||||||
self.api.handleCall(fullBody);
|
|
||||||
var status = self.api.isError ? 400 : 200;
|
|
||||||
res.writeHead(status, {"Content-Type": self.api.getContentType()});
|
|
||||||
res.end(self.api.getOutput());
|
|
||||||
self.api.isError = false;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case new RegExp(/^\/app/).test(req.url):
|
|
||||||
fileServer.serve(req, res, function () {
|
|
||||||
self.handleFileError(res)
|
|
||||||
});
|
|
||||||
break;
|
|
||||||
|
|
||||||
case new RegExp(/^\/static/).test(req.url):
|
|
||||||
fileServer.serve(req, res, function () {
|
|
||||||
self.handleFileError(res)
|
|
||||||
});
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
self.handleFileError(res);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
);
|
});
|
||||||
|
app.get('/client.min.js', function(req, res) {
|
||||||
|
res.sendFile(path.resolve(options.rootDirectory, 'build/client.min.js'));
|
||||||
|
});
|
||||||
|
|
||||||
|
// Serve require.js, screenfull.js, chart.js from node_modules
|
||||||
|
app.get('/require.js', function(req, res) {
|
||||||
|
res.sendFile(path.resolve(options.rootDirectory, 'node_modules/requirejs/require.js'));
|
||||||
|
});
|
||||||
|
app.get('/screenfull.js', function(req, res) {
|
||||||
|
res.sendFile(path.resolve(options.rootDirectory, 'static/vendor/screenfull.js'));
|
||||||
|
});
|
||||||
|
app.get('/chart.js', function(req, res) {
|
||||||
|
// Chart.js v4 uses 'dist/chart.umd.js'
|
||||||
|
res.sendFile(path.resolve(options.rootDirectory, 'node_modules/chart.js/dist/chart.umd.js'));
|
||||||
|
});
|
||||||
|
|
||||||
|
// API endpoint
|
||||||
|
app.post('/api', express.text({type: '*/*'}), function(req, res) {
|
||||||
|
self.api.handleCall(req.body);
|
||||||
|
var status = self.api.isError ? 400 : 200;
|
||||||
|
res.status(status).type(self.api.getContentType()).send(self.api.getOutput());
|
||||||
|
self.api.isError = false;
|
||||||
|
});
|
||||||
|
|
||||||
|
// 404 handler
|
||||||
|
app.use(function(req, res) {
|
||||||
|
res.status(404).send('<h1>404 not ... found</h1>');
|
||||||
|
});
|
||||||
|
|
||||||
this.server.once('error', function(err) {
|
this.server.once('error', function(err) {
|
||||||
if(err.code == 'EADDRINUSE') {
|
if(err.code == 'EADDRINUSE') {
|
||||||
|
|
@ -110,7 +79,6 @@ function (http, nodeStatic, Api, fs) {
|
||||||
});
|
});
|
||||||
|
|
||||||
this.server.listen(options.port);
|
this.server.listen(options.port);
|
||||||
|
|
||||||
console.checkpoint('start HTTP server');
|
console.checkpoint('start HTTP server');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -118,10 +86,5 @@ function (http, nodeStatic, Api, fs) {
|
||||||
return this.server;
|
return this.server;
|
||||||
}
|
}
|
||||||
|
|
||||||
HttpServer.prototype.handleFileError = function (res) {
|
|
||||||
res.writeHead(404, {'Content-Type': 'text/html'});
|
|
||||||
res.end('<h1>404 not ... found</h1>');
|
|
||||||
}
|
|
||||||
|
|
||||||
return HttpServer;
|
return HttpServer;
|
||||||
});
|
});
|
||||||
|
|
@ -4,30 +4,23 @@ define([
|
||||||
|
|
||||||
function (io) {
|
function (io) {
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
function Socket (server, options, coordinator) {
|
function Socket (server, options, coordinator) {
|
||||||
options.logLevel = typeof options.logLevel != 'undefined'
|
|
||||||
? options.logLevel
|
|
||||||
: 0;
|
|
||||||
|
|
||||||
this.coordinator = coordinator;
|
this.coordinator = coordinator;
|
||||||
this.socket = io(server, {
|
this.io = io(server, {
|
||||||
'log level': options.logLevel,
|
// No more 'log level' or 'transports' in v4
|
||||||
//'transports': ['websockets']
|
// Add any v4-compatible options here if needed
|
||||||
});
|
});
|
||||||
|
|
||||||
this.init(options);
|
this.init(options);
|
||||||
}
|
}
|
||||||
|
|
||||||
Socket.prototype.init = function (options) {
|
Socket.prototype.init = function (options) {
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
this.socket.on('connection', function (user) {
|
this.io.on('connection', function (socket) {
|
||||||
console.checkpoint('socket receiving connection');
|
console.checkpoint('socket receiving connection');
|
||||||
self.onConnection(user);
|
self.onConnection(socket);
|
||||||
});
|
});
|
||||||
|
|
||||||
console.checkpoint('start Socket Listener');
|
console.checkpoint('start Socket Listener');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -32,13 +32,7 @@ function (Networker, io, Settings, Exception, nc, Menu) {
|
||||||
var menu = new Menu();
|
var menu = new Menu();
|
||||||
menu.onRun = function(channelName, nickname) {
|
menu.onRun = function(channelName, nickname) {
|
||||||
var options = {
|
var options = {
|
||||||
"reconnect": false,
|
transports: ["websocket"] // v4: only use websocket, flashsocket is gone
|
||||||
"reconnection delay": 500,
|
|
||||||
"max reconnection attempts": 10,
|
|
||||||
"transports": [
|
|
||||||
"websocket",
|
|
||||||
"flashsocket"
|
|
||||||
]
|
|
||||||
};
|
};
|
||||||
var socket = io("/", options);
|
var socket = io("/", options);
|
||||||
var networker = new Networker(socket, channelName, nickname);
|
var networker = new Networker(socket, channelName, nickname);
|
||||||
|
|
|
||||||
2484
package-lock.json
generated
2484
package-lock.json
generated
File diff suppressed because it is too large
Load diff
23
package.json
23
package.json
|
|
@ -15,23 +15,28 @@
|
||||||
"url": "https://github.com/logsol/chuck.js/issues",
|
"url": "https://github.com/logsol/chuck.js/issues",
|
||||||
"email": "fartman@gmx.de"
|
"email": "fartman@gmx.de"
|
||||||
},
|
},
|
||||||
"main": "",
|
"main": "server.js",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"socket.io": "= 2.0.3",
|
"socket.io": "^4.7.4",
|
||||||
"node-static": ">= 0.6.0",
|
"express": "^4.18.2",
|
||||||
"requirejs": "= 2.0.4",
|
"requirejs": "^2.3.6",
|
||||||
"node-fork": ">= 0.4.2",
|
"screenfull": "^6.0.2",
|
||||||
"screenfull": ">= 1.0.4",
|
"chart.js": "^4.4.0"
|
||||||
"chart.js": "= 1.0.1"
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"nodemon": "^3.0.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {},
|
|
||||||
"optionalDependencies": {},
|
"optionalDependencies": {},
|
||||||
"engine": "node >= 0.8.4",
|
"engines": {
|
||||||
|
"node": ">=16.0.0"
|
||||||
|
},
|
||||||
"config": {
|
"config": {
|
||||||
"port": "1234"
|
"port": "1234"
|
||||||
},
|
},
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
"start": "node server.js",
|
||||||
|
"dev": "nodemon server.js",
|
||||||
"prestart": "scripts/build.sh"
|
"prestart": "scripts/build.sh"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
174
static/vendor/screenfull.js
vendored
Normal file
174
static/vendor/screenfull.js
vendored
Normal file
|
|
@ -0,0 +1,174 @@
|
||||||
|
/* eslint-disable promise/prefer-await-to-then */
|
||||||
|
|
||||||
|
const methodMap = [
|
||||||
|
[
|
||||||
|
'requestFullscreen',
|
||||||
|
'exitFullscreen',
|
||||||
|
'fullscreenElement',
|
||||||
|
'fullscreenEnabled',
|
||||||
|
'fullscreenchange',
|
||||||
|
'fullscreenerror',
|
||||||
|
],
|
||||||
|
// New WebKit
|
||||||
|
[
|
||||||
|
'webkitRequestFullscreen',
|
||||||
|
'webkitExitFullscreen',
|
||||||
|
'webkitFullscreenElement',
|
||||||
|
'webkitFullscreenEnabled',
|
||||||
|
'webkitfullscreenchange',
|
||||||
|
'webkitfullscreenerror',
|
||||||
|
|
||||||
|
],
|
||||||
|
// Old WebKit
|
||||||
|
[
|
||||||
|
'webkitRequestFullScreen',
|
||||||
|
'webkitCancelFullScreen',
|
||||||
|
'webkitCurrentFullScreenElement',
|
||||||
|
'webkitCancelFullScreen',
|
||||||
|
'webkitfullscreenchange',
|
||||||
|
'webkitfullscreenerror',
|
||||||
|
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'mozRequestFullScreen',
|
||||||
|
'mozCancelFullScreen',
|
||||||
|
'mozFullScreenElement',
|
||||||
|
'mozFullScreenEnabled',
|
||||||
|
'mozfullscreenchange',
|
||||||
|
'mozfullscreenerror',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'msRequestFullscreen',
|
||||||
|
'msExitFullscreen',
|
||||||
|
'msFullscreenElement',
|
||||||
|
'msFullscreenEnabled',
|
||||||
|
'MSFullscreenChange',
|
||||||
|
'MSFullscreenError',
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
const nativeAPI = (() => {
|
||||||
|
if (typeof document === 'undefined') {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const unprefixedMethods = methodMap[0];
|
||||||
|
const returnValue = {};
|
||||||
|
|
||||||
|
for (const methodList of methodMap) {
|
||||||
|
const exitFullscreenMethod = methodList?.[1];
|
||||||
|
if (exitFullscreenMethod in document) {
|
||||||
|
for (const [index, method] of methodList.entries()) {
|
||||||
|
returnValue[unprefixedMethods[index]] = method;
|
||||||
|
}
|
||||||
|
|
||||||
|
return returnValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
})();
|
||||||
|
|
||||||
|
const eventNameMap = {
|
||||||
|
change: nativeAPI.fullscreenchange,
|
||||||
|
error: nativeAPI.fullscreenerror,
|
||||||
|
};
|
||||||
|
|
||||||
|
// eslint-disable-next-line import/no-mutable-exports
|
||||||
|
let screenfull = {
|
||||||
|
// eslint-disable-next-line default-param-last
|
||||||
|
request(element = document.documentElement, options) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const onFullScreenEntered = () => {
|
||||||
|
screenfull.off('change', onFullScreenEntered);
|
||||||
|
resolve();
|
||||||
|
};
|
||||||
|
|
||||||
|
screenfull.on('change', onFullScreenEntered);
|
||||||
|
|
||||||
|
const returnPromise = element[nativeAPI.requestFullscreen](options);
|
||||||
|
|
||||||
|
if (returnPromise instanceof Promise) {
|
||||||
|
returnPromise.then(onFullScreenEntered).catch(reject);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
exit() {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
if (!screenfull.isFullscreen) {
|
||||||
|
resolve();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const onFullScreenExit = () => {
|
||||||
|
screenfull.off('change', onFullScreenExit);
|
||||||
|
resolve();
|
||||||
|
};
|
||||||
|
|
||||||
|
screenfull.on('change', onFullScreenExit);
|
||||||
|
|
||||||
|
const returnPromise = document[nativeAPI.exitFullscreen]();
|
||||||
|
|
||||||
|
if (returnPromise instanceof Promise) {
|
||||||
|
returnPromise.then(onFullScreenExit).catch(reject);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
toggle(element, options) {
|
||||||
|
return screenfull.isFullscreen ? screenfull.exit() : screenfull.request(element, options);
|
||||||
|
},
|
||||||
|
onchange(callback) {
|
||||||
|
screenfull.on('change', callback);
|
||||||
|
},
|
||||||
|
onerror(callback) {
|
||||||
|
screenfull.on('error', callback);
|
||||||
|
},
|
||||||
|
on(event, callback) {
|
||||||
|
const eventName = eventNameMap[event];
|
||||||
|
if (eventName) {
|
||||||
|
document.addEventListener(eventName, callback, false);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
off(event, callback) {
|
||||||
|
const eventName = eventNameMap[event];
|
||||||
|
if (eventName) {
|
||||||
|
document.removeEventListener(eventName, callback, false);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
raw: nativeAPI,
|
||||||
|
};
|
||||||
|
|
||||||
|
Object.defineProperties(screenfull, {
|
||||||
|
isFullscreen: {
|
||||||
|
get: () => Boolean(document[nativeAPI.fullscreenElement]),
|
||||||
|
},
|
||||||
|
element: {
|
||||||
|
enumerable: true,
|
||||||
|
get: () => document[nativeAPI.fullscreenElement] ?? undefined,
|
||||||
|
},
|
||||||
|
isEnabled: {
|
||||||
|
enumerable: true,
|
||||||
|
// Coerce to boolean in case of old WebKit.
|
||||||
|
get: () => Boolean(document[nativeAPI.fullscreenEnabled]),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!nativeAPI) {
|
||||||
|
screenfull = {isEnabled: false};
|
||||||
|
}
|
||||||
|
|
||||||
|
// UMD wrapper to make screenfull available globally
|
||||||
|
(function (root, factory) {
|
||||||
|
if (typeof define === 'function' && define.amd) {
|
||||||
|
// AMD
|
||||||
|
define(factory);
|
||||||
|
} else if (typeof module === 'object' && module.exports) {
|
||||||
|
// CommonJS
|
||||||
|
module.exports = factory();
|
||||||
|
} else {
|
||||||
|
// Browser globals
|
||||||
|
root.screenfull = factory();
|
||||||
|
}
|
||||||
|
}(typeof self !== 'undefined' ? self : this, function () {
|
||||||
|
return screenfull;
|
||||||
|
}));
|
||||||
Loading…
Add table
Add a link
Reference in a new issue