Skip to content

Commit

Permalink
yeahhh
Browse files Browse the repository at this point in the history
  • Loading branch information
tntons committed Mar 28, 2024
1 parent dfb23b9 commit 5fbf312
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions apps/web/src/app/(user)/shake/[university]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,14 @@ export default function Shake() {
};

const handleCid = (serverCid: string) => {
console.log('Received cid from server:');
cookies.set('cid', serverCid);
console.log('woo');
try {
console.log('Received cid from server:', serverCid);
cookies.set('cid', serverCid);
console.log('cid cookie set with value:', serverCid);
} catch (error) {
console.error('Error handling cid:', error);
}
};

const handleDisconnect = () => {
Expand All @@ -51,15 +57,17 @@ export default function Shake() {
extraHeaders.cid = savedCid;
}
console.log(extraHeaders);
const socket = io('wss://api.cutu2024.sgcu.in.th', { extraHeaders, path: "/api/ws", transports: ['websocket'] });
socket = io('wss://api.cutu2024.sgcu.in.th', {
auth: extraHeaders,
path: "/api/ws",
transports: ['websocket'],
});

socket.on('connect', handleConnect);
socket.on('cid', handleCid);
socket.on('disconnect', handleDisconnect);

return () => {
socket.off('connect', handleConnect);
socket.off('cid', handleCid);
socket.off('disconnect', handleDisconnect);
socket?.disconnect();
};
})();
}, []);
Expand Down Expand Up @@ -100,8 +108,8 @@ export default function Shake() {
};
setCount(prevCount => {
const newCount = prevCount + 1;
if (socket) {
socket?.emit('events', `${university} ${count}`);
if (socket?.connected) {
socket.emit("submit", `${university} ${count}`);
}
return newCount;
});
Expand Down

0 comments on commit 5fbf312

Please sign in to comment.