This commit is contained in:
2025-08-30 00:56:30 +02:00
commit a949b44233
4 changed files with 303 additions and 0 deletions

140
.gitignore vendored Normal file
View File

@@ -0,0 +1,140 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
# Runtime data
pids
*.pid
*.seed
*.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
*.lcov
# nyc test coverage
.nyc_output
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# Bower dependency directory (https://bower.io/)
bower_components
# node-waf configuration
.lock-wscript
# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules/
jspm_packages/
# Snowpack dependency directory (https://snowpack.dev/)
web_modules/
# TypeScript cache
*.tsbuildinfo
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Optional stylelint cache
.stylelintcache
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
# dotenv environment variable files
.env
.env.*
!.env.example
# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache
# Next.js build output
.next
out
# Nuxt.js build / generate output
.nuxt
dist
.output
# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public
# vuepress build output
.vuepress/dist
# vuepress v2.x temp and cache directory
.temp
.cache
# Sveltekit cache directory
.svelte-kit/
# vitepress build output
**/.vitepress/dist
# vitepress cache directory
**/.vitepress/cache
# Docusaurus cache and generated files
.docusaurus
# Serverless directories
.serverless/
# FuseBox cache
.fusebox/
# DynamoDB Local files
.dynamodb/
# Firebase cache directory
.firebase/
# TernJS port file
.tern-port
# Stores VSCode versions used for testing VSCode extensions
.vscode-test
# yarn v3
.pnp.*
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions
# Vite logs files
vite.config.js.timestamp-*
vite.config.ts.timestamp-*

111
index.js Normal file
View File

@@ -0,0 +1,111 @@
import WebSocket, { WebSocketServer } from 'ws';
let hostConnection;
let displayConnection;
const wss = new WebSocketServer({
port: 12345,
}, () => {
console.log("Websocket Server started\nListening on Port 12345")
});
wss.on('connection', (ws) => {
console.log("Trying to connect");
ws.on('error', console.error);
ws.on('message', (data) => {
if (ws == hostConnection || ws == displayConnection) return;
console.log('received: %s', data);
if (data == "HOST") {
if (hostConnection === undefined) {
hostConnection = ws;
initHostConnection();
}
else
{
ws.send("ERROR HOST");
ws.close();
}
} else if (data == "DISPLAY") {
if (displayConnection === undefined) {
displayConnection = ws;
initDisplayConnection();
}
else
{
ws.send("ERROR DISPLAY");
ws.close();
}
}
else
{
ws.send("ERROR MESSAGE");
ws.close();
}
})
// ws.send('Connected to server');
});
function initHostConnection() {
console.log("Initialize Host connection...");
hostConnection.on('message', (data) => {
console.log("[HOST] " + data);
if (displayConnection) {
displayConnection.send("" + data);
}
});
hostConnection.on('error', (data) => {
console.error("[HOST] " + data);
hostConnection = undefined;
if (displayConnection) {
displayConnection.send("HOST-DISCONNECTED");
}
});
hostConnection.on('close', (code, reason) => {
console.error("[HOST] " + code + " " + reason);
hostConnection = undefined;
if (displayConnection) {
displayConnection.send("HOST-DISCONNECTED");
}
});
hostConnection.send("HOST");
if (displayConnection) {
displayConnection.send("HOST-CONNECTED");
hostConnection.send("DISPLAY-CONNECTED");
}
}
function initDisplayConnection() {
console.log("Initialize Display connection...");
displayConnection.on('message', (data) => {
console.log("[DISPLAY] " + data);
});
displayConnection.on('error', (data) => {
console.error("[DISPLAY] " + data);
displayConnection = undefined;
if (hostConnection) {
hostConnection.send("DISPLAY-DISCONNECTED");
}
});
displayConnection.on('close', (code, reason) => {
console.error("[DISPLAY] " + code + " " + reason);
displayConnection = undefined;
if (hostConnection) {
hostConnection.send("DISPLAY-DISCONNECTED");
}
});
displayConnection.send("DISPLAY");
if (hostConnection) {
hostConnection.send("DISPLAY-CONNECTED");
displayConnection.send("HOST-CONNECTED");
}
}

37
package-lock.json generated Normal file
View File

@@ -0,0 +1,37 @@
{
"name": "jeopardyserver",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "jeopardyserver",
"version": "1.0.0",
"license": "ISC",
"dependencies": {
"ws": "^8.18.3"
}
},
"node_modules/ws": {
"version": "8.18.3",
"resolved": "https://registry.npmjs.org/ws/-/ws-8.18.3.tgz",
"integrity": "sha512-PEIGCY5tSlUt50cqyMXfCzX+oOPqN0vuGqWzbcJ2xvnkzkq46oOpz7dQaTDBdfICb4N14+GARUDw2XV2N4tvzg==",
"license": "MIT",
"engines": {
"node": ">=10.0.0"
},
"peerDependencies": {
"bufferutil": "^4.0.1",
"utf-8-validate": ">=5.0.2"
},
"peerDependenciesMeta": {
"bufferutil": {
"optional": true
},
"utf-8-validate": {
"optional": true
}
}
}
}
}

15
package.json Normal file
View File

@@ -0,0 +1,15 @@
{
"name": "jeopardyserver",
"version": "1.0.0",
"description": "",
"license": "ISC",
"author": "",
"type": "module",
"main": "index.js",
"scripts": {
"dev": "node index.js"
},
"dependencies": {
"ws": "^8.18.3"
}
}