Martin Berka e55ee7c11e
Some checks are pending
ci/woodpecker/push/workflow Pipeline is running
Refaktor: Nálezy SonarQube
2025-03-05 21:48:02 +01:00

21 lines
672 B
JavaScript

import React from 'react';
import socketio from "socket.io-client";
let socketUrl;
let socketPath;
if (process.env.NODE_ENV === 'development') {
socketUrl = `http://localhost:3001`;
socketPath = undefined;
} else {
socketUrl = `${window.location.host}`;
socketPath = `${window.location.pathname}socket.io`;
}
export const socket = socketio.connect(socketUrl, { path: socketPath, transports: ["websocket"] });
export const SocketContext = React.createContext();
// Konstanty websocket eventů, musí odpovídat těm na serveru!
export const EVENT_CONNECT = 'connect';
export const EVENT_DISCONNECT = 'disconnect';
export const EVENT_MESSAGE = 'message';