├── .babelrc ├── .env.development ├── .env.production ├── .eslintrc ├── .gitignore ├── .prettierrc ├── LICENSE ├── README.md ├── build-utils ├── addons │ ├── webpack.bundleanalyze.js │ └── webpack.bundlevisualizer.js ├── webpack.common.js ├── webpack.config.js ├── webpack.dev.js └── webpack.prod.js ├── jsconfig.json ├── netlify.toml ├── package-lock.json ├── package.json ├── postcss.config.js ├── sandbox.config.json └── src ├── api ├── config.js ├── http │ ├── lang-service.js │ └── room-service.js └── ws │ └── room-socket.js ├── app ├── App.css ├── App.jsx ├── app-slice.js └── store.js ├── assets ├── images │ ├── demo.png │ └── placeholder.png └── svg │ └── editor-loading.svg ├── components ├── control-bar │ ├── control-bar.css │ └── control-bar.jsx ├── editor-dropdown │ └── editor-dropdown.jsx └── video-player │ ├── video-player.css │ └── video-player.jsx ├── constants ├── colors.js └── languages.js ├── features ├── editor-slice.js ├── shared-monaco-editor │ ├── default-config.js │ ├── shared-monaco-editor.css │ ├── shared-monaco-editor.jsx │ └── theme-utils.js ├── terminal │ ├── log-renderer.js │ ├── terminal.css │ └── terminal.jsx ├── video-chat │ ├── video-chat.css │ └── video-chat.jsx └── video-slice.js ├── index.css ├── index.html ├── index.js ├── lib └── emitter.js ├── pages ├── home │ ├── home.css │ └── home.jsx └── room │ ├── room.css │ └── room.jsx ├── service-worker.js ├── sync-manager.js └── themes ├── css └── codesandbox-black.css ├── monaco-themes ├── codesandbox-black.js └── index.js └── variables ├── common.js └── themes.js /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": ["@babel/preset-env", "@babel/preset-react"], 3 | "plugins": [ 4 | "@babel/plugin-proposal-optional-chaining", 5 | "@babel/plugin-proposal-class-properties", 6 | ] 7 | } 8 | -------------------------------------------------------------------------------- /.env.development: -------------------------------------------------------------------------------- 1 | NODE_ENV=development -------------------------------------------------------------------------------- /.env.production: -------------------------------------------------------------------------------- 1 | NODE_ENV=production -------------------------------------------------------------------------------- /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "parser": "babel-eslint", 3 | "parserOptions": { 4 | "sourceType": "module" 5 | }, 6 | "env": { 7 | "browser": true, 8 | "es6": true, 9 | "node": true 10 | }, 11 | "extends": ["airbnb", "prettier"], 12 | "plugins": ["prettier"], 13 | "rules": { 14 | "prettier/prettier": ["error"], 15 | "import/no-extraneous-dependencies": 0, 16 | "react/jsx-filename-extension": 0 17 | }, 18 | "settings": { 19 | "import/resolver": { 20 | "webpack": { 21 | "config": "./build-utils/webpack.common.js" 22 | } 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | dist/* 2 | node_modules/* 3 | .vscode -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "semi": true, 3 | "trailingComma": "es5", 4 | "singleQuote": true, 5 | "printWidth": 70 6 | } 7 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # codeinterview-frontend 2 | 3 |

4 | 5 |

