Skip to content

Commit

Permalink
Change event names to be more consistent
Browse files Browse the repository at this point in the history
  • Loading branch information
fatfisz committed May 16, 2020
1 parent fdbe920 commit dc625b9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
12 changes: 6 additions & 6 deletions client/components/SocketContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import EventEmitter, { ListenerFn } from 'eventemitter3';
import {
ContextType,
createContext,
DependencyList,
ReactNode,
useCallback,
useEffect,
useMemo,
useState,
useCallback,
DependencyList,
} from 'react';
import io from 'socket.io-client';

Expand Down Expand Up @@ -59,7 +59,7 @@ export function SocketContextProvider({ children }: { children: ReactNode }) {
useSocketListener(socket, 'session estabilished', (session) => {
localStorage.setItem(storageIdKey, session.id);
setSession(session);
socket?.emit('session id received', session.id);
socket?.emit('confirm session', session.id);
});

useSocketListener(
Expand All @@ -75,9 +75,9 @@ export function SocketContextProvider({ children }: { children: ReactNode }) {
name,
currentSessionId: session.id,
addNextCard: useSocketEmitter(socket, 'add next card'),
joinRoom: useSocketEmitter(socket, 'room joined'),
selectSet: useSocketEmitter(socket, 'set selected'),
setName: useSocketEmitter(socket, 'name set'),
joinRoom: useSocketEmitter(socket, 'join room'),
selectSet: useSocketEmitter(socket, 'select set'),
setName: useSocketEmitter(socket, 'set name'),
onRoomStateChanged: useEventListenerSetter(
eventEmitter,
'room state changed'
Expand Down
8 changes: 4 additions & 4 deletions server/State.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class State {
return new Promise((resolve) => {
const { socket } = session;
socket?.emit('session estabilished', session.getState());
socket?.on('session id received', async (clientSessionId) => {
socket?.on('confirm session', async (clientSessionId) => {
if (clientSessionId === session.id) {
resolve(true);
} else {
Expand All @@ -52,7 +52,7 @@ export class State {
private setUpEvents(session: Session) {
const { socket } = session;

socket?.on('name set', (name) => {
socket?.on('set name', (name) => {
session.setName(name);
this.emitRoomStateChanged(session, true);
});
Expand All @@ -74,11 +74,11 @@ export class State {
this.emitRoomStateChanged(session, true);
});

socket?.on('room joined', () => {
socket?.on('join room', () => {
this.emitRoomStateChanged(session);
});

socket?.on('set selected', (cards) => {
socket?.on('select set', (cards) => {
const { room } = session;
if (!room) {
return;
Expand Down
8 changes: 4 additions & 4 deletions shared/types/ServerEvents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ export interface ServerEvents {
};
received: {
'add next card': [];
'room joined': [];
'name set': [string];
'set selected': [number[]];
'session id received': [string];
'confirm session': [string];
'join room': [];
'select set': [number[]];
'set name': [string];
};
}

0 comments on commit dc625b9

Please sign in to comment.