Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/isd-sgcu/cutu-2024
Browse files Browse the repository at this point in the history
  • Loading branch information
TeeGoood committed Mar 28, 2024
2 parents 3b3eb2c + 8858e5e commit 5999a1a
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
1 change: 1 addition & 0 deletions apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
},
"dependencies": {
"axios": "^1.6.8",
"@fingerprintjs/fingerprintjs": "^4.2.2",
"next": "14.1.4",
"react": "^18",
"react-dom": "^18",
Expand Down
9 changes: 9 additions & 0 deletions apps/web/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 29 additions & 1 deletion apps/web/src/app/(user)/shake/[university]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import { getMobileOperatingSystem } from "@/utils/getMobileOperatingSystem";
import ShakeComponent from '../../../../components/Shake';
import { useParams, useSearchParams } from "next/navigation";
import { Suspense } from 'react';
import { io } from "socket.io-client";
import FingerprintJS from '@fingerprintjs/fingerprintjs';
const [cid, setCid] = useState<string | null>(null);
let fid: string | null = null;

let shaking: { x: number; y: number; z: number } | undefined;

Expand All @@ -14,6 +18,24 @@ function normalize(x: number, y: number, z: number) {
return [x / len, y / len, z / len];
}

const socket = io('https://api.cutu2024.sgcu.in.th/');

socket.on('connect', async function () {
console.log('Client has connected to the server!');
const fp = await FingerprintJS.load();
const result = await fp.get();
fid = result.visitorId;
socket.emit('fid', fid);
});

socket.on('cid', function (serverCid: string) {
setCid(serverCid);
});

socket.on('disconnect', function () {
console.log('The client has disconnected!');
});

export default function Shake() {
const [motion1, setMotion1] = useState({
x: 0,
Expand Down Expand Up @@ -49,7 +71,13 @@ export default function Shake() {
y: motion1.y,
z: motion1.z,
};
setCount(count + 1);
setCount(prevCount => {
const newCount = prevCount + 1;
if (fid && cid) {
socket.emit('count', { count: newCount, fid, cid });
}
return newCount;
});
tickTime();
setTime(Math.round(peekTime()));
}
Expand Down

0 comments on commit 5999a1a

Please sign in to comment.