Skip to content

Commit

Permalink
using wss if on https
Browse files Browse the repository at this point in the history
  • Loading branch information
NivEz committed Aug 19, 2023
1 parent 18b0d62 commit eec9d4f
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion client/src/hooks/useWebsocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ export const useWebsocket = ({
}) => {
const [reMemo, setReMemo] = useState(null);

const ws = useMemo(() => new WebSocket(`ws://${host}`), [reMemo]);
const ws = useMemo(() => {
const protocol = location.protocol === "https:" ? "wss" : "ws";
return new WebSocket(`${protocol}://${host}`), [reMemo];
});

const sendMessage = useCallback((commandType, commandValue = '') => {
ws.send(`${commandType}!${commandValue}`);
Expand Down

0 comments on commit eec9d4f

Please sign in to comment.