diff --git a/.env b/.env index 4ace3ec..0efd8b0 100644 --- a/.env +++ b/.env @@ -1 +1 @@ -WDS_SOCKET_PORT=443 +WDS_SOCKET_PORT=4000 diff --git a/src/App.js b/src/App.js index 1f8c3b4..99a27a2 100644 --- a/src/App.js +++ b/src/App.js @@ -49,8 +49,12 @@ function App() { function onJoin(data) { console.log(' 🪲 APP onJoin data: ', data) setUser(data.user) - localStorage.setItem(data.pid, data.token) - navigate(`/poll/${data.pid}`) + if (data.code !== 404) { + localStorage.setItem(data.pid, data.token) + } + if (data.code === 204) { + navigate(`/poll/${data.pid}/join`) + } } function onPoll(data) { console.log(' 🪲 APP onPoll data: ', data) diff --git a/src/socket.jsx b/src/socket.jsx index 08a42af..8c9c1f1 100644 --- a/src/socket.jsx +++ b/src/socket.jsx @@ -1,12 +1,12 @@ import { io } from 'socket.io-client'; const options = { - rejectUnauthorized: false, // allow self-signed certs + rejectUnauthorized: false, requestCert: false, secure: false }; -// const URL = 'http://localhost:4000'; -const URL = 'https://pollback.vaidis.eu'; +const URL = 'http://localhost:4000'; +// const URL = 'https://pollback.vaidis.eu'; export const socket = io(URL, options); diff --git a/src/view/Answers.jsx b/src/view/Answers.jsx index c95d120..01a9219 100644 --- a/src/view/Answers.jsx +++ b/src/view/Answers.jsx @@ -2,12 +2,13 @@ import { useState, useEffect, useRef, useContext } from "react"; import classNames from "classnames"; const Answers = (props) => { - const { poll, user, socket, id, pid } = props; + const { poll, user, socket, id, pid, token } = props; const [winner, setWinner] = useState(0); - const token = localStorage.getItem(id) + // const token = localStorage.getItem(id) const onVote = async (answer) => { const data = { user:user, answer:answer, pid:pid, token:token } + console.log('VOTE data: ', data) socket.emit("vote", data); }; diff --git a/src/view/Poll.jsx b/src/view/Poll.jsx index 0c4e223..b73b9f6 100644 --- a/src/view/Poll.jsx +++ b/src/view/Poll.jsx @@ -41,38 +41,58 @@ function Poll(props) { } useEffect(() => { - console.log('POLL 🎱 props:', props) console.log('POLL 🎱 id:', id) console.log('POLL 🎱 exist:', exist) console.log('POLL 🎱 anon:', anon) + console.log('POLL 🎱 user:', user) console.log('POLL 🎱 token:', Boolean(token)) + console.log('POLL 🎱 poll:', poll) - if (exist === undefined) { - console.log('POLL emit.exist.id:', id) - socket.emit('exist', id) - } - if (exist && anon === undefined) { - console.log('POLL emit.info.id:', id) - socket.emit('info', id) - } - if (exist && anon !== undefined && anon && !token) { - const data = {pid:id, user:randomUser(24)}; - console.log('POLL emit.join.data:', data) + if (!token) { + const data = {pid:id}; + console.log(' 💾 POLL emit.join.data:', data) socket.emit('join', data); } - if (exist && anon !== undefined && !anon && !token) { - console.log('POLL redirect anon:', JSON.stringify(anon)) - return navigate(`/poll/${id}/join`) - } - if (exist && anon !== undefined && anon && token) { - const data = {pid:id, user:user}; - console.log('POLL emit.join.data:', data) + if (token) { + const data = {pid:id, token: token}; + console.log(' 💾 POLL emit.join.data:', data) socket.emit('join', data); } - if (exist && token) { + if (token && user) { console.log('POLL emit.poll.token:', token) socket.emit('poll', token); } + // if (exist === undefined) { + // console.log('POLL emit.exist.id:', id) + // socket.emit('exist', id) + // } + // if (exist && anon === undefined) { + // console.log('POLL emit.info.id:', id) + // socket.emit('info', id) + // } + // if (exist && anon !== undefined && anon && !token) { + // const data = {pid:id, user:randomUser(24)}; + // console.log(' 💾 POLL emit.join.data:', data) + // socket.emit('join', data); + // } + // if (exist && anon !== undefined && !anon && !token) { + // console.log('POLL redirect anon:', JSON.stringify(anon)) + // return navigate(`/poll/${id}/join`) + // } + // if (exist && anon !== undefined && anon && !token) { + // const data = {pid:id, user:randomUser(24)}; + // console.log(' 💾 POLL emit.join.data:', data) + // socket.emit('join', data); + // } + // if (exist && anon !== undefined && anon && token) { + // const data = {pid:id, user:user}; + // console.log(' 💾 💾 💾 POLL emit.join.data:', data) + // socket.emit('join', data); + // } + // if (exist && token) { + // console.log('POLL emit.poll.token:', token) + // socket.emit('poll', token); + // } },[id, exist, anon, token]) const onCopy = () => { @@ -86,8 +106,8 @@ function Poll(props) { {poll &&
Hello {poll.anonymous ? 'Anonymous' : user}, please choose the answer you like
-Hello {poll.anonymous ? 'Anonymous' : user}{user}, please choose the answer you like
+