improvements

This commit is contained in:
sparshg
2024-09-23 22:34:35 +05:30
parent 44e72d77f2
commit 64f2c27bfc
6 changed files with 104 additions and 75 deletions

View File

@@ -12,15 +12,16 @@ export class State {
turn = $state(-1); // -1 not my turn, 0 might be, 1 is
socket: Socket;
constructor(hostname: string) {
let session = sessionStorage.getItem('session');
constructor(hostname: string, newSession: boolean = true) {
// let session = sessionStorage.getItem('session');
this.socket = io(`ws://${hostname}:3000/`, {
transports: ['websocket'],
auth: { session }
auth: { session: !newSession ? sessionStorage.getItem('session') : null }
});
this.socket.on('connect', () => {
console.log(this.socket.id);
sessionStorage.setItem('session', this.socket.id!);
});

View File

@@ -43,7 +43,7 @@
class="btn btn-error text-xl"
onclick={() => {
gameState.socket.emit('leave');
gameState = new State(window.location.hostname);
gameState = new State(window.location.hostname, true);
}}>Leave</button
>
</div>