├── backend
├── .eslintrc.js
├── .gitignore
├── .prettierrc
├── README.md
├── nest-cli.json
├── package-lock.json
├── package.json
├── src
│ ├── app.controller.spec.ts
│ ├── app.controller.ts
│ ├── app.module.ts
│ ├── app.service.ts
│ ├── main.ts
│ └── messages
│ │ ├── dto
│ │ └── create-message.dto.ts
│ │ ├── entities
│ │ └── message.entity.ts
│ │ ├── messages.gateway.ts
│ │ ├── messages.module.ts
│ │ └── messages.service.ts
├── test
│ ├── app.e2e-spec.ts
│ └── jest-e2e.json
├── tsconfig.build.json
└── tsconfig.json
└── chat-frontend
├── .gitignore
├── README.md
├── package-lock.json
├── package.json
├── public
├── favicon.ico
├── index.html
├── logo192.png
├── logo512.png
├── manifest.json
└── robots.txt
└── src
├── App.css
├── App.js
├── index.css
├── index.js
├── reportWebVitals.js
└── setupTests.js
/backend/.eslintrc.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | parser: '@typescript-eslint/parser',
3 | parserOptions: {
4 | project: 'tsconfig.json',
5 | tsconfigRootDir : __dirname,
6 | sourceType: 'module',
7 | },
8 | plugins: ['@typescript-eslint/eslint-plugin'],
9 | extends: [
10 | 'plugin:@typescript-eslint/recommended',
11 | 'plugin:prettier/recommended',
12 | ],
13 | root: true,
14 | env: {
15 | node: true,
16 | jest: true,
17 | },
18 | ignorePatterns: ['.eslintrc.js'],
19 | rules: {
20 | '@typescript-eslint/interface-name-prefix': 'off',
21 | '@typescript-eslint/explicit-function-return-type': 'off',
22 | '@typescript-eslint/explicit-module-boundary-types': 'off',
23 | '@typescript-eslint/no-explicit-any': 'off',
24 | },
25 | };
26 |
--------------------------------------------------------------------------------
/backend/.gitignore:
--------------------------------------------------------------------------------
1 | # compiled output
2 | /dist
3 | /node_modules
4 |
5 | # Logs
6 | logs
7 | *.log
8 | npm-debug.log*
9 | pnpm-debug.log*
10 | yarn-debug.log*
11 | yarn-error.log*
12 | lerna-debug.log*
13 |
14 | # OS
15 | .DS_Store
16 |
17 | # Tests
18 | /coverage
19 | /.nyc_output
20 |
21 | # IDEs and editors
22 | /.idea
23 | .project
24 | .classpath
25 | .c9/
26 | *.launch
27 | .settings/
28 | *.sublime-workspace
29 |
30 | # IDE - VSCode
31 | .vscode/*
32 | !.vscode/settings.json
33 | !.vscode/tasks.json
34 | !.vscode/launch.json
35 | !.vscode/extensions.json
--------------------------------------------------------------------------------
/backend/.prettierrc:
--------------------------------------------------------------------------------
1 | {
2 | "singleQuote": true,
3 | "trailingComma": "all"
4 | }
--------------------------------------------------------------------------------
/backend/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | [circleci-image]: https://img.shields.io/circleci/build/github/nestjs/nest/master?token=abc123def456
6 | [circleci-url]: https://circleci.com/gh/nestjs/nest
7 |
8 | A progressive Node.js framework for building efficient and scalable server-side applications.
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
24 |
25 | ## Description
26 |
27 | [Nest](https://github.com/nestjs/nest) framework TypeScript starter repository.
28 |
29 | ## Installation
30 |
31 | ```bash
32 | $ npm install
33 | ```
34 |
35 | ## Running the app
36 |
37 | ```bash
38 | # development
39 | $ npm run start
40 |
41 | # watch mode
42 | $ npm run start:dev
43 |
44 | # production mode
45 | $ npm run start:prod
46 | ```
47 |
48 | ## Test
49 |
50 | ```bash
51 | # unit tests
52 | $ npm run test
53 |
54 | # e2e tests
55 | $ npm run test:e2e
56 |
57 | # test coverage
58 | $ npm run test:cov
59 | ```
60 |
61 | ## Support
62 |
63 | Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please [read more here](https://docs.nestjs.com/support).
64 |
65 | ## Stay in touch
66 |
67 | - Author - [Kamil Myśliwiec](https://kamilmysliwiec.com)
68 | - Website - [https://nestjs.com](https://nestjs.com/)
69 | - Twitter - [@nestframework](https://twitter.com/nestframework)
70 |
71 | ## License
72 |
73 | Nest is [MIT licensed](LICENSE).
74 |
--------------------------------------------------------------------------------
/backend/nest-cli.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "https://json.schemastore.org/nest-cli",
3 | "collection": "@nestjs/schematics",
4 | "sourceRoot": "src"
5 | }
6 |
--------------------------------------------------------------------------------
/backend/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "backend",
3 | "version": "0.0.1",
4 | "description": "",
5 | "author": "",
6 | "private": true,
7 | "license": "UNLICENSED",
8 | "scripts": {
9 | "prebuild": "rimraf dist",
10 | "build": "nest build",
11 | "format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
12 | "start": "nest start",
13 | "start:dev": "nest start --watch",
14 | "start:debug": "nest start --debug --watch",
15 | "start:prod": "node dist/main",
16 | "lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
17 | "test": "jest",
18 | "test:watch": "jest --watch",
19 | "test:cov": "jest --coverage",
20 | "test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
21 | "test:e2e": "jest --config ./test/jest-e2e.json"
22 | },
23 | "dependencies": {
24 | "@nestjs/common": "^8.0.0",
25 | "@nestjs/core": "^8.0.0",
26 | "@nestjs/mapped-types": "*",
27 | "@nestjs/platform-express": "^8.0.0",
28 | "@nestjs/platform-socket.io": "^8.4.5",
29 | "@nestjs/websockets": "^8.4.5",
30 | "reflect-metadata": "^0.1.13",
31 | "rimraf": "^3.0.2",
32 | "rxjs": "^7.2.0",
33 | "socket.io": "^4.5.1"
34 | },
35 | "devDependencies": {
36 | "@nestjs/cli": "^8.0.0",
37 | "@nestjs/schematics": "^8.0.0",
38 | "@nestjs/testing": "^8.0.0",
39 | "@types/express": "^4.17.13",
40 | "@types/jest": "27.5.0",
41 | "@types/node": "^16.0.0",
42 | "@types/supertest": "^2.0.11",
43 | "@typescript-eslint/eslint-plugin": "^5.0.0",
44 | "@typescript-eslint/parser": "^5.0.0",
45 | "eslint": "^8.0.1",
46 | "eslint-config-prettier": "^8.3.0",
47 | "eslint-plugin-prettier": "^4.0.0",
48 | "jest": "28.0.3",
49 | "prettier": "^2.3.2",
50 | "source-map-support": "^0.5.20",
51 | "supertest": "^6.1.3",
52 | "ts-jest": "28.0.1",
53 | "ts-loader": "^9.2.3",
54 | "ts-node": "^10.0.0",
55 | "tsconfig-paths": "4.0.0",
56 | "typescript": "^4.3.5"
57 | },
58 | "jest": {
59 | "moduleFileExtensions": [
60 | "js",
61 | "json",
62 | "ts"
63 | ],
64 | "rootDir": "src",
65 | "testRegex": ".*\\.spec\\.ts$",
66 | "transform": {
67 | "^.+\\.(t|j)s$": "ts-jest"
68 | },
69 | "collectCoverageFrom": [
70 | "**/*.(t|j)s"
71 | ],
72 | "coverageDirectory": "../coverage",
73 | "testEnvironment": "node"
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/backend/src/app.controller.spec.ts:
--------------------------------------------------------------------------------
1 | import { Test, TestingModule } from '@nestjs/testing';
2 | import { AppController } from './app.controller';
3 | import { AppService } from './app.service';
4 |
5 | describe('AppController', () => {
6 | let appController: AppController;
7 |
8 | beforeEach(async () => {
9 | const app: TestingModule = await Test.createTestingModule({
10 | controllers: [AppController],
11 | providers: [AppService],
12 | }).compile();
13 |
14 | appController = app.get(AppController);
15 | });
16 |
17 | describe('root', () => {
18 | it('should return "Hello World!"', () => {
19 | expect(appController.getHello()).toBe('Hello World!');
20 | });
21 | });
22 | });
23 |
--------------------------------------------------------------------------------
/backend/src/app.controller.ts:
--------------------------------------------------------------------------------
1 | import { Controller, Get } from '@nestjs/common';
2 | import { AppService } from './app.service';
3 |
4 | @Controller()
5 | export class AppController {
6 | constructor(private readonly appService: AppService) {}
7 |
8 | @Get()
9 | getHello(): string {
10 | return this.appService.getHello();
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/backend/src/app.module.ts:
--------------------------------------------------------------------------------
1 | import { Module } from '@nestjs/common';
2 | import { AppController } from './app.controller';
3 | import { AppService } from './app.service';
4 | import { MessagesModule } from './messages/messages.module';
5 |
6 | @Module({
7 | imports: [MessagesModule],
8 | controllers: [AppController],
9 | providers: [AppService],
10 | })
11 | export class AppModule {}
12 |
--------------------------------------------------------------------------------
/backend/src/app.service.ts:
--------------------------------------------------------------------------------
1 | import { Injectable } from '@nestjs/common';
2 |
3 | @Injectable()
4 | export class AppService {
5 | getHello(): string {
6 | return 'Hello World!';
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/backend/src/main.ts:
--------------------------------------------------------------------------------
1 | import { NestFactory } from '@nestjs/core';
2 | import { AppModule } from './app.module';
3 |
4 | async function bootstrap() {
5 | const app = await NestFactory.create(AppModule);
6 | await app.listen(3001);
7 | }
8 | bootstrap();
9 |
--------------------------------------------------------------------------------
/backend/src/messages/dto/create-message.dto.ts:
--------------------------------------------------------------------------------
1 | import { Message } from '../entities/message.entity';
2 |
3 | export class CreateMessageDto extends Message {}
4 |
--------------------------------------------------------------------------------
/backend/src/messages/entities/message.entity.ts:
--------------------------------------------------------------------------------
1 | export class Message {
2 | name: string;
3 | message: string;
4 | }
5 |
--------------------------------------------------------------------------------
/backend/src/messages/messages.gateway.ts:
--------------------------------------------------------------------------------
1 | import {
2 | WebSocketGateway,
3 | SubscribeMessage,
4 | MessageBody,
5 | WebSocketServer,
6 | ConnectedSocket,
7 | } from '@nestjs/websockets';
8 | import { MessagesService } from './messages.service';
9 | import { CreateMessageDto } from './dto/create-message.dto';
10 | import { Server, Socket } from 'socket.io';
11 |
12 | @WebSocketGateway({
13 | cors: {
14 | origins: '*',
15 | },
16 | })
17 | export class MessagesGateway {
18 | @WebSocketServer()
19 | server: Server;
20 |
21 | constructor(private readonly messagesService: MessagesService) {}
22 |
23 | @SubscribeMessage('createMessage')
24 | async create(
25 | @MessageBody() createMessageDto: CreateMessageDto,
26 | @ConnectedSocket() client: Socket,
27 | ) {
28 | const message = await this.messagesService.create(
29 | createMessageDto,
30 | client.id,
31 | );
32 | this.server.emit('message', message);
33 | return;
34 | }
35 |
36 | @SubscribeMessage('findAllMessages')
37 | findAll() {
38 | return this.messagesService.findAll();
39 | }
40 |
41 | @SubscribeMessage('removeMessage')
42 | remove(@MessageBody() id: number) {
43 | return this.messagesService.remove(id);
44 | }
45 |
46 | @SubscribeMessage('join')
47 | joinRoom(
48 | @MessageBody('name') name: string,
49 | @ConnectedSocket() client: Socket,
50 | ) {
51 | console.log(client.id);
52 | return this.messagesService.identify(name, client.id);
53 | }
54 |
55 | @SubscribeMessage('typing')
56 | async typing(
57 | @MessageBody('isTyping') isTyping: boolean,
58 | @ConnectedSocket() client: Socket,
59 | ) {
60 | const name = this.messagesService.getClientByName(client.id);
61 | client.broadcast.emit('typing', { name, isTyping });
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/backend/src/messages/messages.module.ts:
--------------------------------------------------------------------------------
1 | import { Module } from '@nestjs/common';
2 | import { MessagesService } from './messages.service';
3 | import { MessagesGateway } from './messages.gateway';
4 |
5 | @Module({
6 | providers: [MessagesGateway, MessagesService],
7 | })
8 | export class MessagesModule {}
9 |
--------------------------------------------------------------------------------
/backend/src/messages/messages.service.ts:
--------------------------------------------------------------------------------
1 | import { Injectable } from '@nestjs/common';
2 | import { CreateMessageDto } from './dto/create-message.dto';
3 | import { Message } from './entities/message.entity';
4 |
5 | @Injectable()
6 | export class MessagesService {
7 | messages: Message[] = [{ name: 'Ashar', message: 'first message' }];
8 | clientToUser = {};
9 |
10 | identify(name: string, clientId: string) {
11 | this.clientToUser[clientId] = name;
12 | return Object.values(this.clientToUser);
13 | }
14 |
15 | getClientByName(id: string) {
16 | return this.clientToUser[id];
17 | }
18 |
19 | create(createMessageDto: CreateMessageDto, clientId: string) {
20 | const message = {
21 | name: this.clientToUser[clientId],
22 | message: createMessageDto.message,
23 | };
24 | // const message = { ...createMessageDto };
25 | this.messages.push(message);
26 | return message;
27 | }
28 |
29 | findAll() {
30 | return this.messages;
31 | }
32 |
33 | remove(id: number) {
34 | return `This action removes a #${id} message`;
35 | }
36 |
37 | joinRoom() {
38 | return this.messages;
39 | }
40 |
41 | async typing() {
42 | return this.messages;
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/backend/test/app.e2e-spec.ts:
--------------------------------------------------------------------------------
1 | import { Test, TestingModule } from '@nestjs/testing';
2 | import { INestApplication } from '@nestjs/common';
3 | import * as request from 'supertest';
4 | import { AppModule } from './../src/app.module';
5 |
6 | describe('AppController (e2e)', () => {
7 | let app: INestApplication;
8 |
9 | beforeEach(async () => {
10 | const moduleFixture: TestingModule = await Test.createTestingModule({
11 | imports: [AppModule],
12 | }).compile();
13 |
14 | app = moduleFixture.createNestApplication();
15 | await app.init();
16 | });
17 |
18 | it('/ (GET)', () => {
19 | return request(app.getHttpServer())
20 | .get('/')
21 | .expect(200)
22 | .expect('Hello World!');
23 | });
24 | });
25 |
--------------------------------------------------------------------------------
/backend/test/jest-e2e.json:
--------------------------------------------------------------------------------
1 | {
2 | "moduleFileExtensions": ["js", "json", "ts"],
3 | "rootDir": ".",
4 | "testEnvironment": "node",
5 | "testRegex": ".e2e-spec.ts$",
6 | "transform": {
7 | "^.+\\.(t|j)s$": "ts-jest"
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/backend/tsconfig.build.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "./tsconfig.json",
3 | "exclude": ["node_modules", "test", "dist", "**/*spec.ts"]
4 | }
5 |
--------------------------------------------------------------------------------
/backend/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "module": "commonjs",
4 | "declaration": true,
5 | "removeComments": true,
6 | "emitDecoratorMetadata": true,
7 | "experimentalDecorators": true,
8 | "allowSyntheticDefaultImports": true,
9 | "target": "es2017",
10 | "sourceMap": true,
11 | "outDir": "./dist",
12 | "baseUrl": "./",
13 | "incremental": true,
14 | "skipLibCheck": true,
15 | "strictNullChecks": false,
16 | "noImplicitAny": false,
17 | "strictBindCallApply": false,
18 | "forceConsistentCasingInFileNames": false,
19 | "noFallthroughCasesInSwitch": false
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/chat-frontend/.gitignore:
--------------------------------------------------------------------------------
1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2 |
3 | # dependencies
4 | /node_modules
5 | /.pnp
6 | .pnp.js
7 |
8 | # testing
9 | /coverage
10 |
11 | # production
12 | /build
13 |
14 | # misc
15 | .DS_Store
16 | .env.local
17 | .env.development.local
18 | .env.test.local
19 | .env.production.local
20 |
21 | npm-debug.log*
22 | yarn-debug.log*
23 | yarn-error.log*
24 |
--------------------------------------------------------------------------------
/chat-frontend/README.md:
--------------------------------------------------------------------------------
1 | # Getting Started with Create React App
2 |
3 | This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
4 |
5 | ## Available Scripts
6 |
7 | In the project directory, you can run:
8 |
9 | ### `npm start`
10 |
11 | Runs the app in the development mode.\
12 | Open [http://localhost:3000](http://localhost:3000) to view it in your browser.
13 |
14 | The page will reload when you make changes.\
15 | You may also see any lint errors in the console.
16 |
17 | ### `npm test`
18 |
19 | Launches the test runner in the interactive watch mode.\
20 | See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
21 |
22 | ### `npm run build`
23 |
24 | Builds the app for production to the `build` folder.\
25 | It correctly bundles React in production mode and optimizes the build for the best performance.
26 |
27 | The build is minified and the filenames include the hashes.\
28 | Your app is ready to be deployed!
29 |
30 | See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
31 |
32 | ### `npm run eject`
33 |
34 | **Note: this is a one-way operation. Once you `eject`, you can't go back!**
35 |
36 | If you aren't satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
37 |
38 | Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you're on your own.
39 |
40 | You don't have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn't feel obligated to use this feature. However we understand that this tool wouldn't be useful if you couldn't customize it when you are ready for it.
41 |
42 | ## Learn More
43 |
44 | You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
45 |
46 | To learn React, check out the [React documentation](https://reactjs.org/).
47 |
48 | ### Code Splitting
49 |
50 | This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting)
51 |
52 | ### Analyzing the Bundle Size
53 |
54 | This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size)
55 |
56 | ### Making a Progressive Web App
57 |
58 | This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app)
59 |
60 | ### Advanced Configuration
61 |
62 | This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration)
63 |
64 | ### Deployment
65 |
66 | This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment)
67 |
68 | ### `npm run build` fails to minify
69 |
70 | This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify)
71 |
--------------------------------------------------------------------------------
/chat-frontend/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "chat-frontend",
3 | "version": "0.1.0",
4 | "private": true,
5 | "dependencies": {
6 | "@testing-library/jest-dom": "^5.16.4",
7 | "@testing-library/react": "^13.3.0",
8 | "@testing-library/user-event": "^13.5.0",
9 | "react": "^18.1.0",
10 | "react-dom": "^18.1.0",
11 | "react-scripts": "5.0.1",
12 | "socket.io-client": "^4.5.1",
13 | "web-vitals": "^2.1.4"
14 | },
15 | "scripts": {
16 | "start": "react-scripts start",
17 | "build": "react-scripts build",
18 | "test": "react-scripts test",
19 | "eject": "react-scripts eject"
20 | },
21 | "eslintConfig": {
22 | "extends": [
23 | "react-app",
24 | "react-app/jest"
25 | ]
26 | },
27 | "browserslist": {
28 | "production": [
29 | ">0.2%",
30 | "not dead",
31 | "not op_mini all"
32 | ],
33 | "development": [
34 | "last 1 chrome version",
35 | "last 1 firefox version",
36 | "last 1 safari version"
37 | ]
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/chat-frontend/public/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/syedashar1/nestjs-auth-socket-migration/1bd6d740d478719156426b86c9bddc899c6b729b/chat-frontend/public/favicon.ico
--------------------------------------------------------------------------------
/chat-frontend/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
12 |
13 |
17 |
18 |
27 | React App
28 |
29 |
30 |
31 |
32 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/chat-frontend/public/logo192.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/syedashar1/nestjs-auth-socket-migration/1bd6d740d478719156426b86c9bddc899c6b729b/chat-frontend/public/logo192.png
--------------------------------------------------------------------------------
/chat-frontend/public/logo512.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/syedashar1/nestjs-auth-socket-migration/1bd6d740d478719156426b86c9bddc899c6b729b/chat-frontend/public/logo512.png
--------------------------------------------------------------------------------
/chat-frontend/public/manifest.json:
--------------------------------------------------------------------------------
1 | {
2 | "short_name": "React App",
3 | "name": "Create React App Sample",
4 | "icons": [
5 | {
6 | "src": "favicon.ico",
7 | "sizes": "64x64 32x32 24x24 16x16",
8 | "type": "image/x-icon"
9 | },
10 | {
11 | "src": "logo192.png",
12 | "type": "image/png",
13 | "sizes": "192x192"
14 | },
15 | {
16 | "src": "logo512.png",
17 | "type": "image/png",
18 | "sizes": "512x512"
19 | }
20 | ],
21 | "start_url": ".",
22 | "display": "standalone",
23 | "theme_color": "#000000",
24 | "background_color": "#ffffff"
25 | }
26 |
--------------------------------------------------------------------------------
/chat-frontend/public/robots.txt:
--------------------------------------------------------------------------------
1 | # https://www.robotstxt.org/robotstxt.html
2 | User-agent: *
3 | Disallow:
4 |
--------------------------------------------------------------------------------
/chat-frontend/src/App.css:
--------------------------------------------------------------------------------
1 | .App {
2 | text-align: center;
3 | background-color: #282c34;
4 | color: azure;
5 | }
6 |
7 | .App-logo {
8 | height: 40vmin;
9 | pointer-events: none;
10 | }
11 |
12 | @media (prefers-reduced-motion: no-preference) {
13 | .App-logo {
14 | animation: App-logo-spin infinite 20s linear;
15 | }
16 | }
17 |
18 | .App-header {
19 | background-color: #282c34;
20 | min-height: 100vh;
21 | display: flex;
22 | flex-direction: column;
23 | align-items: center;
24 | justify-content: center;
25 | font-size: calc(10px + 2vmin);
26 | color: white;
27 | }
28 |
29 | .App-link {
30 | color: #61dafb;
31 | }
32 |
33 | @keyframes App-logo-spin {
34 | from {
35 | transform: rotate(0deg);
36 | }
37 | to {
38 | transform: rotate(360deg);
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/chat-frontend/src/App.js:
--------------------------------------------------------------------------------
1 | import './App.css';
2 | import { io } from 'socket.io-client';
3 | import { useEffect, useState } from 'react'
4 |
5 | function App() {
6 |
7 | const [messages, setMessages] = useState([])
8 | const [messageText, setMessageText] = useState('')
9 | const [joinedRoom, setJoinedRoom] = useState(false)
10 | const [myName, setMyName] = useState('Ashar')
11 | const [typingDisplay, setTypingDisplay] = useState('')
12 | const socket = io('http://localhost:3001')
13 |
14 | useEffect(() => {
15 |
16 | socket.emit('findAllMessages' , {} , (res) => {
17 | console.log('all messages : ',res);
18 | setMessages(res)
19 | })
20 |
21 | socket.on('message' , (message) => {
22 | // console.log('new message' , message);
23 | // setMessages([...messages , message])
24 |
25 | socket.emit('findAllMessages' , {} , res => setMessages(res) )
26 |
27 | } )
28 |
29 | socket.on('typing' , ({name , isTyping }) => {
30 | if(isTyping) setTypingDisplay(`${name} is typing...`)
31 | else setTypingDisplay('')
32 | } )
33 |
34 | }, [])
35 |
36 |
37 |
38 | const sendMessageHandler = () => {
39 | if(messageText==='') return;
40 |
41 | socket.emit('createMessage' , {message : messageText , name : myName } , (res) => {
42 | setMessageText('')
43 | })
44 |
45 | }
46 |
47 | const join = () => {
48 | socket.emit('join' , {name : myName} , (res) => {
49 | console.log(res);
50 | setJoinedRoom(true)
51 | } )
52 | }
53 |
54 | let timeOut ;
55 | const handleTyping = () => {
56 | console.log('typing');
57 | socket.emit('typing' , {isTyping : true});
58 | timeOut = setTimeout( ()=> {
59 | socket.emit('typing' , {isTyping : false})
60 | } , 2000 )
61 | }
62 |
63 | return (
64 |
65 | {joinedRoom ? <>
66 | {messages.map(m=>
67 | {m.name} : {m.message}
68 |
)}
69 |
70 | {typingDisplay &&
{typingDisplay}
}
71 |
{
72 | setMessageText(e.target.value);
73 | handleTyping();
74 | }}/>
75 |
76 | >
77 | :
78 |
79 |
You need to join first
80 | setMyName(e.target.value)}/>
81 |
82 | }
83 |
84 | );
85 | }
86 |
87 | export default App;
88 |
--------------------------------------------------------------------------------
/chat-frontend/src/index.css:
--------------------------------------------------------------------------------
1 | body {
2 | margin: 0;
3 | font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
4 | 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
5 | sans-serif;
6 | -webkit-font-smoothing: antialiased;
7 | -moz-osx-font-smoothing: grayscale;
8 | text-align: center;
9 | background-color: #282c34;
10 | color: azure;
11 | }
12 |
13 | code {
14 | font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
15 | monospace;
16 | }
17 |
--------------------------------------------------------------------------------
/chat-frontend/src/index.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import ReactDOM from 'react-dom/client';
3 | import './index.css';
4 | import App from './App';
5 | import reportWebVitals from './reportWebVitals';
6 |
7 | const root = ReactDOM.createRoot(document.getElementById('root'));
8 | root.render(
9 |
10 |
11 |
12 | );
13 |
14 | // If you want to start measuring performance in your app, pass a function
15 | // to log results (for example: reportWebVitals(console.log))
16 | // or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
17 | reportWebVitals();
18 |
--------------------------------------------------------------------------------
/chat-frontend/src/reportWebVitals.js:
--------------------------------------------------------------------------------
1 | const reportWebVitals = onPerfEntry => {
2 | if (onPerfEntry && onPerfEntry instanceof Function) {
3 | import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => {
4 | getCLS(onPerfEntry);
5 | getFID(onPerfEntry);
6 | getFCP(onPerfEntry);
7 | getLCP(onPerfEntry);
8 | getTTFB(onPerfEntry);
9 | });
10 | }
11 | };
12 |
13 | export default reportWebVitals;
14 |
--------------------------------------------------------------------------------
/chat-frontend/src/setupTests.js:
--------------------------------------------------------------------------------
1 | // jest-dom adds custom jest matchers for asserting on DOM nodes.
2 | // allows you to do things like:
3 | // expect(element).toHaveTextContent(/react/i)
4 | // learn more: https://github.com/testing-library/jest-dom
5 | import '@testing-library/jest-dom';
6 |
--------------------------------------------------------------------------------