Skip to content

Commit

Permalink
asd
Browse files Browse the repository at this point in the history
  • Loading branch information
Bit-Barron committed Nov 2, 2024
1 parent 38d0060 commit ec1a8bb
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
4 changes: 0 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ services:
- 'traefik.http.routers.youtubepedia.entrypoints=websecure'
- 'traefik.http.routers.youtubepedia.tls.certresolver=letsencrypt'
- 'traefik.http.services.youtubepedia.loadbalancer.server.port=3000'
# WebSocket Middleware
- 'traefik.http.middlewares.youtubepedia-ws.headers.customrequestheaders.Connection=Upgrade'
- 'traefik.http.middlewares.youtubepedia-ws.headers.customrequestheaders.Upgrade=websocket'
- 'traefik.http.routers.youtubepedia.middlewares=youtubepedia-ws'

networks:
proxy:
Expand Down
16 changes: 12 additions & 4 deletions src/lib/server/socket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,17 @@ export const initSocketIO = (httpServer: HTTPServer): Promise<Server> => {
if (!io) {
console.log('Initializing Socket.IO server...');
io = new Server(httpServer, {
path: '/socket.io',
path: '/socket.io/',
cors: {
origin: dev ? ['http://localhost:3000'] : ['https://youtubepedia.barron.agency'],
methods: ['GET', 'POST'],
credentials: true
},
transports: ['websocket', 'polling']
transports: ['websocket', 'polling'],
pingTimeout: 60000,
pingInterval: 25000,
connectTimeout: 45000,
allowEIO3: true
});

io.on('connection', (socket) => {
Expand All @@ -29,8 +33,12 @@ export const initSocketIO = (httpServer: HTTPServer): Promise<Server> => {
console.log(`User ${userId} joined their room`);
}

socket.on('disconnect', () => {
console.log('Client disconnected', socket.id);
socket.on('error', (error) => {
console.error('Socket error:', error);
});

socket.on('disconnect', (reason) => {
console.log(`Client disconnected (${reason})`, socket.id);
});
});

Expand Down
5 changes: 3 additions & 2 deletions src/lib/socket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import { io, type Socket } from 'socket.io-client';

export const initSocket = (userId: string): Socket | null => {
if (browser) {
// Kein expliziter Port - nutze den gleichen Port wie die App
const socket = io(window.location.origin, {
const socketUrl = `${window.location.protocol}//${window.location.hostname}:3001`;

const socket = io(socketUrl, {
auth: { userId },
reconnection: true,
reconnectionDelay: 1000,
Expand Down

0 comments on commit ec1a8bb

Please sign in to comment.