6 | 7 | This is the front-end for [codeinterview](https://github.com/areebbeigh/codeinterview-backend) in ReactJS. 8 | 9 | ## What I'm using 10 | 11 | - The editor is implemented using [react-monaco-editor](https://github.com/react-monaco-editor/react-monaco-editor). 12 | - [y-webrtc](https://github.com/yjs/y-webrtc) adds p2p collaborative editing capabilities using [CDRTs](https://en.wikipedia.org/wiki/Conflict-free_replicated_data_type). 13 | - [x-termjs](https://github.com/xtermjs/xterm.js) for the terminal. 14 | -------------------------------------------------------------------------------- /build-utils/addons/webpack.bundleanalyze.js: -------------------------------------------------------------------------------- 1 | const WebpackBundleAnalyzer = require('webpack-bundle-analyzer').BundleAnalyzerPlugin; 2 | 3 | module.exports = { 4 | plugins: [ 5 | new WebpackBundleAnalyzer({ 6 | analyzerMode: 'static', 7 | reportFilename: './report.html', 8 | openAnalyzer: false 9 | }) 10 | ] 11 | }; -------------------------------------------------------------------------------- /build-utils/addons/webpack.bundlevisualizer.js: -------------------------------------------------------------------------------- 1 | const Visualizer = require('webpack-visualizer-plugin'); 2 | 3 | module.exports = { 4 | plugins: [ 5 | new Visualizer() 6 | ] 7 | }; -------------------------------------------------------------------------------- /build-utils/webpack.common.js: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | const { CleanWebpackPlugin } = require('clean-webpack-plugin'); 3 | const HtmlWebpackPlugin = require('html-webpack-plugin'); 4 | const MonacoWebpackPlugin = require('monaco-editor-webpack-plugin'); 5 | const languages = require('../src/constants/languages'); 6 | 7 | const APP_DIR = path.resolve(__dirname, '..', './src'); 8 | const NODE_MODULES = path.resolve(__dirname, '..', './node_modules'); 9 | 10 | module.exports = { 11 | entry: './src/index.js', 12 | module: { 13 | rules: [ 14 | { 15 | test: /\.(config\.js|js|jsx)$/, 16 | exclude: /node_modules/, 17 | use: ['babel-loader'], 18 | }, 19 | { 20 | test: /\.(woff|woff2)$/, 21 | use: { 22 | loader: 'url-loader', 23 | }, 24 | }, 25 | { 26 | test: /\.ttf$/, 27 | use: ['file-loader'], 28 | }, 29 | { 30 | test: /\.(png|jp(e*)g|svg|gif)$/, 31 | use: ['file-loader'], 32 | }, 33 | { 34 | test: /\.css$/, 35 | include: NODE_MODULES, 36 | use: ['style-loader', 'css-loader'], 37 | }, 38 | { 39 | test: /\.css$/, 40 | include: APP_DIR, 41 | use: [ 42 | 'style-loader', 43 | { 44 | loader: 'css-loader', 45 | options: { 46 | modules: false, 47 | importLoaders: 1, 48 | }, 49 | }, 50 | 'postcss-loader', 51 | ], 52 | }, 53 | ], 54 | }, 55 | resolve: { 56 | extensions: ['*', '.js', '.jsx'], 57 | alias: { 58 | features: path.resolve(__dirname, '..', 'src', 'features'), 59 | components: path.resolve(__dirname, '..', 'src', 'components'), 60 | themes: path.resolve(__dirname, '..', 'src', 'themes'), 61 | lib: path.resolve(__dirname, '..', 'src', 'lib'), 62 | pages: path.resolve(__dirname, '..', 'src', 'pages'), 63 | api: path.resolve(__dirname, '..', 'src', 'api'), 64 | constants: path.resolve(__dirname, '..', 'src', 'constants'), 65 | assets: path.resolve(__dirname, '..', 'src', 'assets'), 66 | '@': path.resolve(__dirname, '..', 'src'), 67 | }, 68 | }, 69 | plugins: [ 70 | new CleanWebpackPlugin(), 71 | new HtmlWebpackPlugin({ 72 | title: 'CodeInterview', 73 | template: './src/index.html', 74 | }), 75 | new MonacoWebpackPlugin({ 76 | // available options are documented at https://github.com/Microsoft/monaco-editor-webpack-plugin#options 77 | // languages: [ 78 | // 'cpp', 79 | // 'csharp', 80 | // 'go', 81 | // 'java', 82 | // 'typescript', 83 | // 'javascript', 84 | // 'objective-c', 85 | // 'python', 86 | // 'rust', 87 | // ], 88 | languages: ['typescript', ...Object.keys(languages)], 89 | }), 90 | ], 91 | output: { 92 | path: path.resolve(__dirname, '../', 'dist'), 93 | publicPath: '/', 94 | filename: 'bundle.js', 95 | }, 96 | }; 97 | -------------------------------------------------------------------------------- /build-utils/webpack.config.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable global-require */ 2 | /* eslint-disable import/no-dynamic-require */ 3 | 4 | const webpackMerge = require('webpack-merge'); 5 | 6 | const commonConfig = require('./webpack.common.js'); 7 | 8 | const getAddons = addonsArgs => { 9 | const addons = Array.isArray(addonsArgs) 10 | ? addonsArgs 11 | : [addonsArgs]; 12 | 13 | return addons 14 | .filter(Boolean) 15 | .map(name => require(`./addons/webpack.${name}.js`)); 16 | }; 17 | 18 | module.exports = ({ env, addon }) => { 19 | const envConfig = require(`./webpack.${env}.js`); 20 | 21 | return webpackMerge(commonConfig, envConfig, ...getAddons(addon)); 22 | }; 23 | -------------------------------------------------------------------------------- /build-utils/webpack.dev.js: -------------------------------------------------------------------------------- 1 | const webpack = require('webpack'); 2 | const Dotenv = require('dotenv-webpack'); 3 | 4 | module.exports = { 5 | mode: 'development', 6 | devtool: 'eval-source-map', 7 | plugins: [ 8 | new webpack.HotModuleReplacementPlugin(), 9 | new Dotenv({ 10 | path: './.env.development', 11 | }), 12 | ], 13 | devServer: { 14 | contentBase: './dist', 15 | hot: true, 16 | historyApiFallback: true, 17 | }, 18 | }; 19 | -------------------------------------------------------------------------------- /build-utils/webpack.prod.js: -------------------------------------------------------------------------------- 1 | const Dotenv = require('dotenv-webpack'); 2 | 3 | module.exports = { 4 | mode: 'production', 5 | devtool: 'source-map', 6 | plugins: [ 7 | new Dotenv({ 8 | path: './.env.production', 9 | }), 10 | ], 11 | devServer: { 12 | contentBase: './dist', 13 | }, 14 | }; 15 | -------------------------------------------------------------------------------- /jsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "baseUrl": "src", 4 | } 5 | } -------------------------------------------------------------------------------- /netlify.toml: -------------------------------------------------------------------------------- 1 | [[redirects]] 2 | from = "/*" 3 | to = "/index.html" 4 | status = 200 -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "codeinterview-frontend", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "start": "webpack-dev-server --config build-utils/webpack.config.js --env.env=dev", 8 | "build": "webpack --config build-utils/webpack.config.js --env.env=prod", 9 | "watch": "webpack --config build-utils/webpack.config.js --watch --env.env=dev", 10 | "build:analyze": "npm run build -- --env.addon=bundleanalyze --env.addon=bundlevisualizer", 11 | "test": "echo \"Error: no test specified\" && exit 0" 12 | }, 13 | "keywords": [], 14 | "author": "Areeb Beigh ", 15 | "license": "MIT", 16 | "devDependencies": { 17 | "@babel/core": "^7.6.4", 18 | "@babel/plugin-proposal-class-properties": "^7.8.3", 19 | "@babel/plugin-proposal-optional-chaining": "^7.9.0", 20 | "@babel/plugin-transform-runtime": "^7.9.0", 21 | "@babel/preset-env": "^7.6.3", 22 | "@babel/preset-react": "^7.6.3", 23 | "babel-eslint": "^10.0.3", 24 | "babel-loader": "^8.0.6", 25 | "clean-webpack-plugin": "^3.0.0", 26 | "css-loader": "^3.4.2", 27 | "dotenv-webpack": "^1.7.0", 28 | "eslint": "^6.5.1", 29 | "eslint-config-airbnb": "^18.0.1", 30 | "eslint-config-prettier": "^6.4.0", 31 | "eslint-import-resolver-webpack": "^0.12.1", 32 | "eslint-loader": "^3.0.2", 33 | "eslint-plugin-import": "^2.18.2", 34 | "eslint-plugin-jsx-a11y": "^6.2.3", 35 | "eslint-plugin-prettier": "^3.1.1", 36 | "eslint-plugin-react": "^7.16.0", 37 | "file-loader": "^6.0.0", 38 | "html-webpack-plugin": "^3.2.0", 39 | "postcss-import": "^12.0.1", 40 | "postcss-import-url": "^5.1.0", 41 | "postcss-load-config": "^2.1.0", 42 | "postcss-loader": "^3.0.0", 43 | "postcss-nested": "^4.2.1", 44 | "postcss-simple-vars": "^5.0.2", 45 | "prettier": "^1.18.2", 46 | "react-hot-loader": "^4.12.15", 47 | "style-loader": "^1.1.3", 48 | "sugarss": "^2.0.0", 49 | "ttf-loader": "^1.0.2", 50 | "url-loader": "^4.0.0", 51 | "webpack": "^4.41.2", 52 | "webpack-bundle-analyzer": "^3.6.0", 53 | "webpack-cli": "^3.3.9", 54 | "webpack-dev-server": "^3.8.2", 55 | "webpack-merge": "^4.2.2", 56 | "webpack-visualizer-plugin": "^0.1.11" 57 | }, 58 | "dependencies": { 59 | "@fortawesome/fontawesome-svg-core": "^1.2.28", 60 | "@fortawesome/free-solid-svg-icons": "^5.13.0", 61 | "@fortawesome/react-fontawesome": "^0.1.9", 62 | "@reduxjs/toolkit": "^1.3.2", 63 | "axios": "^0.19.2", 64 | "bootstrap": "^4.4.1", 65 | "chalk": "^4.0.0", 66 | "moment": "^2.24.0", 67 | "monaco-editor-webpack-plugin": "^1.9.0", 68 | "overlayscrollbars": "^1.12.0", 69 | "overlayscrollbars-react": "^0.2.2", 70 | "postcss-define-function": "^0.1.2", 71 | "postcss-modules-values": "^3.0.0", 72 | "prop-types": "^15.7.2", 73 | "react": "^16.10.2", 74 | "react-bootstrap": "^1.0.0", 75 | "react-bootstrap-dialog": "^0.13.0", 76 | "react-device-detect": "^1.12.1", 77 | "react-dom": "^16.10.2", 78 | "react-monaco-editor": "^0.35.0", 79 | "react-redux": "^7.2.0", 80 | "react-router-dom": "^5.1.2", 81 | "react-toastify": "^6.0.5", 82 | "reconnecting-websocket": "^4.4.0", 83 | "regenerator-runtime": "^0.13.5", 84 | "uuid": "^7.0.3", 85 | "xterm": "^4.5.0", 86 | "xterm-addon-fit": "^0.3.0", 87 | "y-monaco": "0.0.1", 88 | "y-webrtc": "^10.1.4", 89 | "yjs": "^13.0.5" 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /postcss.config.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable prefer-object-spread */ 2 | /* eslint-disable prefer-template */ 3 | const commonVariables = require('./src/themes/variables/common'); 4 | // const themes = require('./src/themes/variables/themes'); 5 | 6 | // const themeVariables = {}; 7 | 8 | // Object.keys(themes).forEach(themeName => { 9 | // const theme = themes[themeName]; 10 | // Object.keys(theme).forEach(varName => { 11 | // themeVariables[themeName + '-' + varName] = theme[varName]; 12 | // }); 13 | // }); 14 | 15 | module.exports = { 16 | plugins: { 17 | 'postcss-import': { 18 | path: './src', 19 | }, 20 | 'postcss-import-url': {}, 21 | 'postcss-nested': {}, 22 | 'postcss-simple-vars': { 23 | variables: commonVariables, 24 | }, 25 | }, 26 | }; 27 | -------------------------------------------------------------------------------- /sandbox.config.json: -------------------------------------------------------------------------------- 1 | 2 | { 3 | "template": "node" 4 | } 5 | -------------------------------------------------------------------------------- /src/api/config.js: -------------------------------------------------------------------------------- 1 | let baseURL = 'codeinterview-backend.herokuapp.com'; 2 | let httpPrefix = 'https://'; 3 | let wsPrefix = 'wss://'; 4 | if (process.env.NODE_ENV === 'development') { 5 | baseURL = 'localhost:8000'; 6 | httpPrefix = 'http://'; 7 | wsPrefix = 'ws://'; 8 | } 9 | 10 | export default { 11 | http: { 12 | baseURL: `${httpPrefix}${baseURL}/api`, 13 | }, 14 | ws: { 15 | baseURL: `${wsPrefix}${baseURL}/ws`, 16 | }, 17 | }; 18 | -------------------------------------------------------------------------------- /src/api/http/lang-service.js: -------------------------------------------------------------------------------- 1 | import axios from 'axios'; 2 | 3 | import config from 'api/config'; 4 | 5 | class LangService { 6 | constructor() { 7 | this.axios = axios.create({ 8 | baseURL: `${config.http.baseURL}/languages/`, 9 | timeout: 5000, 10 | headers: {}, 11 | }); 12 | } 13 | 14 | async getLanguages() { 15 | const languages = await this.axios.get(); 16 | const rv = {}; 17 | languages.data.forEach(lang => { 18 | rv[lang.code] = lang; 19 | }); 20 | return rv; 21 | } 22 | } 23 | 24 | export default () => new LangService(); 25 | -------------------------------------------------------------------------------- /src/api/http/room-service.js: -------------------------------------------------------------------------------- 1 | import axios from 'axios'; 2 | 3 | import config from 'api/config'; 4 | 5 | class RoomService { 6 | constructor() { 7 | this.axios = axios.create({ 8 | baseURL: `${config.http.baseURL}/rooms/`, 9 | timeout: 5000, 10 | headers: {}, 11 | }); 12 | } 13 | 14 | async createNewRoom() { 15 | const room = await this.axios.post(''); 16 | return room; 17 | } 18 | 19 | async getRoom(id) { 20 | if (!id) throw Error('Invalid room ID'); 21 | const room = await this.axios.get(id); 22 | return room; 23 | } 24 | } 25 | 26 | export default () => new RoomService(); 27 | -------------------------------------------------------------------------------- /src/api/ws/room-socket.js: -------------------------------------------------------------------------------- 1 | import ReconnectingWebsocket from 'reconnecting-websocket'; 2 | 3 | import config from 'api/config'; 4 | import EventEmitter from 'lib/emitter'; 5 | import LANGUAGE_CODES from 'constants/languages'; 6 | 7 | class RoomSocket extends EventEmitter { 8 | constructor(roomId, username) { 9 | super(); 10 | const url = `${config.ws.baseURL}/rooms/${roomId}?username=${username}`; 11 | this.ws = new ReconnectingWebsocket(url); 12 | window.ws = this.ws; 13 | this.ws.onopen = this.emit('open'); 14 | 15 | this.ws.onmessage = message => { 16 | const data = JSON.parse(message.data); 17 | console.log(message, data); 18 | if (data.type === 'event') { 19 | this.emit(data.event, data.data); 20 | } 21 | }; 22 | } 23 | 24 | // Helpers 25 | 26 | sendJson(jsonData) { 27 | this.ws.send(JSON.stringify(jsonData)); 28 | } 29 | 30 | // Commands 31 | 32 | sendRun({ language, code, stdin }) { 33 | this.sendJson({ 34 | command: 'run', 35 | language: LANGUAGE_CODES[language], 36 | code, 37 | stdin, 38 | }); 39 | } 40 | 41 | sendMessage(msg) { 42 | this.sendJson({ 43 | command: 'send-message', 44 | message: msg, 45 | }); 46 | } 47 | 48 | sendJoinCall() { 49 | this.sendJson({ 50 | command: 'join-call', 51 | }); 52 | } 53 | 54 | sendLeaveCall() { 55 | this.sendJson({ 56 | command: 'leave-call', 57 | }); 58 | } 59 | } 60 | 61 | export default (roomId, username) => new RoomSocket(roomId, username); 62 | -------------------------------------------------------------------------------- /src/app/App.css: -------------------------------------------------------------------------------- 1 | .btn:focus { 2 | box-shadow: none !important; 3 | } 4 | 5 | body { 6 | background-color: #151515; 7 | } 8 | 9 | .placeholder-container { 10 | width: 250px; 11 | position: absolute; 12 | top: 50%; 13 | left: 50%; 14 | transform: translate(-50%, -50%); 15 | z-index: -1; 16 | text-align: center; 17 | color: white !important; 18 | } 19 | 20 | #placeholder-img { 21 | width: 100%; 22 | padding: 2px; 23 | } -------------------------------------------------------------------------------- /src/app/App.jsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import PropTypes from 'prop-types'; 3 | import { Provider } from 'react-redux'; 4 | import { useLocation } from 'react-router-dom'; 5 | import { ToastContainer, Zoom } from 'react-toastify'; 6 | 7 | import placeHolderImg from 'assets/images/placeholder.png'; 8 | import store from './store'; 9 | 10 | import './App.css'; 11 | import 'bootstrap/dist/css/bootstrap.min.css'; 12 | 13 | const App = ({ children }) => { 14 | const { pathname } = useLocation(); 15 | return ( 16 | <> 17 | {children} 18 | 25 | {pathname !== '/' && ( 26 |
27 | 28 |

Hi there.

29 |
30 | )} 31 | 32 | ); 33 | }; 34 | 35 | App.propTypes = { 36 | children: PropTypes.node.isRequired, 37 | }; 38 | 39 | export default App; 40 | -------------------------------------------------------------------------------- /src/app/app-slice.js: -------------------------------------------------------------------------------- 1 | import { createSlice } from '@reduxjs/toolkit'; 2 | 3 | const appSlice = createSlice({ 4 | name: 'app', 5 | initialState: { 6 | username: null, 7 | }, 8 | reducers: { 9 | setUsername(state, action) { 10 | return { 11 | ...state, 12 | username: action.payload, 13 | }; 14 | }, 15 | }, 16 | }); 17 | 18 | export const { setUsername } = appSlice.actions; 19 | export default appSlice.reducer; 20 | -------------------------------------------------------------------------------- /src/app/store.js: -------------------------------------------------------------------------------- 1 | import { configureStore } from '@reduxjs/toolkit'; 2 | import videoReducer from 'features/video-slice'; 3 | import editorReducer from 'features/editor-slice'; 4 | 5 | export default configureStore({ 6 | reducer: { 7 | video: videoReducer, 8 | editor: editorReducer, 9 | }, 10 | }); 11 | -------------------------------------------------------------------------------- /src/assets/images/demo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areebbeigh/codeinterview-frontend/819484927563904c2a508e5929e373cfa8982d4b/src/assets/images/demo.png -------------------------------------------------------------------------------- /src/assets/images/placeholder.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/areebbeigh/codeinterview-frontend/819484927563904c2a508e5929e373cfa8982d4b/src/assets/images/placeholder.png -------------------------------------------------------------------------------- /src/assets/svg/editor-loading.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /src/components/control-bar/control-bar.css: -------------------------------------------------------------------------------- 1 | @import 'themes/css/codesandbox-black.css'; 2 | 3 | .control-bar-container, .control-bar-container .row { 4 | height: 100%; 5 | background-color: $primary-color; 6 | } -------------------------------------------------------------------------------- /src/components/control-bar/control-bar.jsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import PropTypes from 'prop-types'; 3 | 4 | import './control-bar.css'; 5 | 6 | const controlBar = ({ children }) => { 7 | return
{children}
; 8 | }; 9 | 10 | controlBar.propTypes = { 11 | children: PropTypes.node.isRequired, 12 | }; 13 | 14 | export default controlBar; 15 | -------------------------------------------------------------------------------- /src/components/editor-dropdown/editor-dropdown.jsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import PropTypes from 'prop-types'; 3 | import { Dropdown, DropdownButton } from 'react-bootstrap'; 4 | 5 | const editorDropdown = ({ defaultItem, items, handler }) => { 6 | return ( 7 | 15 | {items.map(item => { 16 | return ( 17 | handler(e, item)} 21 | > 22 | {item} 23 | 24 | ); 25 | })} 26 | 27 | ); 28 | }; 29 | 30 | editorDropdown.propTypes = { 31 | defaultItem: PropTypes.string.isRequired, 32 | items: PropTypes.arrayOf(PropTypes.string).isRequired, 33 | handler: PropTypes.func.isRequired, 34 | }; 35 | 36 | export default editorDropdown; 37 | -------------------------------------------------------------------------------- /src/components/video-player/video-player.css: -------------------------------------------------------------------------------- 1 | .video-container { 2 | position: relative; 3 | text-align: center; 4 | 5 | .controls { 6 | display: inline-block; 7 | position: absolute; 8 | left: 50%; 9 | bottom: 10px; 10 | transform: translate(-50%); 11 | background: rgb(0,0,0,0.3); 12 | color: white; 13 | 14 | .icon { 15 | vertical-align: middle; 16 | font-size: 20px; 17 | width: 30px; 18 | } 19 | } 20 | } 21 | 22 | /* .video-container:hover { 23 | .controls { 24 | display: inline-block; 25 | } 26 | } */ -------------------------------------------------------------------------------- /src/components/video-player/video-player.jsx: -------------------------------------------------------------------------------- 1 | /* eslint-disable jsx-a11y/media-has-caption */ 2 | import React, { useState, useEffect } from 'react'; 3 | import PropTypes from 'prop-types'; 4 | import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; 5 | import { 6 | faMicrophone, 7 | faMicrophoneSlash, 8 | } from '@fortawesome/free-solid-svg-icons'; 9 | 10 | import './video-player.css'; 11 | 12 | function connectVideoToStream(video, stream) { 13 | // eslint-disable-next-line no-param-reassign 14 | if (stream) video.srcObject = stream; 15 | } 16 | 17 | const Player = ({ 18 | stream, 19 | width, 20 | className, 21 | onClick, 22 | showControls, 23 | name, 24 | }) => { 25 | const [isMuted, setMuted] = useState(false); 26 | const videoRef = React.createRef(); 27 | 28 | useEffect(() => { 29 | connectVideoToStream(videoRef.current, stream); 30 | }, [stream]); 31 | 32 | const toggleAudio = () => { 33 | videoRef.current.muted = !isMuted; 34 | setMuted(!isMuted); 35 | }; 36 | 37 | if (stream) { 38 | return ( 39 |
40 |
58 | ); 59 | } 60 | return
; 61 | }; 62 | 63 | Player.defaultProps = { 64 | stream: null, 65 | width: '100%', 66 | className: '', 67 | onClick: () => null, 68 | showControls: false, 69 | name: '', 70 | }; 71 | Player.propTypes = { 72 | stream: PropTypes.shape({}), 73 | width: PropTypes.string, 74 | className: PropTypes.string, 75 | onClick: PropTypes.func, 76 | showControls: PropTypes.bool, 77 | name: PropTypes.string, 78 | }; 79 | 80 | export default Player; 81 | -------------------------------------------------------------------------------- /src/constants/colors.js: -------------------------------------------------------------------------------- 1 | export default { 2 | userColors: ['#46bddf', '#52d273', '#e84f64', '#e57255', '#e5c453'], 3 | }; 4 | -------------------------------------------------------------------------------- /src/constants/languages.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | cpp: 'cpp', 3 | python: 'python3.6', 4 | java: 'java', 5 | javascript: 'javascript', 6 | }; 7 | -------------------------------------------------------------------------------- /src/features/editor-slice.js: -------------------------------------------------------------------------------- 1 | import { createSlice } from '@reduxjs/toolkit'; 2 | 3 | const editorSlice = createSlice({ 4 | name: 'editor', 5 | initialState: { 6 | globalSettings: { 7 | theme: 'vs-dark', 8 | }, 9 | }, 10 | }); 11 | 12 | export default editorSlice.reducer; 13 | -------------------------------------------------------------------------------- /src/features/shared-monaco-editor/default-config.js: -------------------------------------------------------------------------------- 1 | export default { 2 | automaticLayout: true, 3 | scrollbar: { 4 | useShadows: false, 5 | verticalHasArrows: false, 6 | horizontalHasArrows: false, 7 | verticalScrollbarSize: 5, 8 | horizontalScrollbarSize: 5, 9 | arrowSize: 30, 10 | }, 11 | minimap: { 12 | enabled: false, 13 | }, 14 | }; 15 | -------------------------------------------------------------------------------- /src/features/shared-monaco-editor/shared-monaco-editor.css: -------------------------------------------------------------------------------- 1 | @import 'themes/css/codesandbox-black.css'; 2 | 3 | .loading-screen { 4 | position: absolute; 5 | top: 0; 6 | left: 0; 7 | height: 100%; 8 | width: 100%; 9 | background-color: $primary-color; 10 | color: white; 11 | z-index: 2; 12 | opacity: 0.95; 13 | 14 | .loading-content { 15 | position: absolute; 16 | top: 50%; 17 | left: 50%; 18 | transform: translate(-50%, -50%); 19 | text-align: center; 20 | 21 | img { 22 | width: 150px; 23 | height: 150px; 24 | } 25 | } 26 | } 27 | 28 | .shared-editor-container { 29 | /* border: 2px solid #cccccc; */ 30 | height: 100%; 31 | } 32 | 33 | .shared-editor-header { 34 | height: $titlebar-height; 35 | background-color: $primary-color; 36 | max-width: 100%; 37 | margin: 0 !important; 38 | position: relative; 39 | 40 | .dropdown-menu { 41 | height: auto; 42 | max-height: 200px; 43 | } 44 | 45 | .tab-area { 46 | position: absolute; 47 | bottom: 0; 48 | z-index: 1; 49 | .tab { 50 | /* border: 1px solid rgb(0,0,0,0.3); */ 51 | height: 25px; 52 | line-height: 25px; 53 | box-sizing: border-box; 54 | color: #565656; 55 | padding: 0 8px; 56 | border: 1px solid #343a40; 57 | border-left: none; 58 | cursor: pointer; 59 | float: left; 60 | } 61 | .active { 62 | color: #999 !important; 63 | border-bottom: 0; 64 | } 65 | } 66 | } 67 | 68 | .shared-editor-header h5 { 69 | margin: 0; 70 | } 71 | 72 | .shared-editor-container { 73 | .react-monaco-editor-container { 74 | height: calc(100% - $titlebar-height); 75 | } 76 | } 77 | 78 | .dropdown-menu { 79 | height: 200px; 80 | overflow-y: auto; 81 | } -------------------------------------------------------------------------------- /src/features/shared-monaco-editor/shared-monaco-editor.jsx: -------------------------------------------------------------------------------- 1 | /* eslint-disable jsx-a11y/no-static-element-interactions */ 2 | /* eslint-disable jsx-a11y/click-events-have-key-events */ 3 | import React from 'react'; 4 | import { connect } from 'react-redux'; 5 | import PropTypes from 'prop-types'; 6 | import { Row, Col } from 'react-bootstrap'; 7 | import MonacoEditor from 'react-monaco-editor'; 8 | import { MonacoBinding } from 'y-monaco'; 9 | import EditorDropdown from 'components/editor-dropdown/editor-dropdown'; 10 | import { toast } from 'react-toastify'; 11 | 12 | import LANG_CONFIG from 'constants/languages'; 13 | import langService from 'api/http/lang-service'; 14 | import loadingIcon from 'assets/svg/editor-loading.svg'; 15 | import setDefaultTheme from './theme-utils'; 16 | import defaultConfig from './default-config'; 17 | 18 | import './shared-monaco-editor.css'; 19 | 20 | const mapStateToProps = state => ({ 21 | globalSettings: state.editor.globalSettings, 22 | }); 23 | 24 | class SharedMonacoEditor extends React.Component { 25 | constructor(props) { 26 | super(props); 27 | this.editorDidMount = this.editorDidMount.bind(this); 28 | this.handleLanguageChange = this.handleLanguageChange.bind(this); 29 | this.changeTab = this.changeTab.bind(this); 30 | 31 | this.langService = langService(); 32 | this.editor = null; 33 | this.data = { 34 | code: { 35 | model: null, 36 | state: null, 37 | binding: null, 38 | }, 39 | input: { 40 | model: null, 41 | state: null, 42 | binding: null, 43 | }, 44 | }; 45 | this.state = { 46 | currentTab: 'code', 47 | language: 'none', 48 | }; 49 | } 50 | 51 | componentDidMount() { 52 | this.langService 53 | .getLanguages() 54 | .then(languages => { 55 | this.languages = languages; 56 | }) 57 | .catch(err => { 58 | console.error(err); 59 | toast.error( 60 | `Could not load server language data. ${err.message}` 61 | ); 62 | }) 63 | .finally(() => { 64 | const { 65 | language, 66 | sharedEditorDidMount, 67 | loadTemplate, 68 | } = this.props; 69 | if (this.state.language === 'none') { 70 | this.setState({ 71 | language, 72 | loadTemplate, 73 | }); 74 | } 75 | sharedEditorDidMount(this); 76 | }); 77 | } 78 | 79 | componentDidUpdate(prevProps, prevState) { 80 | const { language, loadTemplate } = this.state; 81 | const { data } = this; 82 | const { model } = data.code; 83 | const langCode = LANG_CONFIG[language]; 84 | if ( 85 | prevState.language !== language && 86 | loadTemplate && 87 | this.languages && 88 | langCode in this.languages 89 | ) { 90 | model.pushEditOperations( 91 | [], 92 | [ 93 | { 94 | range: model.getFullModelRange(), 95 | text: 96 | this.languages[LANG_CONFIG[language]]?.template || '', 97 | forceMoveMarkers: true, 98 | }, 99 | ], 100 | () => null 101 | ); 102 | } 103 | } 104 | 105 | componentWillUnmount() { 106 | const { sharedEditorDidMount } = this.props; 107 | sharedEditorDidMount(undefined); 108 | } 109 | 110 | editorDidMount(editor, monaco) { 111 | setDefaultTheme(monaco); // TODO: add multi-theme support 112 | this.editor = editor; 113 | const { language, currentTab } = this.state; 114 | const { doc, webrtcProvider } = window.sync; 115 | 116 | // create editor tabs with y-bindings 117 | const yCode = doc.getText('code'); 118 | const yInput = doc.getText('input'); 119 | this.data.code.model = monaco.editor.createModel('code'); 120 | this.data.input.model = monaco.editor.createModel('input'); 121 | this.data.code.binding = new MonacoBinding( 122 | yCode, 123 | this.data.code.model, 124 | new Set([editor]), 125 | webrtcProvider.awareness 126 | ); 127 | this.data.code.binding = new MonacoBinding( 128 | yInput, 129 | this.data.input.model, 130 | new Set([editor]), 131 | webrtcProvider.awareness 132 | ); 133 | this.changeTab(currentTab); 134 | 135 | const ySharedState = doc.getMap('editor-state'); 136 | ySharedState.observe(() => { 137 | // sync lang change in dropdown without template update 138 | // eslint-disable-next-line no-shadow 139 | const { language } = this.state; 140 | const newLang = ySharedState.get('editor-language'); 141 | console.log('here', newLang); 142 | if (language !== newLang) { 143 | this.setState({ 144 | language: newLang, 145 | loadTemplate: false, 146 | }); 147 | } 148 | }); 149 | } 150 | 151 | handleLanguageChange(e, newLang) { 152 | this.changeLang(newLang); 153 | } 154 | 155 | changeLang(newLang, loadTemplate = true) { 156 | const { doc } = window.sync; 157 | const ySharedState = doc.getMap('editor-state'); 158 | ySharedState.set('editor-language', newLang); 159 | this.setState({ language: newLang, loadTemplate }); 160 | } 161 | 162 | changeTab(tab) { 163 | const { editor } = this; 164 | const { currentTab } = this.state; 165 | this.data[currentTab].state = editor.saveViewState(); 166 | editor.setModel(this.data[tab].model); 167 | editor.restoreViewState(this.data[tab].state); 168 | this.setState({ 169 | currentTab: tab, 170 | }); 171 | editor.focus(); 172 | } 173 | 174 | render() { 175 | const { language, currentTab } = this.state; 176 | const { className, showDropdown, globalSettings } = this.props; 177 | const editorOptions = { 178 | ...defaultConfig, 179 | theme: globalSettings.theme, 180 | }; 181 | const editorLanguages = Object.keys(LANG_CONFIG); 182 | editorLanguages.sort(); 183 | 184 | return ( 185 |
186 | {/* show loading screen till we get language data */} 187 | {language === 'none' && ( 188 |
189 |
190 | loading-editor 195 |

Warming up editor...

196 |
197 |
198 | )} 199 |
200 | 201 |
202 | this.changeTab('code')} 204 | className={`tab ${ 205 | currentTab === 'code' ? 'active' : '' 206 | }`} 207 | > 208 | Code 209 | 210 | this.changeTab('input')} 212 | className={`tab ${ 213 | currentTab === 'input' ? 'active' : '' 214 | }`} 215 | > 216 | Standard Input 217 | 218 |
219 | {showDropdown && ( 220 | 221 | 226 | 227 | )} 228 |
229 | 236 |
237 |
238 | ); 239 | } 240 | } 241 | 242 | SharedMonacoEditor.defaultProps = { 243 | language: 'python', 244 | sharedEditorDidMount: () => null, 245 | loadTemplate: true, 246 | className: '', 247 | showDropdown: false, 248 | globalSettings: {}, 249 | }; 250 | 251 | SharedMonacoEditor.propTypes = { 252 | language: PropTypes.string, 253 | sharedEditorDidMount: PropTypes.func, 254 | loadTemplate: PropTypes.bool, 255 | className: PropTypes.string, 256 | showDropdown: PropTypes.bool, 257 | globalSettings: PropTypes.shape({ 258 | theme: PropTypes.string, 259 | }), 260 | }; 261 | 262 | export default connect(mapStateToProps)(SharedMonacoEditor); 263 | -------------------------------------------------------------------------------- /src/features/shared-monaco-editor/theme-utils.js: -------------------------------------------------------------------------------- 1 | import codesandboxTheme from 'themes/monaco-themes/codesandbox-black'; 2 | 3 | export default monaco => { 4 | monaco.editor.defineTheme('codesandbox-black', codesandboxTheme); 5 | monaco.editor.setTheme('codesandbox-black'); 6 | }; 7 | -------------------------------------------------------------------------------- /src/features/terminal/log-renderer.js: -------------------------------------------------------------------------------- 1 | import chalk from 'chalk'; 2 | import moment from 'moment'; 3 | 4 | const ENTRY_TYPES = { 5 | USER_JOIN: 'UJ', 6 | USER_LEAVE: 'UL', 7 | USER_MSG: 'UM', 8 | USER_RUN: 'UR', 9 | USER_JOIN_CALL: 'UJC', 10 | USER_LEAVE_CALL: 'ULC', 11 | CODE_OUTPUT: 'CO', 12 | }; 13 | 14 | class LogRenderer { 15 | constructor({ showTimestamps, profiles }) { 16 | this.chalk = new chalk.Instance({ level: 3 }); 17 | this.showTimestamps = showTimestamps; 18 | this.profiles = profiles; 19 | } 20 | 21 | colorAuthor(username) { 22 | const profiles = this.profiles.filter( 23 | profile => profile.username === username 24 | ); 25 | if (profiles.length === 0) return this.chalk`{dim ${username}}`; 26 | return this.chalk`{hex('${profiles[0].color}') ${username}}`; 27 | } 28 | 29 | withTimestamp({ timestamp, line }) { 30 | if (this.showTimestamps) { 31 | const ts = this.chalk`{dim ${moment 32 | .unix(timestamp) 33 | .format('hh:mm')}}`; 34 | return this.chalk`${ts} ${line}`; 35 | } 36 | return line; 37 | } 38 | 39 | render({ timestamp, content, type, author }) { 40 | const rv = []; 41 | 42 | const add = line => { 43 | rv.push(this.withTimestamp({ timestamp, line })); 44 | }; 45 | 46 | switch (type) { 47 | case ENTRY_TYPES.USER_JOIN: 48 | add( 49 | this.chalk`{italic.hex('#b2b7bb') {bold ${this.colorAuthor( 50 | author 51 | )}} joined the room}` 52 | ); 53 | break; 54 | case ENTRY_TYPES.USER_LEAVE: 55 | add( 56 | this.chalk`{italic.hex('#b2b7bb') {bold ${this.colorAuthor( 57 | author 58 | )}} left the room}` 59 | ); 60 | break; 61 | case ENTRY_TYPES.USER_RUN: 62 | add( 63 | this.chalk`{italic.white.bold ${this.colorAuthor( 64 | author 65 | )} made a run request}` 66 | ); 67 | break; 68 | case ENTRY_TYPES.USER_MSG: 69 | add( 70 | this.chalk`{bold ${this.colorAuthor(author)}}: ${content}` 71 | ); 72 | break; 73 | case ENTRY_TYPES.USER_JOIN_CALL: 74 | add( 75 | this.chalk`{italic.white.bold ${this.colorAuthor( 76 | author 77 | )} joined the video call}` 78 | ); 79 | break; 80 | case ENTRY_TYPES.USER_LEAVE_CALL: 81 | add( 82 | this.chalk`{italic.white.bold ${this.colorAuthor( 83 | author 84 | )} left the video call}` 85 | ); 86 | break; 87 | case ENTRY_TYPES.CODE_OUTPUT: 88 | rv.push(this.chalk`{dim.italic Code output:}`); 89 | if (content.error) { 90 | content.error 91 | .trim() 92 | .split('\n') 93 | .map(line => this.chalk`{bold.red ${line}}`) 94 | .map(add); 95 | } 96 | if (content.output) { 97 | content.output 98 | .trim() 99 | .split('\n') 100 | .map(line => this.chalk`{bgBlack ${line}}`) 101 | .map(add); 102 | add( 103 | this 104 | .chalk`{italic.dim Execution time: ${content.exec_time}s}` 105 | ); 106 | } 107 | break; 108 | default: 109 | content.split('\n').map(add); 110 | } 111 | return rv; 112 | } 113 | } 114 | 115 | export default LogRenderer; 116 | -------------------------------------------------------------------------------- /src/features/terminal/terminal.css: -------------------------------------------------------------------------------- 1 | @import 'themes/css/codesandbox-black.css'; 2 | 3 | $terminal-input-height: 35px; 4 | 5 | .terminal-container { 6 | height: 100%; 7 | 8 | .terminal-header { 9 | height: $titlebar-height; 10 | background-color: $primary-color; 11 | position: relative; 12 | margin: 0; 13 | 14 | .tab-area { 15 | position: absolute; 16 | bottom: 0; 17 | z-index: 1; 18 | .tab { 19 | /* border: 1px solid rgb(0,0,0,0.3); */ 20 | height: 25px; 21 | line-height: 25px; 22 | box-sizing: border-box; 23 | color: #565656; 24 | padding: 0 8px; 25 | border: 1px solid #343a40; 26 | border-left: none; 27 | cursor: pointer; 28 | float: left; 29 | } 30 | .active { 31 | color: #999 !important; 32 | border-bottom: 0; 33 | } 34 | } 35 | } 36 | 37 | .xterm-container { 38 | height: calc(100% - $titlebar-height - $terminal-input-height); 39 | .xterm { 40 | .xterm-viewport { 41 | overflow: hidden; 42 | } 43 | .xterm-screen { 44 | padding: 15px; 45 | overflow: hidden; 46 | } 47 | .xterm-cursor { 48 | display: none; 49 | } 50 | .xterm-rows { 51 | div { 52 | max-width: 100% !important; 53 | /* height: fit-content !important; */ 54 | white-space: initial; 55 | } 56 | } 57 | } 58 | } 59 | 60 | .terminal-input { 61 | height: $terminal-input-height; 62 | margin: 0 2.5%; 63 | background: rgb(0,0,0,0.2); 64 | color: white; 65 | border: none; 66 | resize: none; 67 | width: 95%; 68 | padding: 2px 10px; 69 | } 70 | .terminal-input:focus { 71 | outline: none; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/features/terminal/terminal.jsx: -------------------------------------------------------------------------------- 1 | import React, { useEffect } from 'react'; 2 | import PropTypes from 'prop-types'; 3 | import { Row } from 'react-bootstrap'; 4 | import { Terminal as Xterm } from 'xterm'; 5 | import { FitAddon } from 'xterm-addon-fit'; 6 | 7 | import LogRenderer from './log-renderer'; 8 | 9 | import 'xterm/css/xterm.css'; 10 | import './terminal.css'; 11 | 12 | const xtermRef = React.createRef(); 13 | const inputRef = React.createRef(); 14 | const logRenderer = new LogRenderer({ 15 | showTimestamps: false, 16 | }); 17 | const addons = { 18 | fitAddon: new FitAddon(), 19 | }; 20 | let xterm = null; 21 | let prevLogs = []; 22 | 23 | const Terminal = ({ 24 | logs, 25 | profiles, 26 | options, 27 | onInput, 28 | className, 29 | name, 30 | }) => { 31 | // Terminal helpers 32 | 33 | const clear = () => { 34 | // https://github.com/xtermjs/xterm.js/issues/950 35 | // When run initially at mount stage, xterm.clear() doesn't work since all the 36 | // content could still be in the write buffer and not rendered. xterm.reset() 37 | // doesn't seem to work either. 38 | xterm.write('\x1b[H\x1b[2J'); 39 | }; 40 | 41 | const writeEntry = log => { 42 | const lines = logRenderer.render(log); 43 | lines.forEach(line => { 44 | xterm.writeln(line); 45 | }); 46 | }; 47 | 48 | const writeLogs = (update = false) => { 49 | if (!update) clear(); 50 | logs.forEach(log => { 51 | // TODO: this check is inefficient. Maintain a hashmap instead. 52 | if (!update || prevLogs.indexOf(log) === -1) writeEntry(log); 53 | }); 54 | }; 55 | 56 | useEffect(() => { 57 | window.addEventListener('resize', () => addons.fitAddon.fit()); 58 | xterm = new Xterm({ 59 | convertEol: true, 60 | fontFamily: `'Fira Mono', monospace`, 61 | fontSize: 15, 62 | rendererType: 'dom', // default is canvas 63 | lineHeight: 1, 64 | theme: { 65 | background: '#151515', 66 | }, 67 | ...options, 68 | }); 69 | xterm.loadAddon(addons.fitAddon); 70 | xterm.open(xtermRef.current); 71 | xterm.inputBuffer = []; 72 | addons.fitAddon.fit(); 73 | 74 | // Accept user input (chat) 75 | inputRef.current.addEventListener('keydown', e => { 76 | if (e.keyCode === 13) { 77 | if (onInput) onInput(inputRef.current.value); 78 | inputRef.current.value = ''; 79 | } 80 | }); 81 | }, []); 82 | 83 | useEffect(() => { 84 | logRenderer.profiles = profiles; 85 | writeLogs(true); 86 | prevLogs = logs; 87 | }, [logs, profiles]); 88 | 89 | return ( 90 |
91 |
92 | 93 |
94 | {name} 95 |
96 |
97 |
98 | 103 |
104 |
105 | ); 106 | }; 107 | 108 | Terminal.defaultProps = { 109 | profiles: [], 110 | options: {}, 111 | onInput: () => {}, 112 | className: '', 113 | name: 'Log Terminal', 114 | }; 115 | Terminal.propTypes = { 116 | profiles: PropTypes.arrayOf( 117 | PropTypes.shape({ 118 | username: PropTypes.string, 119 | color: PropTypes.string, 120 | }) 121 | ), 122 | options: PropTypes.shape({}), 123 | onInput: PropTypes.func, 124 | logs: PropTypes.arrayOf(PropTypes.shape({})).isRequired, 125 | className: PropTypes.string, 126 | name: PropTypes.string, 127 | }; 128 | 129 | export default Terminal; 130 | -------------------------------------------------------------------------------- /src/features/video-chat/video-chat.css: -------------------------------------------------------------------------------- 1 | $window-height: 100vh; 2 | $window-width: 70vw; 3 | $title-bar-height: 30px; 4 | 5 | .video-chat-window { 6 | position: absolute; 7 | top: 50%; 8 | left: 50%; 9 | transform: translate(-50%, -50%); 10 | /* max-width: $window-width; */ 11 | max-height: $window-height; 12 | background: rgb(0, 0, 0, 1); 13 | border-top-right-radius: 0.4em; 14 | border-top-left-radius: 0.4em; 15 | z-index: 1; 16 | overflow: hidden; 17 | 18 | .title-bar { 19 | height: $title-bar-height; 20 | max-height: $title-bar-height; 21 | background: #0c0c0c; 22 | 23 | svg { 24 | height: $title-bar-height; 25 | padding: 7px; 26 | } 27 | 28 | svg:hover { 29 | cursor: pointer; 30 | } 31 | } 32 | 33 | .video-chat-container { 34 | video { 35 | background: #000; 36 | } 37 | 38 | .os-content-glue { 39 | max-height: calc($window-height - $title-bar-height); 40 | } 41 | 42 | .focus-stream-row { 43 | max-height: 50vh; 44 | 45 | .focus-stream { 46 | max-height: 50vh; 47 | } 48 | } 49 | 50 | .peer-stream { 51 | max-height: 18vh; 52 | width: auto !important; 53 | } 54 | } 55 | } 56 | 57 | $compressed-window-height: 360px; 58 | $compressed-window-width: 250px; 59 | 60 | .video-chat-window.compressed { 61 | max-height: $compressed-window-height; 62 | max-width: $compressed-window-width; 63 | left: 100%; 64 | top: 100%; 65 | transform: translate(-110%, calc(-100% - $control-bar-height)); 66 | 67 | .video-chat-container { 68 | .os-host, 69 | .os-content-glue { 70 | max-height: calc($compressed-window-height - $title-bar-height); 71 | max-width: $compressed-window-width; 72 | } 73 | } 74 | } 75 | 76 | .video-chat-window.compressed.minimized { 77 | transform: translate(-110%, calc(-100% - $control-bar-height)); 78 | 79 | .video-chat-container { 80 | .os-host, 81 | .os-content-glue { 82 | max-height: 0px; 83 | height: 0px !important; 84 | } 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /src/features/video-chat/video-chat.jsx: -------------------------------------------------------------------------------- 1 | import React, { useState, useEffect } from 'react'; 2 | import { Row } from 'react-bootstrap'; 3 | import { OverlayScrollbarsComponent } from 'overlayscrollbars-react'; 4 | import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; 5 | import { 6 | faExpandAlt, 7 | faCompressAlt, 8 | faWindowMinimize, 9 | faWindowMaximize, 10 | } from '@fortawesome/free-solid-svg-icons'; 11 | 12 | import Player from 'components/video-player/video-player'; 13 | 14 | import './video-chat.css'; 15 | 16 | function getName(peerId) { 17 | const { sync } = window; 18 | if (peerId in sync.profiles) { 19 | return sync.profiles[peerId].username; 20 | } 21 | return ''; 22 | } 23 | 24 | const VideoChat = () => { 25 | const [myPeerId, setMyPeerId] = useState( 26 | window.sync?.peerId || null 27 | ); 28 | const [streams, setStreams] = useState(window.sync?.streams || {}); 29 | const [localStream, setLocalStream] = useState(null); 30 | const [focusStream, setFocusStream] = useState(null); 31 | const [focusId, setFocusId] = useState(null); 32 | const [uiCompressed, setUiCompressed] = useState(false); 33 | const [uiMinimized, setUiMinimized] = useState(false); 34 | 35 | // Media stream helper 36 | 37 | const getMediaStream = () => { 38 | window.sync 39 | .getUserMedia() 40 | .then(stream => { 41 | // don't want our audio echo 42 | setLocalStream(new MediaStream(stream.getVideoTracks())); 43 | }) 44 | .catch(console.warn); 45 | }; 46 | 47 | // Sync listeners 48 | 49 | const addStream = ({ peerId, stream }) => { 50 | setStreams({ 51 | ...streams, 52 | [peerId]: stream, 53 | }); 54 | }; 55 | 56 | const updatePeers = () => { 57 | setStreams(window.sync.streams); 58 | }; 59 | 60 | useEffect(() => { 61 | const { sync } = window; 62 | // sync object event listeners 63 | sync.on('ready', updatePeers); 64 | sync.on('peers', updatePeers); 65 | sync.on('stream', ({ peerId, stream }) => { 66 | addStream({ peerId, stream }); 67 | setFocusStream(stream); 68 | setFocusId(peerId); 69 | }); 70 | sync.on('peerId', setMyPeerId); 71 | // get user media 72 | getMediaStream(); 73 | 74 | return () => { 75 | try { 76 | window.sync.releaseUserMedia(); 77 | } catch (err) { 78 | console.warn('error while releasing user stream', err); 79 | } 80 | }; 81 | }, []); 82 | 83 | if (uiMinimized && !uiCompressed) setUiCompressed(true); 84 | if (myPeerId) streams[myPeerId] = localStream; 85 | 86 | return ( 87 |
92 |
93 | { 98 | setUiCompressed(!uiCompressed); 99 | setUiMinimized(false); 100 | }} 101 | /> 102 | { 107 | setUiMinimized(!uiMinimized); 108 | }} 109 | /> 110 |
111 |
112 | 120 | 121 | 131 | 132 | 136 | {Object.keys(streams).map(id => { 137 | if ( 138 | focusStream === streams[id] || 139 | (!focusStream && streams[id] === localStream) 140 | ) 141 | return ''; 142 | return ( 143 | { 151 | setFocusStream(streams[id]); 152 | setFocusId(id); 153 | }} 154 | /> 155 | ); 156 | })} 157 | 158 | 159 |
160 |
161 | ); 162 | }; 163 | 164 | export default VideoChat; 165 | -------------------------------------------------------------------------------- /src/features/video-slice.js: -------------------------------------------------------------------------------- 1 | import { createSlice } from '@reduxjs/toolkit'; 2 | 3 | const videoSlice = createSlice({ 4 | name: 'video', 5 | initialState: { 6 | inCall: false, 7 | }, 8 | reducers: { 9 | setInCall(state, action) { 10 | return { 11 | ...state, 12 | inCall: action.payload, 13 | }; 14 | }, 15 | }, 16 | }); 17 | 18 | export const { setInCall } = videoSlice.actions; 19 | export default videoSlice.reducer; 20 | -------------------------------------------------------------------------------- /src/index.css: -------------------------------------------------------------------------------- 1 | html, body { 2 | margin: 0; 3 | padding: 0; 4 | height: 100%; 5 | } -------------------------------------------------------------------------------- /src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | <%= htmlWebpackPlugin.options.title %> 5 | 6 | 7 |
8 | 9 | 10 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | import 'regenerator-runtime/runtime'; 2 | import React from 'react'; 3 | import ReactDOM from 'react-dom'; 4 | import { 5 | BrowserRouter as Router, 6 | Switch, 7 | Route, 8 | } from 'react-router-dom'; 9 | 10 | import Room from 'pages/room/room'; 11 | import Home from 'pages/home/home'; 12 | import * as serviceWorker from './service-worker'; 13 | import App from './app/App'; 14 | 15 | import 'react-toastify/dist/ReactToastify.min.css'; 16 | import 'overlayscrollbars/css/OverlayScrollbars.css'; 17 | import './index.css'; 18 | 19 | ReactDOM.render( 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | , 28 | document.getElementById('root') 29 | ); 30 | 31 | serviceWorker.unregister(); 32 | -------------------------------------------------------------------------------- /src/lib/emitter.js: -------------------------------------------------------------------------------- 1 | class Emitter { 2 | eventSubscibersMap = {}; 3 | 4 | emit(event, data) { 5 | try { 6 | const subscribers = this.eventSubscibersMap[event] || []; 7 | subscribers.forEach(cb => { 8 | try { 9 | cb(data); 10 | } catch (err) { 11 | console.warn('emit warning:', err); 12 | } 13 | }); 14 | } catch (err) { 15 | console.warn('emit exception:', err); 16 | } 17 | } 18 | 19 | on(event, cb) { 20 | if (!(event in this.eventSubscibersMap)) 21 | this.eventSubscibersMap[event] = []; 22 | if (this.eventSubscibersMap[event].indexOf(cb) === -1) 23 | this.eventSubscibersMap[event].push(cb); 24 | } 25 | } 26 | 27 | export default Emitter; 28 | -------------------------------------------------------------------------------- /src/pages/home/home.css: -------------------------------------------------------------------------------- 1 | .wrapper { 2 | color: #c5c5c5; 3 | min-height: 100%; 4 | 5 | .welcome-card { 6 | background: #151515; 7 | width: 70%; 8 | border: none; 9 | } 10 | 11 | .demo-image { 12 | width: 900px; 13 | box-shadow: 5px 6px 5px #0000002b; 14 | margin-bottom: 50px; 15 | } 16 | 17 | .btn { 18 | width: 250px; 19 | } 20 | } 21 | 22 | a { 23 | color: white; 24 | } 25 | 26 | a:hover { 27 | text-decoration: none; 28 | color: white; 29 | } -------------------------------------------------------------------------------- /src/pages/home/home.jsx: -------------------------------------------------------------------------------- 1 | /* eslint-disable react/jsx-one-expression-per-line */ 2 | import React from 'react'; 3 | import { Container, Row, Button, Card } from 'react-bootstrap'; 4 | import { MobileOnlyView } from 'react-device-detect'; 5 | import Dialog from 'react-bootstrap-dialog'; 6 | import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; 7 | import { faHeart } from '@fortawesome/free-solid-svg-icons'; 8 | import getRoomService from 'api/http/room-service'; 9 | import { toast } from 'react-toastify'; 10 | 11 | import DemoImage from 'assets/images/demo.png'; 12 | import 'bootstrap/dist/css/bootstrap.min.css'; 13 | import './home.css'; 14 | 15 | const Home = () => { 16 | const roomService = getRoomService(); 17 | let clicked = false; 18 | toast.info( 19 | `Hi! I'm currently hosting the backend for this site on Heroku and AWS free tiers so you might experience some failed requests and errors from time to time due to max connection limits. Sorry for being broke. (T▽T) Enjoy!`, 20 | { position: 'bottom-right', autoClose: false } 21 | ); 22 | return ( 23 | 24 | 25 | 26 | 27 | Welcome to CodeInterview! 28 | 29 | CodeInterview is a home made solution and personal 30 | self-learning project for online coding interviews by{' '} 31 | 36 | @areebbeigh 37 | 38 | . No sign-ups, just create a room and share the URL. 39 |
40 | You can also check it out on{' '} 41 | 46 | GitHub 47 | 48 | . 49 |
50 |
51 |
52 |
53 | 54 | demo 59 | 60 | 85 | 94 | 95 | 96 | { 98 | dialog.show({ 99 | body: `Hey. CodeInterview works best on desktops. Head on to your desktop browser. I'll wait :)`, 100 | actions: [Dialog.OKAction()], 101 | onHide: () => null, 102 | }); 103 | }} 104 | /> 105 | 106 |
107 | ); 108 | }; 109 | 110 | export default Home; 111 | -------------------------------------------------------------------------------- /src/pages/room/room.css: -------------------------------------------------------------------------------- 1 | @import 'themes/css/codesandbox-black.css'; 2 | 3 | .room-container { 4 | background-color: $primary-color; 5 | white-space: nowrap; 6 | } 7 | 8 | .editor-col { 9 | padding: 0 !important; 10 | } 11 | 12 | .code-editor { 13 | height: calc(100vh - $control-bar-height); 14 | } 15 | 16 | .input-editor, .output-terminal { 17 | height: calc(100vh - $control-bar-height); 18 | } 19 | 20 | .control-bar { 21 | height: $control-bar-height; 22 | 23 | .media-controls { 24 | display: inline; 25 | color: #ffffff9c; 26 | 27 | .icon { 28 | width: 25px; 29 | } 30 | } 31 | } 32 | 33 | -------------------------------------------------------------------------------- /src/pages/room/room.jsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import PropTypes from 'prop-types'; 3 | import { Container, Row, Col, Button } from 'react-bootstrap'; 4 | import Dialog from 'react-bootstrap-dialog'; 5 | import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; 6 | import { OverlayScrollbarsComponent } from 'overlayscrollbars-react'; 7 | import { toast } from 'react-toastify'; 8 | import { 9 | faCircle, 10 | faMicrophone, 11 | faVideo, 12 | faMicrophoneSlash, 13 | faVideoSlash, 14 | } from '@fortawesome/free-solid-svg-icons'; 15 | 16 | import ControlBar from 'components/control-bar/control-bar'; 17 | import SharedMonacoEditor from 'features/shared-monaco-editor/shared-monaco-editor'; 18 | import VideoChat from 'features/video-chat/video-chat'; 19 | import Terminal from 'features/terminal/terminal'; 20 | import roomService from 'api/http/room-service'; 21 | import roomSocket from 'api/ws/room-socket'; 22 | import colors from 'constants/colors'; 23 | import { setupSync } from '@/sync-manager'; 24 | 25 | import './room.css'; 26 | 27 | function isMicOn() { 28 | return window?.sync.streamData?.audio?.enabled; 29 | } 30 | 31 | function isCamOn() { 32 | return window?.sync.streamData?.video?.enabled; 33 | } 34 | 35 | function displayWelcomeToast(name) { 36 | toast.dark( 37 | `Welcome to CodeInterview, ${name}! Share this room's URL to let others join in.` 38 | ); 39 | } 40 | 41 | class Room extends React.Component { 42 | constructor(props) { 43 | super(props); 44 | this.handleCallBtn = this.handleCallBtn.bind(this); 45 | this.handleRunBtn = this.handleRunBtn.bind(this); 46 | this.sendMessage = this.sendMessage.bind(this); 47 | 48 | this.codeEditorRef = React.createRef(); 49 | this.inputEditorRef = React.createRef(); 50 | 51 | this.roomService = roomService(); 52 | this.state = { 53 | videoChat: false, 54 | roomId: null, 55 | username: null, 56 | syncSetup: false, 57 | profile: {}, 58 | profiles: [], 59 | logs: [{ content: 'Welcome to CodeInterview!' }], 60 | }; 61 | } 62 | 63 | async componentDidMount() { 64 | const { props } = this; 65 | const { roomId } = props.match.params; 66 | try { 67 | // confirm this room exists 68 | const room = await this.roomService.getRoom(roomId); 69 | this.setState({ 70 | roomId, 71 | alone: room.data.participants === 0, 72 | }); 73 | } catch (err) { 74 | toast.error( 75 | `Could not fetch room data. Are you sure this room exists? [${err.message}]`, 76 | { autoClose: false } 77 | ); 78 | } 79 | } 80 | 81 | componentDidUpdate() { 82 | const { username, roomId, profile, profiles } = this.state; 83 | // ask for username 84 | if (!username) { 85 | this.dialog.show({ 86 | body: `Let's get you a nickname.`, 87 | prompt: Dialog.TextPrompt({ 88 | placeholder: 'e.g Deku', 89 | initialValue: '', 90 | required: true, 91 | }), 92 | actions: [ 93 | Dialog.OKAction(dialog => { 94 | const username = dialog.value; 95 | const userProfile = { 96 | username, 97 | color: colors.userColors[0], 98 | }; 99 | this.setState({ 100 | username, 101 | profile: userProfile, 102 | profiles: [...profiles, userProfile], 103 | }); 104 | displayWelcomeToast(username); 105 | }), 106 | ], 107 | // prevents dialog from closing on clicking outside 108 | onHide: () => null, 109 | }); 110 | } 111 | // setup websocket and webrtc connections 112 | if (roomId && username && !window.sync) { 113 | // websocket 114 | this.roomSocket = roomSocket(roomId, username); 115 | this.bindSocketListeners(); 116 | // webrtc 117 | window.sync = setupSync(roomId); 118 | window.sync.setProfile(profile); 119 | this.bindConnListeners(); 120 | // eslint-disable-next-line react/no-did-update-set-state 121 | this.setState({ syncSetup: true }); 122 | } 123 | } 124 | 125 | // Button event handlers 126 | 127 | handleCallBtn() { 128 | const { videoChat } = this.state; 129 | this.setState({ 130 | videoChat: !videoChat, 131 | }); 132 | if (!videoChat) this.roomSocket.sendJoinCall(); 133 | else this.roomSocket.sendLeaveCall(); 134 | } 135 | 136 | handleRunBtn() { 137 | const { language } = this.codeEditorRef.state; 138 | const { code, input } = this.codeEditorRef.data; 139 | this.roomSocket.sendRun({ 140 | code: code.model.getValue(), 141 | language, 142 | stdin: input.model.getValue(), 143 | }); 144 | } 145 | 146 | // Room socket helpers 147 | 148 | sendMessage(msg) { 149 | this.roomSocket.sendMessage(msg); 150 | } 151 | 152 | bindSocketListeners() { 153 | this.roomSocket.on('logs', entries => { 154 | const { logs } = this.state; 155 | this.setState({ 156 | logs: [...logs, ...entries], 157 | }); 158 | }); 159 | this.roomSocket.on('new-entry', entry => { 160 | const { logs } = this.state; 161 | this.setState({ 162 | logs: [...logs, entry], 163 | }); 164 | }); 165 | this.roomSocket.on('error', data => { 166 | toast.error(`An internal error occured: ${data}`); 167 | }); 168 | } 169 | 170 | // WebRTC helpers 171 | 172 | bindConnListeners() { 173 | window.sync.on('profiles', profiles => { 174 | let i = 0; 175 | Object.values(profiles).forEach(peerProfile => { 176 | const color = colors.userColors[i % colors.userColors.length]; 177 | // eslint-disable-next-line no-param-reassign 178 | peerProfile.color = color; 179 | i += 1; 180 | }); 181 | this.setState({ 182 | profiles: Object.values(profiles), 183 | }); 184 | }); 185 | } 186 | 187 | render() { 188 | const { 189 | videoChat, 190 | roomId, 191 | username, 192 | syncSetup, 193 | logs, 194 | profiles, 195 | alone, 196 | } = this.state; 197 | // haven't confirmed room exists yet 198 | if (!roomId) return ''; 199 | 200 | // wait for user to input name 201 | if (!username) { 202 | return ( 203 | <> 204 | { 206 | this.dialog = el; 207 | }} 208 | /> 209 | 210 | ); 211 | } 212 | 213 | // wait for webrtc connection to setup 214 | if (!syncSetup) return ''; 215 | 216 | // actual IDE 217 | return ( 218 |
219 | {videoChat && } 220 | 221 | 222 | 223 | { 225 | this.codeEditorRef = ref; 226 | }} 227 | id="code-editor" 228 | name="Code editor" 229 | language="python" 230 | className="code-editor" 231 | showDropdown 232 | loadTemplate={alone} 233 | /> 234 | 235 | 236 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 257 | 258 | 259 | 269 | {profiles.map((profile, idx) => ( 270 |
275 | 281 | 282 | {profile.username} 283 | 284 |
285 | ))} 286 |
287 | 288 | 289 | {videoChat && ( 290 |
291 | { 300 | window.sync.toggleLocalAudio(); 301 | this.forceUpdate(); 302 | }} 303 | /> 304 | { 308 | window.sync.toggleLocalVideo(); 309 | this.forceUpdate(); 310 | }} 311 | /> 312 |
313 | )} 314 | 321 | 322 |
323 |
324 | 325 |
326 |
327 |
328 | ); 329 | } 330 | } 331 | 332 | Room.defaultProps = {}; 333 | Room.propTypes = { 334 | match: PropTypes.shape({ 335 | params: PropTypes.shape({ 336 | roomId: PropTypes.string, 337 | }), 338 | }).isRequired, 339 | }; 340 | 341 | export default Room; 342 | -------------------------------------------------------------------------------- /src/service-worker.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable no-param-reassign */ 2 | /* eslint-disable no-use-before-define */ 3 | // This optional code is used to register a service worker. 4 | // register() is not called by default. 5 | 6 | // This lets the app load faster on subsequent visits in production, and gives 7 | // it offline capabilities. However, it also means that developers (and users) 8 | // will only see deployed updates on subsequent visits to a page, after all the 9 | // existing tabs open on the page have been closed, since previously cached 10 | // resources are updated in the background. 11 | 12 | // To learn more about the benefits of this model and instructions on how to 13 | // opt-in, read https://bit.ly/CRA-PWA 14 | 15 | const isLocalhost = Boolean( 16 | window.location.hostname === 'localhost' || 17 | // [::1] is the IPv6 localhost address. 18 | window.location.hostname === '[::1]' || 19 | // 127.0.0.0/8 are considered localhost for IPv4. 20 | window.location.hostname.match( 21 | /^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/ 22 | ) 23 | ); 24 | 25 | export function register(config) { 26 | if ( 27 | process.env.NODE_ENV === 'production' && 28 | 'serviceWorker' in navigator 29 | ) { 30 | // The URL constructor is available in all browsers that support SW. 31 | const publicUrl = new URL( 32 | process.env.PUBLIC_URL, 33 | window.location.href 34 | ); 35 | if (publicUrl.origin !== window.location.origin) { 36 | // Our service worker won't work if PUBLIC_URL is on a different origin 37 | // from what our page is served on. This might happen if a CDN is used to 38 | // serve assets; see https://github.com/facebook/create-react-app/issues/2374 39 | return; 40 | } 41 | 42 | window.addEventListener('load', () => { 43 | const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`; 44 | 45 | if (isLocalhost) { 46 | // This is running on localhost. Let's check if a service worker still exists or not. 47 | checkValidServiceWorker(swUrl, config); 48 | 49 | // Add some additional logging to localhost, pointing developers to the 50 | // service worker/PWA documentation. 51 | navigator.serviceWorker.ready.then(() => { 52 | console.log( 53 | 'This web app is being served cache-first by a service ' + 54 | 'worker. To learn more, visit https://bit.ly/CRA-PWA' 55 | ); 56 | }); 57 | } else { 58 | // Is not localhost. Just register service worker 59 | registerValidSW(swUrl, config); 60 | } 61 | }); 62 | } 63 | } 64 | 65 | function registerValidSW(swUrl, config) { 66 | navigator.serviceWorker 67 | .register(swUrl) 68 | .then(registration => { 69 | registration.onupdatefound = () => { 70 | const installingWorker = registration.installing; 71 | if (installingWorker == null) { 72 | return; 73 | } 74 | installingWorker.onstatechange = () => { 75 | if (installingWorker.state === 'installed') { 76 | if (navigator.serviceWorker.controller) { 77 | // At this point, the updated precached content has been fetched, 78 | // but the previous service worker will still serve the older 79 | // content until all client tabs are closed. 80 | console.log( 81 | 'New content is available and will be used when all ' + 82 | 'tabs for this page are closed. See https://bit.ly/CRA-PWA.' 83 | ); 84 | 85 | // Execute callback 86 | if (config && config.onUpdate) { 87 | config.onUpdate(registration); 88 | } 89 | } else { 90 | // At this point, everything has been precached. 91 | // It's the perfect time to display a 92 | // "Content is cached for offline use." message. 93 | console.log('Content is cached for offline use.'); 94 | 95 | // Execute callback 96 | if (config && config.onSuccess) { 97 | config.onSuccess(registration); 98 | } 99 | } 100 | } 101 | }; 102 | }; 103 | }) 104 | .catch(error => { 105 | console.error( 106 | 'Error during service worker registration:', 107 | error 108 | ); 109 | }); 110 | } 111 | 112 | function checkValidServiceWorker(swUrl, config) { 113 | // Check if the service worker can be found. If it can't reload the page. 114 | fetch(swUrl, { 115 | headers: { 'Service-Worker': 'script' }, 116 | }) 117 | .then(response => { 118 | // Ensure service worker exists, and that we really are getting a JS file. 119 | const contentType = response.headers.get('content-type'); 120 | if ( 121 | response.status === 404 || 122 | (contentType != null && 123 | contentType.indexOf('javascript') === -1) 124 | ) { 125 | // No service worker found. Probably a different app. Reload the page. 126 | navigator.serviceWorker.ready.then(registration => { 127 | registration.unregister().then(() => { 128 | window.location.reload(); 129 | }); 130 | }); 131 | } else { 132 | // Service worker found. Proceed as normal. 133 | registerValidSW(swUrl, config); 134 | } 135 | }) 136 | .catch(() => { 137 | console.log( 138 | 'No internet connection found. App is running in offline mode.' 139 | ); 140 | }); 141 | } 142 | 143 | export function unregister() { 144 | if ('serviceWorker' in navigator) { 145 | navigator.serviceWorker.ready.then(registration => { 146 | registration.unregister(); 147 | }); 148 | } 149 | } 150 | -------------------------------------------------------------------------------- /src/sync-manager.js: -------------------------------------------------------------------------------- 1 | import { WebrtcProvider } from 'y-webrtc'; 2 | import * as Y from 'yjs'; 3 | 4 | import Emitter from 'lib/emitter'; 5 | 6 | class SyncManager extends Emitter { 7 | streams = {}; 8 | 9 | profiles = {}; 10 | 11 | constructor(roomId) { 12 | super(); 13 | this.doc = new Y.Doc(); 14 | const webrtcProvider = new WebrtcProvider( 15 | `codeinterview-${roomId}`, 16 | this.doc, 17 | { 18 | // don't use broadcast connections between browser windows. 19 | // https://github.com/yjs/y-webrtc/issues/10 20 | filterBcConns: false, 21 | maxConns: Number.POSITIVE_INFINITY, 22 | } 23 | ); 24 | this.webrtcProvider = webrtcProvider; 25 | 26 | webrtcProvider.on('peers', info => { 27 | console.log(info); 28 | const added = Array.from(info.added); 29 | const removed = Array.from(info.removed); 30 | 31 | removed.forEach(peerId => { 32 | delete this.profiles[peerId]; 33 | this.emit('profiles', this.profiles); 34 | delete this.streams[peerId]; 35 | }); 36 | 37 | added.forEach(peerId => { 38 | const peerConn = this.getPeerById(peerId); 39 | if (peerConn) { 40 | // exchange user profile data 41 | peerConn.peer.on('data', data => { 42 | let dataJson = null; 43 | try { 44 | dataJson = JSON.parse(data.toString()); 45 | } catch (err) { 46 | return; 47 | } 48 | const { type, profileData } = dataJson; 49 | if (type === 'profile-data') { 50 | this.profiles[peerId] = { 51 | ...profileData, 52 | peerId, 53 | }; 54 | this.emit('profiles', this.profiles); 55 | } 56 | }); 57 | // send newly connected peer our profile 58 | peerConn.peer.on('connect', () => { 59 | peerConn.peer.send( 60 | JSON.stringify({ 61 | type: 'profile-data', 62 | profileData: this.profile, 63 | }) 64 | ); 65 | }); 66 | // exchange stream data 67 | if (this.stream) { 68 | peerConn.peer.addStream(this.stream); 69 | } 70 | // receive peer streams 71 | peerConn.peer.on('stream', stream => { 72 | console.log('got peer stream', peerId, stream); 73 | this.streams[peerId] = stream; 74 | this.emit('stream', { peerId, stream }); 75 | }); 76 | } else { 77 | console.warn( 78 | 'Peer added but cannot find connection object', 79 | peerId, 80 | info 81 | ); 82 | } 83 | }); 84 | 85 | this.checkPeerId(); 86 | this.emit('peers'); 87 | }); 88 | 89 | webrtcProvider.on('synced', info => { 90 | console.log('synced', info); 91 | this.checkPeerId(); 92 | this.emit('ready', { peerId: this.peerId }); 93 | }); 94 | } 95 | 96 | checkPeerId() { 97 | if (!this.peerId) { 98 | this.peerId = this.webrtcProvider.room.peerId; 99 | if (this.peerId) { 100 | this.emit('peerId', this.peerId); 101 | } 102 | } 103 | } 104 | 105 | getWebrtcConns() { 106 | return this.webrtcProvider?.room?.webrtcConns; 107 | } 108 | 109 | getPeers() { 110 | return Array.from(this.getWebrtcConns()?.values() || []); 111 | } 112 | 113 | getPeerById(id) { 114 | return this.getWebrtcConns()?.get(id) || null; 115 | } 116 | 117 | getPeerIds() { 118 | try { 119 | return Array.from(this.getWebrtcConns()?.keys() || []); 120 | } catch (err) { 121 | console.warn('getPeerList error:', err); 122 | } 123 | return []; 124 | } 125 | 126 | getStream(peerId) { 127 | try { 128 | return this.streams[peerId]; 129 | } catch (err) { 130 | console.warn('getStream error:', err); 131 | } 132 | return null; 133 | } 134 | 135 | getUserMedia() { 136 | return new Promise((resolve, reject) => { 137 | const options = { 138 | audio: true, 139 | video: { 140 | facingMode: 'user', 141 | video: { 142 | width: { ideal: 640 }, 143 | height: { ideal: 360 }, 144 | }, 145 | width: { ideal: 640 }, 146 | height: { ideal: 360 }, 147 | frameRate: { 148 | min: 1, 149 | ideal: 15, 150 | }, 151 | }, 152 | }; 153 | try { 154 | navigator.mediaDevices 155 | .getUserMedia(options) 156 | .then(resolve) 157 | .catch(reject); 158 | } catch (err) { 159 | reject(err); 160 | } 161 | }).then(stream => { 162 | this.setStream(stream); 163 | return stream; 164 | }); 165 | } 166 | 167 | releaseUserMedia() { 168 | this.stream.getTracks().map(track => track.stop()); 169 | this.stream = null; 170 | } 171 | 172 | toggleLocalAudio() { 173 | const { audio } = this.streamData; 174 | audio.enabled = !audio.enabled; 175 | } 176 | 177 | toggleLocalVideo() { 178 | const { video } = this.streamData; 179 | video.enabled = !video.enabled; 180 | } 181 | 182 | setStream(stream) { 183 | this.stream = stream; 184 | this.streamData = { 185 | audio: stream.getAudioTracks()[0], 186 | video: stream.getVideoTracks()[0], 187 | }; 188 | const peerConns = this.getPeers(); 189 | peerConns.forEach(conn => { 190 | conn.peer.addStream(stream); 191 | }); 192 | } 193 | 194 | setProfile(profile) { 195 | this.profile = profile; 196 | this.on('peerId', peerId => { 197 | this.profiles[peerId] = profile; 198 | }); 199 | const peerConns = this.getPeers(); 200 | peerConns.forEach(conn => { 201 | conn.peer.send( 202 | JSON.stringify({ 203 | type: 'profile-data', 204 | profile, 205 | }) 206 | ); 207 | }); 208 | this.emit('profiles', this.profiles); 209 | } 210 | } 211 | 212 | export function setupSync(roomId) { 213 | return new SyncManager(roomId); 214 | } 215 | 216 | export default SyncManager; 217 | -------------------------------------------------------------------------------- /src/themes/css/codesandbox-black.css: -------------------------------------------------------------------------------- 1 | $primary-color: #151515; 2 | $secondary-color: #0971F1; 3 | 4 | /* .btn { 5 | background: $secondary-color; 6 | } */ -------------------------------------------------------------------------------- /src/themes/monaco-themes/codesandbox-black.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable no-dupe-keys */ 2 | // https://github.com/codesandbox/codesandbox-client/tree/ce4d1a0bb049c592ce2e9b5011b290899f856acd/packages/common/src/themes 3 | module.exports = { 4 | base: 'vs-dark', 5 | type: 'dark', 6 | inherit: true, 7 | rules: [], 8 | colors: { 9 | 'activityBar.background': '#151515', 10 | 'activityBar.border': '#242424', 11 | 'button.background': '#0971F1', 12 | 'button.foreground': '#fff', 13 | 'button.border': '#0971F1', 14 | 'button.hoverBackground': '#0971F1', 15 | 16 | 'dropdown.background': '#151515', 17 | 'dropdown.border': '#242424', 18 | 'dropdown.foreground': '#fff', 19 | 'terminal.background': '#040404', 20 | 'terminal.foreground': '#fff', 21 | 'terminal.ansiBrightBlack': '#535BCF', 22 | 'terminal.ansiBrightRed': '#E1270E', 23 | 'terminal.ansiBrightGreen': '#5BC266', 24 | 'terminal.ansiBrightYellow': '#FBCC43', 25 | 'terminal.ansiBlack': '#21222C', 26 | 'terminal.ansiRed': '#E1270E', 27 | 'terminal.ansiGreen': '#5BC266', 28 | 'terminal.ansiYellow': '#FBCC43', 29 | 'terminal.ansiBlue': '#535BCF', 30 | 'terminal.ansiMagenta': '#BF5AF2', 31 | 'terminal.ansiCyan': '#6CC7F6', 32 | 'terminal.ansiWhite': '#fff', 33 | 34 | contrastBorder: '#242424', 35 | 36 | 'selection.background': '#535BCF', 37 | errorForeground: '#E1270E', 38 | 'input.background': '#242424', 39 | 'input.foreground': '#fff', 40 | 'input.border': '#040404', 41 | 42 | 'input.placeholderForeground': '#999', 43 | 'inputOption.activeBorder': '#6CC7F6', 44 | 'inputValidation.infoBorder': '#BF5AF2', 45 | 'inputValidation.warningBorder': '#FBCC43', 46 | 'inputValidation.errorBorder': '#E1270E', 47 | 'tab.activeBackground': '#282A36', 48 | 'tab.activeForeground': '#F8F8F2', 49 | 'editor.background': '#151515', 50 | 'editor.foreground': '#ffffff', 51 | 'editor.hoverHighlightBackground': '#333', 52 | 'editor.inactiveSelectionBackground': '#333', 53 | 54 | 'editorLineNumber.foreground': '#242424', 55 | 'editorGroup.background': '#151515', 56 | 'editorGroup.border': '#242424', 57 | 'editorGroup.dropBackground': '#151515', 58 | 'editorGroupHeader.tabsBackground': '#151515', 59 | 60 | 'editor.lineHighlightBackground': '#242424', 61 | 'editor.lineHighlightBorder': '#242424', 62 | 'editor.rangeHighlightBackground': '#222', 63 | 64 | 'editor.selectionBackground': '#242424', 65 | 66 | 'editor.selectionHighlightBackground': '#242424', 67 | 68 | 'editor.wordHighlightStrongBackground': '#242424', 69 | 70 | 'editor.wordHighlightBackground': '#242424', 71 | 'editorBracketMatch.background': '#242424', 72 | 'editorBracketMatch.border': '#242424', 73 | 'editorCodeLens.foreground': '#242424', 74 | 'editorCursor.background': '#151515', 75 | 'editorCursor.foreground': '#fff', 76 | 'editorError.border': '#242424', 77 | 'editorError.foreground': '#E1270E', 78 | 79 | 'editorGutter.background': '#151515', 80 | 'editorGutter.deletedBackground': '#E1270E', 81 | 'editorGutter.modifiedBackground': '#151515', 82 | 83 | 'editorGroup.background': '#151515', 84 | 'editorGroup.border': '#242424', 85 | 'editorGroup.dropBackground': '#151515', 86 | 87 | 'editorGroupHeader.tabsBackground': '#151515', 88 | 'editorGroupHeader.tabsBorder': '#242424', 89 | 90 | 'editorHoverWidget.background': '#151515', 91 | 'editorHoverWidget.border': '#242424', 92 | 'editorIndentGuide.background': '#151515', 93 | 'editorLineNumber.foreground': '#242424', 94 | 'editorLineNumber.activeForeground': '#757575', 95 | 'editorLink.activeForeground': '#999', 96 | 97 | 'editorMarkerNavigation.background': '#151515', 98 | 'editorMarkerNavigationError.background': '#151515', 99 | 'editorMarkerNavigationWarning.background': '#242424', 100 | 101 | 'editorOverviewRuler.border': '#242424', 102 | 'editorOverviewRuler.commonContentForeground': '#242424', 103 | 'editorOverviewRuler.currentContentForeground': '#E1270E', 104 | 'editorOverviewRuler.incomingContentForeground': '#5BC266', 105 | 'editorRuler.foreground': '#fff', 106 | 107 | 'editorSuggestWidget.background': '#151515', 108 | 'editorSuggestWidget.border': '#242424', 109 | 'editorSuggestWidget.foreground': '#999', 110 | 'editorSuggestWidget.selectedBackground': '#242424', 111 | 112 | 'editorWarning.border': '#242424', 113 | 'editorWarning.foreground': '#F35644', 114 | 'editorWhitespace.foreground': '#444', 115 | 'editorWidget.background': '#111', 116 | 'editorWidget.border': '#2d2d2d', 117 | errorForeground: '#e27e8d', 118 | 119 | 'extensionButton.prominentBackground': '#242424', 120 | 'extensionButton.prominentForeground': '#fff', 121 | 'extensionButton.prominentHoverBackground': '#242424', 122 | focusBorder: '#242424', 123 | foreground: '#999', 124 | 'peekView.border': '#353535', 125 | 'peekViewEditor.background': '#242424', 126 | 'peekViewEditor.matchHighlightBackground': '#76D0FB', 127 | 'peekViewResult.background': '#242424', 128 | 'peekViewResult.fileForeground': '#fff', 129 | 'peekViewResult.lineForeground': '#fff', 130 | 'peekViewResult.matchHighlightBackground': '#76D0FB', 131 | 'peekViewResult.selectionBackground': '#242424', 132 | 'peekViewResult.selectionForeground': '#fff', 133 | 'peekViewTitle.background': '#242424', 134 | 'peekViewTitleDescription.foreground': '#535BCF', 135 | 'peekViewTitleLabel.foreground': '#fff', 136 | 137 | 'tab.activeBackground': '#151515', 138 | 'tab.activeForeground': '#fff', 139 | 'tab.border': '#242424', 140 | 'tab.activeBorder': '#6CC7F6', 141 | 'tab.inactiveBackground': '#151515', 142 | 'tab.inactiveForeground': '#757575', 143 | 'tab.unfocusedActiveForeground': '#ffffff', 144 | 'tab.unfocusedInactiveForeground': '#757575', 145 | 'activityBarBadge.background': '#E1270E', 146 | 'sideBarTitle.foreground': '#ffffff', 147 | 148 | 'scrollbarSlider.activeBackground': '#fff', 149 | 'scrollbarSlider.border': '#242424', 150 | 'sideBar.background': '#151515', 151 | 'sideBar.border': '#242424', 152 | 'sideBar.foreground': '#ffffff', 153 | 'sideBarSectionHeader.background': '#151515', 154 | 'sideBarSectionHeader.foreground': '#ffffff', 155 | 'sideBarSectionHeader.border': '#242424', 156 | 'sideBar.hoverBackground': '#00ff00', 157 | 158 | 'statusBar.background': '#242424', 159 | 'statusBar.foreground': '#ffffff', 160 | 'statusBar.debuggingBackground': '#E1270E', 161 | 'statusBar.debuggingForeground': '#242424', 162 | 'statusBar.noFolderBackground': '#242424', 163 | 'statusBar.noFolderForeground': '#F8F8F2', 164 | 'statusBarItem.prominentBackground': '#E1270E', 165 | 'statusBarItem.prominentBackground': '#E1270E', 166 | 'statusBarItem.prominentHoverBackground': '#FFB86C', 167 | 'statusBarItem.remoteForeground': '#e6e6e6', 168 | 'statusBarItem.remoteBackground': '#BF5AF2', 169 | 'statusBar.border': '#242424', 170 | 'titleBar.background': '#151515', 171 | 'titleBar.activeBackground': '#151515', 172 | 'titleBar.activeForeground': '#fff', 173 | 'titleBar.border': '#242424', 174 | 'titleBar.inactiveBackground': '#151515', 175 | 'titleBar.inactiveForeground': '#999', 176 | 177 | 'menu.background': '#151515', 178 | 'menu.selectionBackground': '#242424', 179 | 'list.activeSelectionBackground': '#151515', 180 | 'list.activeSelectionForeground': '#fff', 181 | 'list.dropBackground': '#151515', 182 | 'list.focusBackground': '#151515', 183 | 'list.highlightForeground': '#6CC7F6', 184 | 'list.hoverBackground': '#242424', 185 | 'list.warningForeground': '#FBCC43', 186 | 'list.errorForeground': '#E1270E', 187 | }, 188 | }; 189 | -------------------------------------------------------------------------------- /src/themes/monaco-themes/index.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable global-require */ 2 | module.exports = { 3 | 'codesandbox-black': require('./codesandbox-black'), 4 | }; 5 | -------------------------------------------------------------------------------- /src/themes/variables/common.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | 'control-bar-height': '50px', 3 | 'titlebar-height': '50px', 4 | }; 5 | -------------------------------------------------------------------------------- /src/themes/variables/themes.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable prefer-object-spread */ 2 | /* eslint-disable prefer-destructuring */ 3 | const themes = require('../monaco-themes'); 4 | 5 | module.exports = { 6 | 'vs-dark': { 7 | 'primary-color': '#000000', 8 | 'secondary-color': '#000000', 9 | }, 10 | }; 11 | 12 | Object.keys(themes).forEach(themeName => { 13 | const type = themes[themeName].type; 14 | const secondaryColor = type === 'light' ? '#403f53' : '#159497'; 15 | const themeDefinition = { 16 | 'primary-color': 17 | themes[themeName].colors['editorGroup.background'], 18 | 'secondary-color': 19 | themes[themeName].colors['buttin.background'] || secondaryColor, 20 | }; 21 | module.exports[themeName] = Object.assign( 22 | {}, 23 | themeDefinition, 24 | themeName in exports ? exports[themeName] : {} 25 | ); 26 | }); 27 | --------------------------------------------------------------------------------