Skip to content

Commit

Permalink
Merge pull request #21 from adarshaacharya/dev
Browse files Browse the repository at this point in the history
fix: room create and join issues
  • Loading branch information
adarshaacharya committed Oct 13, 2021
2 parents 53d51c4 + 82c05ff commit dc4a344
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 19 deletions.
3 changes: 3 additions & 0 deletions client/src/_context/room/room.state.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const RoomState: React.FC = ({ children }) => {
payload: room,
});
history.push(`/room/${room._id}`);
message.success('New room created ! 🔥 ');
});
setRoomUser(username); // set username in state
} catch (error) {
Expand Down Expand Up @@ -71,6 +72,8 @@ const RoomState: React.FC = ({ children }) => {
type: JOIN_ROOM,
payload: room,
});
message.success('You have joined the room. 🥳');

history.push(`/room/${roomID}`);
});
} catch (error) {
Expand Down
10 changes: 3 additions & 7 deletions client/src/components/CreateRoom/CreateRoom.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Button, Card, Form, Input, message } from 'antd';
import { useSfx } from 'hooks';
import { Button, Card, Form, Input } from 'antd';
import React from 'react';
import { useRoomContext } from '_context/room/room.context';
import styles from './style.module.css';
Expand All @@ -16,12 +15,9 @@ const layout = {

const CreateRoom = () => {
const { createRoom } = useRoomContext();
const { playIpl } = useSfx();

const onFormSubmit = (values: IVal) => {
createRoom(values);
playIpl();
message.success('New room created ! 🔥 ');
};

const [form] = Form.useForm();
Expand All @@ -35,7 +31,7 @@ const CreateRoom = () => {
label='Username'
rules={[
{ required: true, message: "Username can't be empty" },
{ max: 8, message: 'Username must be maximum 8 characters.' },
{ max: 20, message: 'Username must be maximum 20 characters.' },
]}
className='py'
>
Expand All @@ -46,7 +42,7 @@ const CreateRoom = () => {
label='Room Name'
rules={[
{ required: true, message: "Room name can't be empty" },
{ max: 8, message: 'Room name must be maximum 8 characters.' },
{ max: 15, message: 'Room name must be maximum 15 characters.' },
]}
className='py'
>
Expand Down
8 changes: 2 additions & 6 deletions client/src/components/JoinRoom/JoinRoom.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Button, Card, Form, Input, message } from 'antd';
import { useSfx } from 'hooks';
import { Button, Card, Form, Input } from 'antd';
import React from 'react';
import { useRoomContext } from '_context/room/room.context';
import styles from './style.module.css';
Expand All @@ -15,12 +14,9 @@ const layout = {

const JoinRoom = () => {
const { joinRoom } = useRoomContext();
const { playIpl } = useSfx();

const onFormSubmit = (values: IVal) => {
joinRoom(values);
message.success('You have joined the room. 🥳');
playIpl();
};

const [form] = Form.useForm();
Expand All @@ -41,7 +37,7 @@ const JoinRoom = () => {
label='Username'
rules={[
{ required: true, message: "Username can't be empty" },
{ max: 8, message: 'Username must be maximum 8 characters.' },
{ max: 20, message: 'Username must be maximum 20 characters.' },
]}
className='py'
>
Expand Down
4 changes: 2 additions & 2 deletions client/src/constants/sockets.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export const SOCKETS_EVENT = `socket.event`;

export const SOCKETS_EVENT_CONNECTED = `${SOCKETS_EVENT}.connection`;
export const SOCKETS_EVENT_DISCONNECTED = `${SOCKETS_EVENT}.disconnect`;
export const SOCKETS_EVENT_CONNECTED = `connect`;
export const SOCKETS_EVENT_DISCONNECTED = `disconnect`;
export const SOCKETS_EVENT_CONNECTION_ERROR = `${SOCKETS_EVENT}.connection.error`;

export const SOCKETS_EVENT_USER_JOINED = `${SOCKETS_EVENT}.join.room`;
Expand Down
4 changes: 2 additions & 2 deletions server/constants/sockets.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export const SOCKETS_EVENT = `socket.event`;

export const SOCKETS_EVENT_CONNECTED = `${SOCKETS_EVENT}.connection`;
export const SOCKETS_EVENT_DISCONNECTED = `${SOCKETS_EVENT}.disconnect`;
export const SOCKETS_EVENT_CONNECTED = `connection`;
export const SOCKETS_EVENT_DISCONNECTED = `disconnect`;
export const SOCKETS_EVENT_CONNECTION_ERROR = `${SOCKETS_EVENT}.connection.error`;

export const SOCKETS_EVENT_USER_JOINED = `${SOCKETS_EVENT}.join.room`;
Expand Down
1 change: 1 addition & 0 deletions server/controllers/code.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export const SubmitCode = async (req: Request, res: Response): Promise<void> =>
const output = await Axios.post(uri, data, axiosConfig);
res.status(201).json(output.data);
} catch (err) {
// @ts-ignore
console.log(err.message);
res.status(500).json({ msg: 'Server error' });
}
Expand Down
6 changes: 4 additions & 2 deletions server/controllers/room.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ import mongoose from 'mongoose';
import socketIO, { Socket } from 'socket.io';
import Room from '../models/room.model';
import getExtension from '../utils/lang-to-extension';
import { Server } from 'http';

const socketio = (server: any) => {
const socketio = (server: Server) => {
const io = socketIO(server);

// socket config
io.on(SOCKETS_EVENT_CONNECTED, (socket : Socket) => {
io.on(SOCKETS_EVENT_CONNECTED, (socket: Socket) => {
console.log('✅ Connected to room.');

// create new room
Expand Down Expand Up @@ -155,6 +156,7 @@ const socketio = (server: any) => {

io.to(roomID).emit(SOCKETS_EVENTS_UPDATE_OUTPUT, output.data);
} catch (error) {
// @ts-ignore
console.log(error.message);
}
});
Expand Down

0 comments on commit dc4a344

Please sign in to comment.