GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — StreamDesk/server.js at main · Epyxx/StreamDesk

Expand file tree

/

server.js

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
70 lines (61 loc) · 3.45 KB
/

server.js

Copy path

File metadata and controls

70 lines (61 loc) · 3.45 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
const express = require('express');
const http = require('http');
const path = require('path');
const { WebSocketServer } = require('ws');
const { PORT, CLIENT_ID, CLIENT_SECRET, REDIRECT_URI } = require('./src/config');
const { log, logError } = require('./src/logger');
const { sendToClient } = require('./src/helpers');
const { createClientState } = require('./src/clientState');
const { handleStartOAuth, handleOAuthLogin, registerOAuthCallback, saveStateOnDisconnect } = require('./src/oauth');
const {
handleJoinChannel, handleLeaveChannel, handleSendMessage, handleGetUserInfo, handleModAction, handleLogout,
handleCreatePoll, handleEndPoll, handleCreatePrediction, handleResolvePrediction,
} = require('./src/wsHandlers');
if (!CLIENT_ID || !CLIENT_SECRET || !REDIRECT_URI) {
logError('SERVER', 'TWITCH_CLIENT_ID, TWITCH_CLIENT_SECRET und TWITCH_REDIRECT_URI müssen in der .env-Datei gesetzt sein.');
process.exit(1);
}
const app = express();
app.use(express.static(path.join(__dirname, 'public')));
app.get('/', (req, res) => res.sendFile(path.join(__dirname, 'public', 'index.html')));
app.get('/favicon.ico', (req, res) => res.status(204).end());
registerOAuthCallback(app);
const server = http.createServer(app);
const wss = new WebSocketServer({ server });
const clients = new Map();
wss.on('connection', (ws) => {
log('WS', `Neue Verbindung (${clients.size + 1} aktiv)`);
const clientState = createClientState();
clients.set(ws, clientState);
ws.on('message', async (raw) => {
let msg; try { msg = JSON.parse(raw.toString()); } catch (e) { return; }
try {
switch (msg.type) {
case 'login_oauth': await handleOAuthLogin(ws, clientState, msg.token); break;
case 'start_oauth': handleStartOAuth(ws); break;
case 'get_mod_channels': sendToClient(ws, { type: 'mod_channels', channels: [] }); break;
case 'join_channel': await handleJoinChannel(ws, clientState, msg.channel); break;
case 'leave_channel': await handleLeaveChannel(ws, clientState, msg.channel); break;
case 'send_message': await handleSendMessage(ws, clientState, msg); break;
case 'get_user_info': await handleGetUserInfo(ws, clientState, msg); break;
case 'mod_action': await handleModAction(ws, clientState, msg); break;
case 'create_poll': await handleCreatePoll(ws, clientState, msg); break;
case 'end_poll': await handleEndPoll(ws, clientState, msg); break;
case 'create_prediction': await handleCreatePrediction(ws, clientState, msg); break;
case 'resolve_prediction': await handleResolvePrediction(ws, clientState, msg); break;
case 'update_filter': clientState.filters.set(msg.channel.toLowerCase(), msg.words || []); break;
case 'logout': handleLogout(ws, clientState); break;
}
} catch (e) {
logError('WS', `Fehler bei "${msg?.type}": ${e.message}`);
sendToClient(ws, { type: 'error', message: e.message });
}
});
ws.on('close', () => {
saveStateOnDisconnect(clientState);
handleLogout(ws, clientState);
clients.delete(ws);
log('WS', `Verbindung geschlossen${clientState.username ? ` (@${clientState.username})` : ''} (${clients.size} aktiv)`);
});
});
server.listen(PORT, () => log('SERVER', `🚀 StreamDesk v1.2.2 läuft auf http://localhost:${PORT}`));
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.