diff --git a/frontEnd/.eslintrc.cjs b/frontEnd/.eslintrc.cjs index a960342..0ab05ff 100644 --- a/frontEnd/.eslintrc.cjs +++ b/frontEnd/.eslintrc.cjs @@ -24,5 +24,7 @@ module.exports = { plugins: ['react', '@typescript-eslint', 'prettier'], rules: { 'react/react-in-jsx-scope': 'off', + 'import/extensions': ['off'], + 'react-hooks/exhaustive-deps': 'off', }, }; diff --git a/frontEnd/package-lock.json b/frontEnd/package-lock.json index 9e79b77..0079841 100644 --- a/frontEnd/package-lock.json +++ b/frontEnd/package-lock.json @@ -10,7 +10,8 @@ "dependencies": { "react": "^18.2.0", "react-dom": "^18.2.0", - "react-router-dom": "^6.18.0" + "react-router-dom": "^6.18.0", + "socket.io-client": "^4.7.2" }, "devDependencies": { "@testing-library/jest-dom": "^6.1.4", @@ -19,6 +20,7 @@ "@types/node": "^20.8.10", "@types/react": "^18.2.37", "@types/react-dom": "^18.2.7", + "@types/socket.io-client": "^3.0.0", "@typescript-eslint/eslint-plugin": "^6.10.0", "@typescript-eslint/parser": "^6.10.0", "@vitejs/plugin-react": "^4.0.3", @@ -1999,6 +2001,11 @@ "@sinonjs/commons": "^3.0.0" } }, + "node_modules/@socket.io/component-emitter": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/@socket.io/component-emitter/-/component-emitter-3.1.0.tgz", + "integrity": "sha512-+9jVqKhRSpsc591z5vX+X5Yyw+he/HCB4iQ/RYxw35CEPaY1gnsNE43nf9n9AaYjAQrTiI/mOwKUKdUs9vf7Xg==" + }, "node_modules/@testing-library/dom": { "version": "9.3.3", "resolved": "https://registry.npmjs.org/@testing-library/dom/-/dom-9.3.3.tgz", @@ -2439,6 +2446,16 @@ "integrity": "sha512-MMzuxN3GdFwskAnb6fz0orFvhfqi752yjaXylr0Rp4oDg5H0Zn1IuyRhDVvYOwAXoJirx2xuS16I3WjxnAIHiQ==", "dev": true }, + "node_modules/@types/socket.io-client": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/@types/socket.io-client/-/socket.io-client-3.0.0.tgz", + "integrity": "sha512-s+IPvFoEIjKA3RdJz/Z2dGR4gLgysKi8owcnrVwNjgvc01Lk68LJDDsG2GRqegFITcxmvCMYM7bhMpwEMlHmDg==", + "deprecated": "This is a stub types definition. socket.io-client provides its own type definitions, so you do not need this installed.", + "dev": true, + "dependencies": { + "socket.io-client": "*" + } + }, "node_modules/@types/stack-utils": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/@types/stack-utils/-/stack-utils-2.0.2.tgz", @@ -3846,7 +3863,6 @@ "version": "4.3.4", "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", "integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==", - "dev": true, "dependencies": { "ms": "2.1.2" }, @@ -4230,6 +4246,46 @@ "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==", "dev": true }, + "node_modules/engine.io-client": { + "version": "6.5.2", + "resolved": "https://registry.npmjs.org/engine.io-client/-/engine.io-client-6.5.2.tgz", + "integrity": "sha512-CQZqbrpEYnrpGqC07a9dJDz4gePZUgTPMU3NKJPSeQOyw27Tst4Pl3FemKoFGAlHzgZmKjoRmiJvbWfhCXUlIg==", + "dependencies": { + "@socket.io/component-emitter": "~3.1.0", + "debug": "~4.3.1", + "engine.io-parser": "~5.2.1", + "ws": "~8.11.0", + "xmlhttprequest-ssl": "~2.0.0" + } + }, + "node_modules/engine.io-client/node_modules/ws": { + "version": "8.11.0", + "resolved": "https://registry.npmjs.org/ws/-/ws-8.11.0.tgz", + "integrity": "sha512-HPG3wQd9sNQoT9xHyNCXoDUa+Xw/VevmY9FoHyQ+g+rrMn4j6FB4np7Z0OhdTgjx6MgQLK7jwSy1YecU1+4Asg==", + "engines": { + "node": ">=10.0.0" + }, + "peerDependencies": { + "bufferutil": "^4.0.1", + "utf-8-validate": "^5.0.2" + }, + "peerDependenciesMeta": { + "bufferutil": { + "optional": true + }, + "utf-8-validate": { + "optional": true + } + } + }, + "node_modules/engine.io-parser": { + "version": "5.2.1", + "resolved": "https://registry.npmjs.org/engine.io-parser/-/engine.io-parser-5.2.1.tgz", + "integrity": "sha512-9JktcM3u18nU9N2Lz3bWeBgxVgOKpw7yhRaoxQA3FUDZzzw+9WlA6p4G4u0RixNkg14fH7EfEc/RhpurtiROTQ==", + "engines": { + "node": ">=10.0.0" + } + }, "node_modules/enquirer": { "version": "2.4.1", "resolved": "https://registry.npmjs.org/enquirer/-/enquirer-2.4.1.tgz", @@ -8925,8 +8981,7 @@ "node_modules/ms": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", - "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", - "dev": true + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" }, "node_modules/mz": { "version": "2.7.0", @@ -10235,6 +10290,32 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/socket.io-client": { + "version": "4.7.2", + "resolved": "https://registry.npmjs.org/socket.io-client/-/socket.io-client-4.7.2.tgz", + "integrity": "sha512-vtA0uD4ibrYD793SOIAwlo8cj6haOeMHrGvwPxJsxH7CeIksqJ+3Zc06RvWTIFgiSqx4A3sOnTXpfAEE2Zyz6w==", + "dependencies": { + "@socket.io/component-emitter": "~3.1.0", + "debug": "~4.3.2", + "engine.io-client": "~6.5.2", + "socket.io-parser": "~4.2.4" + }, + "engines": { + "node": ">=10.0.0" + } + }, + "node_modules/socket.io-parser": { + "version": "4.2.4", + "resolved": "https://registry.npmjs.org/socket.io-parser/-/socket.io-parser-4.2.4.tgz", + "integrity": "sha512-/GbIKmo8ioc+NIWIhwdecY0ge+qVBSMdgxGygevmdHj24bsfgtCmcUUcQ5ZzcylGFHsN3k4HB4Cgkl96KVnuew==", + "dependencies": { + "@socket.io/component-emitter": "~3.1.0", + "debug": "~4.3.1" + }, + "engines": { + "node": ">=10.0.0" + } + }, "node_modules/source-map": { "version": "0.6.1", "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", @@ -11358,6 +11439,14 @@ "integrity": "sha512-JZnDKK8B0RCDw84FNdDAIpZK+JuJw+s7Lz8nksI7SIuU3UXJJslUthsi+uWBUYOwPFwW7W7PRLRfUKpxjtjFCw==", "dev": true }, + "node_modules/xmlhttprequest-ssl": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/xmlhttprequest-ssl/-/xmlhttprequest-ssl-2.0.0.tgz", + "integrity": "sha512-QKxVRxiRACQcVuQEYFsI1hhkrMlrXHPegbbd1yn9UHOmRxY+si12nQYzri3vbzt8VdTTRviqcKxcyllFas5z2A==", + "engines": { + "node": ">=0.4.0" + } + }, "node_modules/y18n": { "version": "5.0.8", "resolved": "https://registry.npmjs.org/y18n/-/y18n-5.0.8.tgz", diff --git a/frontEnd/package.json b/frontEnd/package.json index d45c669..e076deb 100644 --- a/frontEnd/package.json +++ b/frontEnd/package.json @@ -13,7 +13,8 @@ "dependencies": { "react": "^18.2.0", "react-dom": "^18.2.0", - "react-router-dom": "^6.18.0" + "react-router-dom": "^6.18.0", + "socket.io-client": "^4.7.2" }, "devDependencies": { "@testing-library/jest-dom": "^6.1.4", @@ -22,6 +23,7 @@ "@types/node": "^20.8.10", "@types/react": "^18.2.37", "@types/react-dom": "^18.2.7", + "@types/socket.io-client": "^3.0.0", "@typescript-eslint/eslint-plugin": "^6.10.0", "@typescript-eslint/parser": "^6.10.0", "@vitejs/plugin-react": "^4.0.3", diff --git a/frontEnd/src/constants/socketEvents.ts b/frontEnd/src/constants/socketEvents.ts new file mode 100644 index 0000000..3d272d5 --- /dev/null +++ b/frontEnd/src/constants/socketEvents.ts @@ -0,0 +1,13 @@ +export const SOCKET_RECEIVE_EVENT = { + ALL_USERS: 'all_users', + OFFER: 'getOffer', + ANSWER: 'getAnswer', + CANDIDATE: 'getCandidate', + USER_EXIT: 'user_exit', +}; + +export const SOCKET_EMIT_EVENT = { + OFFER: 'offer', + ANSWER: 'answer', + JOIN_ROOM: 'join_room', +}; diff --git a/frontEnd/src/constants/urls.ts b/frontEnd/src/constants/urls.ts new file mode 100644 index 0000000..4a4ae89 --- /dev/null +++ b/frontEnd/src/constants/urls.ts @@ -0,0 +1,2 @@ +export const SOCKET_URL = `ws://localhost:4000`; +export const API_URL = `http://localhost:4000`; diff --git a/frontEnd/src/main.tsx b/frontEnd/src/main.tsx index d61fc6e..2bee3b6 100644 --- a/frontEnd/src/main.tsx +++ b/frontEnd/src/main.tsx @@ -1,4 +1,3 @@ -import React from 'react'; import ReactDOM from 'react-dom/client'; import { createBrowserRouter, RouterProvider } from 'react-router-dom'; import Home from '@pages/Home.tsx'; @@ -15,8 +14,4 @@ const router = createBrowserRouter([ element: , }, ]); -ReactDOM.createRoot(document.getElementById('root')!).render( - - - , -); +ReactDOM.createRoot(document.getElementById('root')!).render(); diff --git a/frontEnd/src/pages/Room.tsx b/frontEnd/src/pages/Room.tsx index eaee17c..4aed3e4 100644 --- a/frontEnd/src/pages/Room.tsx +++ b/frontEnd/src/pages/Room.tsx @@ -1,3 +1,48 @@ +import { useEffect, useRef, useState } from 'react'; +import { useParams } from 'react-router-dom'; +import { createSocket } from '@/services/Socket'; +import { StreamObject, streamModel } from '@/stores/StreamModel'; +import { SOCKET_EMIT_EVENT } from '@/constants/socketEvents'; + +function StreamVideo({ stream }: { stream: MediaStream }) { + const videoRef = useRef(null); + useEffect(() => { + if (!videoRef.current) return; + videoRef.current.srcObject = stream; + }, []); + + return