├── frontend ├── src │ ├── css │ │ ├── App.css │ │ ├── Video.css │ │ ├── VideoBar.css │ │ ├── ConfigBar.css │ │ ├── Footer.css │ │ ├── Editor.css │ │ └── Header.css │ ├── config │ │ └── mappings.js │ ├── index.js │ └── components │ │ ├── VideoBar.jsx │ │ ├── Footer.jsx │ │ ├── Video.jsx │ │ ├── ConfigBar.jsx │ │ ├── Header.jsx │ │ ├── Editor.jsx │ │ └── App.jsx ├── .gitignore ├── package.json ├── public │ └── index.html └── README.md ├── backend ├── Procfile ├── .gitignore ├── package.json ├── server.js └── package-lock.json ├── readme_resource ├── github1.png ├── github2.png └── githubLL.png ├── LICENSE └── README.md /frontend/src/css/App.css: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /backend/Procfile: -------------------------------------------------------------------------------- 1 | web: npm start -------------------------------------------------------------------------------- /readme_resource/github1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shreyshreyansh/Peer-Coder/HEAD/readme_resource/github1.png -------------------------------------------------------------------------------- /readme_resource/github2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shreyshreyansh/Peer-Coder/HEAD/readme_resource/github2.png -------------------------------------------------------------------------------- /readme_resource/githubLL.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shreyshreyansh/Peer-Coder/HEAD/readme_resource/githubLL.png -------------------------------------------------------------------------------- /frontend/src/config/mappings.js: -------------------------------------------------------------------------------- 1 | const languageToEditorMode = { 2 | c: "c_cpp", 3 | cpp: "c_cpp", 4 | python: "python", 5 | python3: "python", 6 | java: "java", 7 | }; 8 | 9 | export { languageToEditorMode }; 10 | -------------------------------------------------------------------------------- /frontend/src/css/Video.css: -------------------------------------------------------------------------------- 1 | video { 2 | margin: 5px 0px 0px 5px; 3 | object-fit: cover; 4 | border: 2px solid rgb(251, 216, 127); 5 | border-radius: 7px; 6 | /* border-image: linear-gradient(45deg, rgb(124, 66, 218), rgb(233, 30, 99)) 1; */ 7 | } 8 | -------------------------------------------------------------------------------- /frontend/src/css/VideoBar.css: -------------------------------------------------------------------------------- 1 | div.scrollmenu { 2 | height: 127px; 3 | background-color: rgb(3, 37, 78); 4 | overflow: auto; 5 | white-space: nowrap; 6 | padding: 3px; 7 | } 8 | div.scrollmenu video { 9 | display: inline-block; 10 | } 11 | -------------------------------------------------------------------------------- /backend/.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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /backend/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "backend", 3 | "version": "1.0.0", 4 | "description": "Server", 5 | "main": "server.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1", 8 | "start": "node server.js" 9 | }, 10 | "author": "Shreyansh Shrey", 11 | "license": "ISC", 12 | "dependencies": { 13 | "cors": "^2.8.5", 14 | "express": "^4.17.1", 15 | "socket.io": "^4.1.2", 16 | "uuid": "^8.3.2" 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /frontend/src/index.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import ReactDOM from "react-dom"; 3 | import App from "./components/App"; 4 | import { 5 | HashRouter as Router, 6 | Route, 7 | useParams, 8 | Redirect, 9 | } from "react-router-dom"; 10 | const { v4: uuidV4 } = require("uuid"); 11 | ReactDOM.render( 12 | 13 | 14 | 15 | 16 | } /> 17 | , 18 | document.getElementById("root") 19 | ); 20 | 21 | function Room() { 22 | let { roomId } = useParams(); 23 | return ; 24 | } 25 | -------------------------------------------------------------------------------- /frontend/src/components/VideoBar.jsx: -------------------------------------------------------------------------------- 1 | import React, { Component } from "react"; 2 | import Video from "./Video"; 3 | import "../css/VideoBar.css"; 4 | 5 | class VideoBar extends Component { 6 | render() { 7 | return ( 8 |
9 | {this.props.peersStream.map((peer) => { 10 | return ( 11 | 18 | ); 19 | })} 20 |
21 | ); 22 | } 23 | } 24 | export default VideoBar; 25 | -------------------------------------------------------------------------------- /frontend/src/components/Footer.jsx: -------------------------------------------------------------------------------- 1 | import React, { Component } from "react"; 2 | import "../css/Footer.css"; 3 | 4 | class Footer extends Component { 5 | render() { 6 | return ( 7 |
8 | 14 | ⭐ Star Project 15 | 16 | 22 | © GitHub community 23 | 24 |
25 | ); 26 | } 27 | } 28 | export default Footer; 29 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Shreyansh shrey 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /frontend/src/css/ConfigBar.css: -------------------------------------------------------------------------------- 1 | .ui { 2 | font-family: "Roboto", sans-serif; 3 | } 4 | .ui.selection.dropdown { 5 | color: rgb(251, 216, 127); 6 | background-color: rgb(3, 37, 78); 7 | } 8 | .ui.dropdown .menu > .item { 9 | background: rgb(3, 37, 78); 10 | color: rgb(251, 216, 127); 11 | border: none; 12 | z-index: 13; 13 | position: relative; 14 | } 15 | .ui.dropdown .menu > .item:hover { 16 | color: rgb(3, 37, 78); 17 | z-index: 13; 18 | background: rgb(251, 216, 127); 19 | } 20 | .ui.dropdown.selected, 21 | .ui.dropdown .menu .selected.item { 22 | color: rgb(251, 216, 127); 23 | z-index: 13; 24 | background: rgb(3, 21, 68); 25 | } 26 | .dropdown { 27 | margin: 10px; 28 | } 29 | 30 | .config-bar { 31 | background-color: rgb(1, 28, 39); 32 | padding: 0 5px 0 5px; 33 | } 34 | 35 | .run { 36 | float: right; 37 | margin-right: 10px; 38 | margin-top: 12px; 39 | width: 120px; 40 | font-family: "Roboto", sans-serif; 41 | font-size: 1.2rem; 42 | font-weight: 700px; 43 | } 44 | .run:hover { 45 | float: right; 46 | margin-right: 10px; 47 | width: 120px; 48 | font-family: "Roboto", sans-serif; 49 | font-size: 1rem; 50 | background-color: rgb(3, 37, 78); 51 | color: rgb(251, 216, 127); 52 | } 53 | -------------------------------------------------------------------------------- /frontend/src/css/Footer.css: -------------------------------------------------------------------------------- 1 | .footer { 2 | position: fixed; 3 | left: 0; 4 | bottom: 0; 5 | width: 100%; 6 | height: 5%; 7 | background-color: rgb(1, 28, 39); 8 | color: white; 9 | z-index: 5; 10 | font-family: "Roboto", sans-serif; 11 | font-weight: 900; 12 | } 13 | .right-footer { 14 | float: right; 15 | margin-right: 150px; 16 | margin-top: 6.5px; 17 | background-color: rgb(251, 216, 127); 18 | color: rgb(1, 28, 39); 19 | padding: 2px 7px; 20 | border-radius: 15px; 21 | } 22 | .left-footer { 23 | display: inline-block; 24 | margin-left: 150px; 25 | margin-top: 6.5px; 26 | background-color: rgb(251, 216, 127); 27 | color: rgb(1, 28, 39); 28 | padding: 2px 7px; 29 | border-radius: 15px; 30 | text-decoration: none; 31 | } 32 | 33 | .left-footer:hover { 34 | display: inline-block; 35 | margin-left: 150px; 36 | margin-top: 6.5px; 37 | background-color: rgb(3, 37, 78); 38 | color: rgb(251, 216, 127); 39 | padding: 2px 7px; 40 | border-radius: 15px; 41 | text-decoration: none; 42 | } 43 | 44 | .right-footer:hover { 45 | display: inline-block; 46 | margin-left: 150px; 47 | margin-top: 6.5px; 48 | background-color: rgb(3, 37, 78); 49 | color: rgb(251, 216, 127); 50 | padding: 2px 7px; 51 | border-radius: 15px; 52 | text-decoration: none; 53 | } 54 | -------------------------------------------------------------------------------- /frontend/src/components/Video.jsx: -------------------------------------------------------------------------------- 1 | import PropTypes from "prop-types"; 2 | import React from "react"; 3 | import "../css/Video.css"; 4 | 5 | class Video extends React.Component { 6 | componentDidMount() { 7 | this.video.srcObject = this.props.media; 8 | } 9 | 10 | shouldComponentUpdate(props) { 11 | return this.props.media !== props.media; 12 | } 13 | 14 | componentDidUpdate() { 15 | this.video.srcObject = this.props.media; 16 | } 17 | 18 | render() { 19 | const { width, height, muted, children } = this.props; 20 | 21 | return ( 22 | 33 | ); 34 | } 35 | } 36 | 37 | Video.defaultProps = { 38 | children: null, 39 | height: 110, 40 | width: 160, 41 | muted: false, 42 | media: null, 43 | }; 44 | 45 | Video.propTypes = { 46 | children: PropTypes.element, 47 | media: PropTypes.shape({ 48 | active: PropTypes.bool, 49 | ended: PropTypes.bool, 50 | id: PropTypes.string, 51 | }), 52 | height: PropTypes.number, 53 | width: PropTypes.number, 54 | muted: PropTypes.bool, 55 | }; 56 | 57 | export default Video; 58 | -------------------------------------------------------------------------------- /frontend/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "frontend", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@testing-library/jest-dom": "^5.14.1", 7 | "@testing-library/react": "^11.2.7", 8 | "@testing-library/user-event": "^12.8.3", 9 | "ace-builds": "^1.4.12", 10 | "axios": "^0.21.1", 11 | "gh-pages": "^3.2.3", 12 | "peer": "^0.6.1", 13 | "peerjs": "^1.3.2", 14 | "react": "^17.0.2", 15 | "react-ace": "^9.4.1", 16 | "react-dom": "^17.0.2", 17 | "react-player": "^2.9.0", 18 | "react-router-dom": "^5.2.0", 19 | "react-scripts": "4.0.3", 20 | "react-split-pane": "^0.1.92", 21 | "semantic-ui-react": "^2.0.3", 22 | "socket.io-client": "^4.1.2", 23 | "uuid": "^8.3.2", 24 | "web-vitals": "^1.1.2" 25 | }, 26 | "scripts": { 27 | "start": "react-scripts start", 28 | "build": "react-scripts build", 29 | "test": "react-scripts test", 30 | "eject": "react-scripts eject" 31 | }, 32 | "eslintConfig": { 33 | "extends": [ 34 | "react-app", 35 | "react-app/jest" 36 | ] 37 | }, 38 | "browserslist": { 39 | "production": [ 40 | ">0.2%", 41 | "not dead", 42 | "not op_mini all" 43 | ], 44 | "development": [ 45 | "last 1 chrome version", 46 | "last 1 firefox version", 47 | "last 1 safari version" 48 | ] 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /frontend/src/components/ConfigBar.jsx: -------------------------------------------------------------------------------- 1 | import React, { Component } from "react"; 2 | import { Dropdown } from "semantic-ui-react"; 3 | import "../css/ConfigBar.css"; 4 | 5 | class ConfigBar extends Component { 6 | render() { 7 | return ( 8 |
9 | this.props.handleOnChange(e, data)} 15 | defaultValue={this.props.themes[8].value} 16 | /> 17 | this.props.handleOnChange(e, data)} 23 | value={this.props.mode} 24 | /> 25 | this.props.handleOnChange(e, data)} 31 | defaultValue={this.props.fontSizes[4].value} 32 | /> 33 | 36 |
37 | ); 38 | } 39 | } 40 | 41 | export default ConfigBar; 42 | -------------------------------------------------------------------------------- /frontend/src/css/Editor.css: -------------------------------------------------------------------------------- 1 | .Resizer { 2 | background: #000; 3 | opacity: 0.2; 4 | z-index: 1; 5 | -moz-box-sizing: border-box; 6 | -webkit-box-sizing: border-box; 7 | box-sizing: border-box; 8 | -moz-background-clip: padding; 9 | -webkit-background-clip: padding; 10 | background-clip: padding-box; 11 | } 12 | 13 | .Resizer:hover { 14 | -webkit-transition: all 2s ease; 15 | transition: all 2s ease; 16 | } 17 | 18 | .Resizer.horizontal { 19 | height: 11px; 20 | margin: -5px 0; 21 | border-top: 5px solid rgba(255, 255, 255, 0); 22 | border-bottom: 5px solid rgba(255, 255, 255, 0); 23 | cursor: row-resize; 24 | width: 100%; 25 | } 26 | 27 | .Resizer.horizontal:hover { 28 | border-top: 5px solid rgba(0, 0, 0, 0.5); 29 | border-bottom: 5px solid rgba(0, 0, 0, 0.5); 30 | } 31 | 32 | .Resizer.vertical { 33 | width: 11px; 34 | margin: 0 -5px; 35 | border-left: 5px solid rgba(255, 255, 255, 0); 36 | border-right: 5px solid rgba(255, 255, 255, 0); 37 | cursor: col-resize; 38 | } 39 | 40 | .Resizer.vertical:hover { 41 | border-left: 5px solid rgba(0, 0, 0, 0.5); 42 | border-right: 5px solid rgba(0, 0, 0, 0.5); 43 | } 44 | .Resizer.disabled { 45 | cursor: not-allowed; 46 | } 47 | .Resizer.disabled:hover { 48 | border-color: transparent; 49 | } 50 | .head { 51 | background-color: rgb(251, 216, 127); 52 | color: rgb(1, 28, 39); 53 | } 54 | .text { 55 | font-family: "Roboto", sans-serif; 56 | font-weight: 1000; 57 | margin-left: 15px; 58 | } 59 | -------------------------------------------------------------------------------- /backend/server.js: -------------------------------------------------------------------------------- 1 | // https://peaceful-depths-33963.herokuapp.com/ 2 | const app = require("express")(); 3 | const http = require("http").Server(app); 4 | const PORT = process.env.PORT || 4000; 5 | const io = require("socket.io")(http, { 6 | cors: { 7 | origin: "*", 8 | methods: ["GET", "POST"], 9 | }, 10 | }); 11 | const cors = require("cors"); 12 | app.use( 13 | cors({ 14 | origin: "*", 15 | }) 16 | ); 17 | 18 | app.get("/", (req, res) => { 19 | res.send({ status: "running" }); 20 | }); 21 | 22 | io.on("connection", (socket) => { 23 | socket.on("join-room", (roomId, userId) => { 24 | socket.join(roomId); 25 | socket.broadcast.to(roomId).emit("user-connected", userId); 26 | socket.on("disconnect", () => { 27 | socket.broadcast.to(roomId).emit("user-disconnected", userId); 28 | }); 29 | socket.on("code change", function (data) { 30 | socket.broadcast.to(roomId).emit("receive code", data); 31 | }); 32 | socket.on("input change", function (data) { 33 | socket.broadcast.to(roomId).emit("receive input", data); 34 | }); 35 | socket.on("output change", function (data) { 36 | socket.broadcast.to(roomId).emit("receive output", data); 37 | }); 38 | socket.on("data-for-new-user", function (data) { 39 | socket.broadcast.to(roomId).emit("receive-data-for-new-user", data); 40 | }); 41 | socket.on("mode-change-send", function (data) { 42 | socket.broadcast.to(roomId).emit("mode-change-receive", data); 43 | }); 44 | }); 45 | }); 46 | 47 | http.listen(PORT, () => { 48 | console.log(`Server is running at port ${PORT}`); 49 | }); 50 | -------------------------------------------------------------------------------- /frontend/src/css/Header.css: -------------------------------------------------------------------------------- 1 | /* Style the header with a grey background and some padding */ 2 | .header { 3 | overflow: hidden; 4 | background-color: rgb(1, 28, 39); 5 | text-decoration: none; 6 | padding: 9px; 7 | } 8 | 9 | .logo { 10 | text-decoration: none; 11 | color: rgb(251, 216, 127); 12 | font-family: "Roboto", sans-serif; 13 | font-size: 2rem; 14 | font-weight: 500; 15 | display: inline-block; 16 | margin-top: 7px; 17 | } 18 | 19 | .copy-url { 20 | float: right; 21 | margin-right: 10px; 22 | width: 120px; 23 | font-family: "Roboto", sans-serif; 24 | font-size: 1.2rem; 25 | font-weight: 700px; 26 | } 27 | .copy-url:hover { 28 | float: right; 29 | margin-right: 10px; 30 | width: 120px; 31 | font-family: "Roboto", sans-serif; 32 | font-size: 1rem; 33 | background-color: rgb(3, 37, 78); 34 | color: rgb(251, 216, 127); 35 | } 36 | 37 | button { 38 | justify-content: center; 39 | align-items: center; 40 | background-color: rgb(251, 216, 127); 41 | height: 35px; 42 | border-radius: 5px; 43 | color: rgb(3, 37, 78); 44 | font-size: 0.8rem; 45 | width: 35px; 46 | margin: 0 0.3rem; 47 | border: none; 48 | } 49 | 50 | .buttonOff { 51 | background-color: rgb(3, 37, 78); 52 | color: rgb(251, 216, 127); 53 | } 54 | 55 | /* Float the link section to the right */ 56 | .header-right { 57 | float: right; 58 | } 59 | 60 | /* Add media queries for responsiveness - when the screen is 500px wide or less, stack the links on top of each other */ 61 | @media screen and (max-width: 200px) { 62 | .header button { 63 | float: none; 64 | display: block; 65 | text-align: left; 66 | } 67 | .header-right { 68 | float: none; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /frontend/src/components/Header.jsx: -------------------------------------------------------------------------------- 1 | import React, { Component } from "react"; 2 | import "../css/Header.css"; 3 | 4 | class Header extends Component { 5 | constructor(props) { 6 | super(props); 7 | this.state = { 8 | video: false, 9 | audio: false, 10 | }; 11 | } 12 | toggleAudioCss() { 13 | let audio = this.state.audio; 14 | this.setState({ audio: !audio }); 15 | } 16 | toggleVideoCss() { 17 | let video = this.state.video; 18 | this.setState({ video: !video }); 19 | } 20 | handleClick() { 21 | window.prompt("ROOM URL", window.location.href); 22 | } 23 | render() { 24 | return ( 25 |
26 |
27 | PEER CODER 28 |
29 | 32 |
33 | 46 | 59 |
60 |
61 | ); 62 | } 63 | } 64 | 65 | export default Header; 66 | -------------------------------------------------------------------------------- /frontend/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 11 | 16 | 17 | 18 | 19 | 23 | 27 | Peer Coder 28 | 29 | 53 | 54 | 55 |
56 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # [PEER CODER](https://shreyshreyansh.github.io/Peer-Coder-Web/) ⭐ 2 | 3 | [![React Badge](http://img.shields.io/badge/Powered%20By-React-blue?style=for-the-badge&logo=react)](https://reactjs.org/) 4 | [![Website Badge](https://img.shields.io/badge/Visit-Now-green?style=for-the-badge&logo=vercel)](https://shreyshreyansh.github.io/Peer-Coder-Web/) 5 | [![OPEN-PR](https://img.shields.io/badge/Open%20For-PR-orange?style=for-the-badge&logo=github)](https://github.com/shreyshreyansh/Peer-Coder) 6 | 7 | 8 | ## Overview 👀 9 | 10 | ![](readme_resource/githubLL.png) 11 | - **Real time code syncing among peers 👨‍💻** 12 | - **Executes code in Java, Python, C++, C 💻** 13 | - **Real time video and audio call 📹** 14 | - **Clean UI ⚡** 15 | 16 | ## What is Peer Coder? 🤔 17 | 18 | #### Remote pair programming is something developers have grappled with since well before the pandemic began. 19 | #### Peer Coder is ideal for Online Interviewing of Developers as well as Learning to code from Friends. 20 | #### An online code editor for interviews, troubleshooting, teaching & more… 21 | 22 | ## How it works? 🤔 23 | - **open the website [https://shreyshreyansh.github.io/Peer-Coder-Web/](https://shreyshreyansh.github.io/Peer-Coder-Web/)** 24 | - **Click Room url button and copy the url given in the prompt** 25 | - **Share that url with your peers and enjoy coding** 26 | 27 | ## Dependencies 🗃 28 | 29 | - [React.js](https://reactjs.org/) - **Frontend Framework** 30 | - [Node.js](https://nodejs.org/en/) - **Backend Framework** 31 | - [Socket.io](https://socket.io/) - **Client-Server Communication** 32 | - [Peer.js](https://peerjs.com/) - **Client-Client Communication** 33 | - [Ace editor](https://www.npmjs.com/package/react-ace) - **Code Editor** 34 | 35 | ## Run Locally 💻 36 | 37 | ``` 38 | > Clone the repo 39 | >> For Windows: Git Bash 40 | >> For Linux: Terminal 41 | >> git clone https://github.com/shreyshreyansh/Peer-Coder.git 42 | >> cd Peer-Coder 43 | > Install all dependencies 44 | >> npm i 45 | > Spin the server on port 4000 46 | >> cd backend 47 | >> npm start 48 | > Spin the react on port 3000 49 | >> cd frontend 50 | >> npm start 51 | > Visit the website on http://localhost:3000/ 52 | 53 | ``` 54 | -------------------------------------------------------------------------------- /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 the browser. 13 | 14 | The page will reload if you make edits.\ 15 | You will 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 | -------------------------------------------------------------------------------- /frontend/src/components/Editor.jsx: -------------------------------------------------------------------------------- 1 | import React, { Component } from "react"; 2 | import ConfigBar from "./ConfigBar"; 3 | import AceEditor from "react-ace"; 4 | import SplitPane from "react-split-pane"; 5 | import { languageToEditorMode } from "../config/mappings"; 6 | import "ace-builds/webpack-resolver"; 7 | 8 | import "ace-builds/src-noconflict/ext-language_tools"; 9 | 10 | import "ace-builds/src-noconflict/mode-java"; 11 | import "ace-builds/src-noconflict/mode-c_cpp"; 12 | import "ace-builds/src-noconflict/mode-python"; 13 | import "ace-builds/src-noconflict/mode-javascript"; 14 | import "ace-builds/src-noconflict/mode-rust"; 15 | import "ace-builds/src-noconflict/mode-kotlin"; 16 | 17 | import "ace-builds/src-noconflict/theme-github"; 18 | import "ace-builds/src-noconflict/theme-solarized_dark"; 19 | import "ace-builds/src-noconflict/theme-dracula"; 20 | import "ace-builds/src-noconflict/theme-monokai"; 21 | import "ace-builds/src-noconflict/theme-eclipse"; 22 | import "ace-builds/src-noconflict/theme-tomorrow_night"; 23 | import "ace-builds/src-noconflict/theme-tomorrow_night_blue"; 24 | import "ace-builds/src-noconflict/theme-xcode"; 25 | import "ace-builds/src-noconflict/theme-ambiance"; 26 | import "ace-builds/src-noconflict/theme-solarized_light"; 27 | 28 | import "../css/Editor.css"; 29 | 30 | const languages = Object.keys(languageToEditorMode); 31 | const fontSizes = [ 32 | "8", 33 | "10", 34 | "12", 35 | "14", 36 | "16", 37 | "18", 38 | "20", 39 | "22", 40 | "24", 41 | "26", 42 | "28", 43 | "30", 44 | "32", 45 | ]; 46 | const themes = [ 47 | "monokai", 48 | "github", 49 | "solarized_dark", 50 | "dracula", 51 | "eclipse", 52 | "tomorrow_night", 53 | "tomorrow_night_blue", 54 | "xcode", 55 | "ambiance", 56 | "solarized_light", 57 | ].sort(); 58 | var lang; 59 | var font; 60 | var theme; 61 | 62 | class Editor extends Component { 63 | constructor(props) { 64 | super(props); 65 | this.state = { 66 | theme: "tomorrow_night_blue", 67 | fontSize: 16, 68 | }; 69 | let i = 0; 70 | lang = languages.map((language) => { 71 | i++; 72 | return { key: "" + i, text: language, value: language }; 73 | }); 74 | let j = 0; 75 | font = fontSizes.map((fontSize) => { 76 | j++; 77 | return { key: "" + j, text: fontSize, value: fontSize }; 78 | }); 79 | let k = 0; 80 | theme = themes.map((theme) => { 81 | k++; 82 | return { key: "" + k, text: theme, value: theme }; 83 | }); 84 | this.handleOnChange = this.handleOnChange.bind(this); 85 | } 86 | handleOnChange(e, data) { 87 | if (data.placeholder === "Theme") { 88 | this.setState({ theme: data.value }); 89 | } else if (data.placeholder === "Font Size") { 90 | this.setState({ fontSize: parseInt(data.value) }); 91 | } else if (data.placeholder === "Language") { 92 | this.props.onChangeMode(data.value); 93 | } 94 | } 95 | render() { 96 | return ( 97 | 98 | this.props.handleRunClick()} 106 | /> 107 | 114 |
115 |
116 |
CODE HERE
117 |
118 | this.props.onChangeCode(data)} 124 | width={"100vw"} 125 | height={"61.4vh"} 126 | showGutter={true} 127 | useWorker={false} 128 | editorProps={{ $blockScrolling: false }} 129 | setOptions={{ 130 | enableLiveAutocompletion: true, 131 | enableSnippets: true, 132 | }} 133 | /> 134 |
135 |
136 |
137 |
138 |
INPUT
139 |
140 | this.props.onChangeInput(data)} 146 | width={"100vw"} 147 | height={"28vh"} 148 | showGutter={true} 149 | useWorker={false} 150 | editorProps={{ $blockScrolling: false }} 151 | setOptions={{ 152 | enableLiveAutocompletion: true, 153 | enableSnippets: true, 154 | }} 155 | /> 156 |
157 |
158 |
159 |
OUTPUT
160 |
161 | this.props.onChangeOutput(data)} 167 | width={"100vw"} 168 | height={"32vh"} 169 | readOnly={true} 170 | showGutter={true} 171 | useWorker={false} 172 | editorProps={{ $blockScrolling: false }} 173 | setOptions={{ 174 | enableLiveAutocompletion: true, 175 | enableSnippets: true, 176 | }} 177 | /> 178 |
179 |
180 |
181 |
182 | ); 183 | } 184 | } 185 | 186 | export default Editor; 187 | -------------------------------------------------------------------------------- /frontend/src/components/App.jsx: -------------------------------------------------------------------------------- 1 | import React, { Component } from "react"; 2 | import Header from "./Header"; 3 | import VideoBar from "./VideoBar"; 4 | import Editor from "./Editor"; 5 | import Footer from "./Footer"; 6 | import io from "socket.io-client"; 7 | import Peer from "peerjs"; 8 | import axios from "axios"; 9 | import "../css/App.css"; 10 | const myPeer = new Peer(); 11 | // https://peaceful-depths-33963.herokuapp.com/ 12 | // http://localhost:4000 13 | const socket = io("http://localhost:4000"); 14 | const peers = {}; 15 | 16 | class App extends Component { 17 | constructor(props) { 18 | super(props); 19 | this.state = { 20 | userId: "", 21 | stream: {}, 22 | peers: [], 23 | mode: "java", 24 | code: "", 25 | input: "", 26 | output: "", 27 | status: "RUN", 28 | }; 29 | this.handleVideoToggle = this.handleVideoToggle.bind(this); 30 | this.handleAudioToggle = this.handleAudioToggle.bind(this); 31 | this.handleChangeCode = this.handleChangeCode.bind(this); 32 | this.handleChangeInput = this.handleChangeInput.bind(this); 33 | this.handleChangeOutput = this.handleChangeOutput.bind(this); 34 | this.handleRunClick = this.handleRunClick.bind(this); 35 | this.handleChangeMode = this.handleChangeMode.bind(this); 36 | } 37 | componentDidMount() { 38 | myPeer.on("open", (id) => { 39 | navigator.mediaDevices 40 | .getUserMedia({ 41 | video: true, 42 | audio: true, 43 | }) 44 | .then((stream) => { 45 | this.addUserIdAndStream(id, stream); 46 | this.addVideoStream(id, stream, false); 47 | socket.on("user-connected", (userId) => { 48 | this.connectToNewUser(userId, stream); 49 | this.sendDatatoNewUser(); 50 | }); 51 | myPeer.on("call", (call) => { 52 | call.answer(stream); 53 | call.on("stream", (userVideoStream) => { 54 | this.addVideoStream(call.peer, userVideoStream, false); 55 | }); 56 | call.on("close", () => { 57 | const peers = this.state.peers; 58 | var peersModified = peers.filter((peer) => { 59 | return peer.userId !== call.peer; 60 | }); 61 | this.setState({ peers: peersModified }); 62 | }); 63 | peers[call.peer] = call; 64 | }); 65 | socket.emit("join-room", this.props.roomId, id); 66 | socket.on("receive code", (payload) => { 67 | this.updateCodeFromSockets(payload); 68 | }); 69 | socket.on("receive input", (payload) => { 70 | this.updateInputFromSockets(payload); 71 | }); 72 | socket.on("receive output", (payload) => { 73 | this.updateOutputFromSockets(payload); 74 | }); 75 | socket.on("receive-data-for-new-user", (payload) => { 76 | this.updateStateFromSockets(payload); 77 | }); 78 | socket.on("mode-change-receive", (payload) => { 79 | this.updateModeFromSockets(payload); 80 | }); 81 | }); 82 | }); 83 | socket.on("user-disconnected", (userId) => { 84 | if (peers[userId]) peers[userId].close(); 85 | }); 86 | } 87 | sendDatatoNewUser() { 88 | socket.emit("data-for-new-user", { 89 | newCode: this.state.code, 90 | newInput: this.state.input, 91 | newOutput: this.state.output, 92 | newMode: this.state.mode, 93 | }); 94 | } 95 | updateStateFromSockets(payload) { 96 | this.setState({ code: payload.newCode }); 97 | this.setState({ input: payload.newInput }); 98 | this.setState({ output: payload.newOutput }); 99 | this.setState({ mode: payload.newMode }); 100 | } 101 | updateCodeFromSockets(payload) { 102 | this.setState({ code: payload.newCode }); 103 | } 104 | updateInputFromSockets(payload) { 105 | this.setState({ input: payload.newInput }); 106 | } 107 | updateOutputFromSockets(payload) { 108 | this.setState({ output: payload.newOutput }); 109 | } 110 | updateModeFromSockets(payload) { 111 | this.setState({ mode: payload.mode }); 112 | } 113 | connectToNewUser(userId, stream) { 114 | const call = myPeer.call(userId, stream); 115 | call.on("stream", (userVideoStream) => { 116 | this.addVideoStream(userId, userVideoStream, false); 117 | }); 118 | call.on("close", () => { 119 | const peers = this.state.peers; 120 | var peersModified = peers.filter((peer) => { 121 | return peer.userId !== userId; 122 | }); 123 | this.setState({ peers: peersModified }); 124 | }); 125 | peers[userId] = call; 126 | } 127 | 128 | addVideoStream(userId, stream, flag) { 129 | if (userId === this.state.userId) { 130 | stream.getVideoTracks()[0].enabled = false; 131 | stream.getAudioTracks()[0].enabled = false; 132 | } 133 | const peers = this.state.peers; 134 | peers.forEach((peer) => { 135 | if (peer.userId === userId) { 136 | peer.stream = stream; 137 | flag = true; 138 | } 139 | }); 140 | if (!flag) peers.push({ userId: userId, stream: stream }); 141 | this.setState({ peers: peers }); 142 | } 143 | 144 | addUserIdAndStream(userId, stream) { 145 | this.setState({ userId: userId, stream: stream }); 146 | } 147 | 148 | handleVideoToggle(userId) { 149 | this.state.peers.forEach((peer) => { 150 | if (peer.userId === userId) { 151 | const enabled = peer.stream.getVideoTracks()[0].enabled; 152 | peer.stream.getVideoTracks()[0].enabled = !enabled; 153 | } 154 | }); 155 | } 156 | 157 | handleAudioToggle(userId) { 158 | this.state.peers.forEach((peer) => { 159 | if (peer.userId === userId) { 160 | const enabled = peer.stream.getAudioTracks()[0].enabled; 161 | peer.stream.getAudioTracks()[0].enabled = !enabled; 162 | } 163 | }); 164 | } 165 | handleChangeCode(newCode) { 166 | this.setState({ code: newCode }); 167 | socket.emit("code change", { 168 | newCode: newCode, 169 | }); 170 | } 171 | handleChangeInput(newInput) { 172 | this.setState({ input: newInput }); 173 | socket.emit("input change", { 174 | newInput: newInput, 175 | }); 176 | } 177 | handleChangeOutput(newOutput) { 178 | this.setState({ output: newOutput }); 179 | socket.emit("output change", { 180 | newOutput: newOutput, 181 | }); 182 | } 183 | handleRunClick() { 184 | this.setState({ 185 | status: `RUNNING `, 186 | }); 187 | const params = { 188 | source_code: this.state.code, 189 | language: this.state.mode, 190 | input: this.state.input, 191 | api_key: "guest", 192 | }; 193 | axios.post(`https://api.paiza.io/runners/create`, params).then((res) => { 194 | const query = new URLSearchParams({ 195 | id: res.data.id, 196 | api_key: "guest", 197 | }); 198 | var callback = (res, error) => { 199 | this.setState({ status: "RUN" }); 200 | // consume data 201 | if (error) { 202 | console.error(error); 203 | return; 204 | } 205 | let output = ""; 206 | if (res.data.stdout) output += res.data.stdout; 207 | if (res.data.stderr) output += res.data.stderr; 208 | if (res.data.build_stderr) output += res.data.build_stderr; 209 | this.handleChangeOutput(output); 210 | }; 211 | 212 | request(10, callback); 213 | function request(retries, callback) { 214 | axios 215 | .get(`https://api.paiza.io/runners/get_details?${query.toString()}`) 216 | .then((response) => { 217 | // request successful 218 | 219 | if (response.data.status === "completed") { 220 | // server done, deliver data to script to consume 221 | callback(response); 222 | } else { 223 | if (retries > 0) { 224 | request(--retries, callback); 225 | } else { 226 | // no retries left, calling callback with error 227 | callback([], "out of retries"); 228 | } 229 | } 230 | }) 231 | .catch((error) => { 232 | // ajax error occurred 233 | // would be better to not retry on 404, 500 and other unrecoverable HTTP errors 234 | // retry, if any retries left 235 | if (retries > 0) { 236 | request(--retries, callback); 237 | } else { 238 | // no retries left, calling callback with error 239 | callback([], error); 240 | } 241 | }); 242 | } 243 | }); 244 | } 245 | handleChangeMode(mode) { 246 | this.setState({ mode: mode }); 247 | socket.emit("mode-change-send", { mode: mode }); 248 | } 249 | 250 | render() { 251 | return ( 252 | 253 |
259 | 260 | 272 |