From b5a93bb31fca918e2bf24a2048b205f6c5a47bc1 Mon Sep 17 00:00:00 2001 From: Aadarsha Acharya Date: Sat, 25 Sep 2021 14:56:59 +0545 Subject: [PATCH 1/3] feat: add chatbox --- server/controllers/room.controller.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/server/controllers/room.controller.ts b/server/controllers/room.controller.ts index 9ac7f8a..fe56d45 100755 --- a/server/controllers/room.controller.ts +++ b/server/controllers/room.controller.ts @@ -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 From 5736eb0e279a34062f80e365224ab3d69432f59a Mon Sep 17 00:00:00 2001 From: Aadarsha Acharya Date: Thu, 14 Oct 2021 00:31:26 +0545 Subject: [PATCH 2/3] fix: connect and disconnect room issues --- client/src/_context/room/room.state.tsx | 1 + client/src/components/CreateRoom/CreateRoom.tsx | 4 ++-- client/src/constants/sockets.ts | 4 ++-- server/constants/sockets.ts | 4 ++-- server/controllers/room.controller.ts | 1 + 5 files changed, 8 insertions(+), 6 deletions(-) diff --git a/client/src/_context/room/room.state.tsx b/client/src/_context/room/room.state.tsx index f504eab..be4092c 100755 --- a/client/src/_context/room/room.state.tsx +++ b/client/src/_context/room/room.state.tsx @@ -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) { diff --git a/client/src/components/CreateRoom/CreateRoom.tsx b/client/src/components/CreateRoom/CreateRoom.tsx index cf5d099..f01042d 100755 --- a/client/src/components/CreateRoom/CreateRoom.tsx +++ b/client/src/components/CreateRoom/CreateRoom.tsx @@ -20,8 +20,8 @@ const CreateRoom = () => { const onFormSubmit = (values: IVal) => { createRoom(values); - playIpl(); - message.success('New room created ! 🔥 '); + // playIpl(); + // message.success('New room created ! 🔥 '); }; const [form] = Form.useForm(); diff --git a/client/src/constants/sockets.ts b/client/src/constants/sockets.ts index c223af1..cf7b6b6 100644 --- a/client/src/constants/sockets.ts +++ b/client/src/constants/sockets.ts @@ -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`; diff --git a/server/constants/sockets.ts b/server/constants/sockets.ts index c223af1..3577a98 100644 --- a/server/constants/sockets.ts +++ b/server/constants/sockets.ts @@ -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`; diff --git a/server/controllers/room.controller.ts b/server/controllers/room.controller.ts index fe56d45..ebcc02d 100755 --- a/server/controllers/room.controller.ts +++ b/server/controllers/room.controller.ts @@ -156,6 +156,7 @@ const socketio = (server: Server) => { io.to(roomID).emit(SOCKETS_EVENTS_UPDATE_OUTPUT, output.data); } catch (error) { + // @ts-ignore console.log(error.message); } }); From 82c05ff6ba9f7ca38d51b78f6bcd4fbdc32b40e8 Mon Sep 17 00:00:00 2001 From: Aadarsha Acharya Date: Thu, 14 Oct 2021 00:39:38 +0545 Subject: [PATCH 3/3] refactor: room create and join validation schema --- client/src/_context/room/room.state.tsx | 2 ++ client/src/components/CreateRoom/CreateRoom.tsx | 10 +++------- client/src/components/JoinRoom/JoinRoom.tsx | 8 ++------ server/controllers/code.controller.ts | 1 + 4 files changed, 8 insertions(+), 13 deletions(-) diff --git a/client/src/_context/room/room.state.tsx b/client/src/_context/room/room.state.tsx index be4092c..84b5bf2 100755 --- a/client/src/_context/room/room.state.tsx +++ b/client/src/_context/room/room.state.tsx @@ -72,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) { diff --git a/client/src/components/CreateRoom/CreateRoom.tsx b/client/src/components/CreateRoom/CreateRoom.tsx index f01042d..962c104 100755 --- a/client/src/components/CreateRoom/CreateRoom.tsx +++ b/client/src/components/CreateRoom/CreateRoom.tsx @@ -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'; @@ -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(); @@ -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' > @@ -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' > diff --git a/client/src/components/JoinRoom/JoinRoom.tsx b/client/src/components/JoinRoom/JoinRoom.tsx index aa3859a..75518dd 100755 --- a/client/src/components/JoinRoom/JoinRoom.tsx +++ b/client/src/components/JoinRoom/JoinRoom.tsx @@ -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'; @@ -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(); @@ -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' > diff --git a/server/controllers/code.controller.ts b/server/controllers/code.controller.ts index ab03151..e4bb819 100755 --- a/server/controllers/code.controller.ts +++ b/server/controllers/code.controller.ts @@ -30,6 +30,7 @@ export const SubmitCode = async (req: Request, res: Response): Promise => 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' }); }