├── .babelrc ├── .editorconfig ├── .eslintrc ├── .gitignore ├── .yo-rc.json ├── LICENSE ├── README.md ├── cfg ├── base.js ├── dev.js ├── dist.js └── test.js ├── chrome ├── background.js ├── icon-128.png ├── icon-16.png └── manifest.json ├── index.html ├── karma.conf.js ├── main.js ├── package.json ├── server.js ├── src ├── actions │ ├── ActionsFunction.js │ └── ActionsType.js ├── components │ ├── Column.js │ ├── HistoryList.js │ ├── Main.js │ ├── Row.js │ ├── SocketPlayground.js │ ├── SocketPlaygroundBar.js │ ├── SocketSetting.js │ ├── SocketTerminal.js │ ├── SocketTerminalList.js │ └── TerminalListItem.js ├── config │ ├── README.md │ ├── base.js │ ├── dev.js │ ├── dist.js │ └── test.js ├── constant │ └── Constants.js ├── containers │ ├── HistoryList.js │ ├── SocketPlayground.js │ ├── SocketSetting.js │ ├── SocketTerminal.js │ └── SocketTerminalList.js ├── favicon.ico ├── helpers │ ├── GlobalHelpers.js │ ├── SocketIOConnection.js │ ├── StorageHelper.js │ ├── StorageProxy.js │ ├── WebSocketConnection.js │ └── WebSocketErrorMessages.js ├── images │ └── yeoman.png ├── index.html ├── index.js ├── reducers │ ├── RootReducer.js │ └── SocketContainerReducer.js ├── stores │ ├── AppStore.js │ └── README.md └── styles │ └── App.scss ├── test ├── actions │ └── .keep ├── components │ └── MainTest.js ├── config │ └── ConfigTest.js ├── helpers │ └── shallowRenderHelper.js ├── loadtests.js ├── sources │ └── .keep └── stores │ └── .keep └── webpack.config.js /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | "es2015", 4 | "react" 5 | ] 6 | } 7 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = space 5 | indent_size = 2 6 | end_of_line = lf 7 | charset = utf-8 8 | trim_trailing_whitespace = true 9 | insert_final_newline = true 10 | 11 | [*.md] 12 | trim_trailing_whitespace = false 13 | -------------------------------------------------------------------------------- /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "parser": "babel-eslint", 3 | "extends": "airbnb", 4 | "env": { 5 | "browser": true, 6 | }, 7 | "rules": { 8 | "react/forbid-prop-types": 0, 9 | "react/jsx-filename-extension": [1, { "extensions": [".js", ".jsx"] }], 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | 5 | # Runtime data 6 | pids 7 | *.pid 8 | *.seed 9 | 10 | # Directory for instrumented libs generated by jscoverage/JSCover 11 | lib-cov 12 | 13 | # Coverage directory used by tools like istanbul 14 | coverage 15 | 16 | #WebStorm config files 17 | .idea 18 | 19 | # Dist 20 | dist 21 | 22 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 23 | .grunt 24 | 25 | # node-waf configuration 26 | .lock-wscript 27 | 28 | # Compiled binary addons (http://nodejs.org/api/addons.html) 29 | build/Release 30 | 31 | # Dependency directory 32 | # https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git 33 | node_modules 34 | 35 | # Bower 36 | bower_components/ 37 | -------------------------------------------------------------------------------- /.yo-rc.json: -------------------------------------------------------------------------------- 1 | { 2 | "generator-react-webpack": { 3 | "appName": "reactWebpack", 4 | "style": "sass", 5 | "postcss": true 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 | # chrome-app-websocket-tester 2 | Chrome App for WebSocket testing created by the WebSocket API and the Socket.IO API. 3 | 4 | ## Chrome Store App 5 | [Chrome Store Link](https://chrome.google.com/webstore/detail/websocket-tester/cbacdiognkmjbknpgomnfcopaekfhnbb) 6 | 7 | [![icon](/chrome/icon-128.png)](https://chrome.google.com/webstore/detail/websocket-tester/cbacdiognkmjbknpgomnfcopaekfhnbb) 8 | 9 | ## Quick Start 10 | 11 | Download project or fork: 12 | 13 | ```sh 14 | cd chrome-app-websocket-tester 15 | npm install 16 | npm start 17 | ``` 18 | 19 | ## Features 20 | 21 | * ES6 22 | * React 23 | * Redux 24 | * Immutable JS 25 | * Websocket API 26 | * Socket.IO 27 | * Material UI 28 | * Flexbox Grid 29 | 30 | 31 | ## Support 32 | 33 | Please [open an issue](https://github.com/williamcabrera4/chrome-app-websocket-tester/issues/new) for support. 34 | 35 | ## Contributing 36 | 37 | Please contribute using [Github Flow](https://guides.github.com/introduction/flow/). Create a branch, add commits, and [open a pull request](https://github.com/williamcabrera4/chrome-app-websocket-tester/pulls). 38 | -------------------------------------------------------------------------------- /cfg/base.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | let path = require('path'); 3 | let port = 8000; 4 | let srcPath = path.join(__dirname, '/../src'); 5 | let publicPath = '/assets/'; 6 | let additionalPaths = []; 7 | module.exports = { 8 | additionalPaths: additionalPaths, 9 | port: port, 10 | debug: true, 11 | output: { 12 | path: path.join(__dirname, '/../dist/assets'), 13 | filename: 'app.js', 14 | publicPath: publicPath 15 | }, 16 | devServer: { 17 | contentBase: './src/', 18 | historyApiFallback: true, 19 | hot: true, 20 | port: port, 21 | publicPath: publicPath, 22 | noInfo: false 23 | }, 24 | resolve: { 25 | extensions: [ 26 | '', 27 | '.js', 28 | '.jsx' 29 | ], 30 | alias: { 31 | actions: srcPath + '/actions/', 32 | components: srcPath + '/components/', 33 | sources: srcPath + '/sources/', 34 | stores: srcPath + '/stores/', 35 | styles: srcPath + '/styles/', 36 | config: srcPath + '/config/' + process.env.REACT_WEBPACK_ENV 37 | } 38 | }, 39 | module: { 40 | preLoaders: [{ 41 | test: /\.(js|jsx)$/, 42 | include: srcPath, 43 | loader: 'eslint-loader' 44 | }], 45 | loaders: [ 46 | { 47 | test: /\.css$/, 48 | loader: 'style-loader!css-loader!postcss-loader' 49 | }, 50 | { 51 | test: /\.sass/, 52 | loader: 'style-loader!css-loader!postcss-loader!sass-loader?outputStyle=expanded&indentedSyntax' 53 | }, 54 | { 55 | test: /\.scss/, 56 | loader: 'style-loader!css-loader!postcss-loader!sass-loader?outputStyle=expanded' 57 | }, 58 | { 59 | test: /\.less/, 60 | loader: 'style-loader!css-loader!postcss-loader!less-loader' 61 | }, 62 | { 63 | test: /\.styl/, 64 | loader: 'style-loader!css-loader!postcss-loader!stylus-loader' 65 | }, 66 | { 67 | test: /\.(png|jpg|gif|woff|woff2)$/, 68 | loader: 'url-loader?limit=8192' 69 | } 70 | ] 71 | }, 72 | postcss: function () { 73 | return []; 74 | } 75 | }; -------------------------------------------------------------------------------- /cfg/dev.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | let path = require('path'); 4 | let webpack = require('webpack'); 5 | let _ = require('lodash'); 6 | 7 | let baseConfig = require('./base'); 8 | 9 | // Add needed plugins here 10 | let BowerWebpackPlugin = require('bower-webpack-plugin'); 11 | 12 | let config = _.merge({ 13 | entry: [ 14 | 'webpack-dev-server/client?http://127.0.0.1:8000', 15 | 'webpack/hot/only-dev-server', 16 | './src/index' 17 | ], 18 | cache: true, 19 | devtool: 'eval', 20 | plugins: [ 21 | new webpack.HotModuleReplacementPlugin(), 22 | new webpack.NoErrorsPlugin(), 23 | new BowerWebpackPlugin({ 24 | searchResolveModulesDirectories: false 25 | }) 26 | ] 27 | }, baseConfig); 28 | 29 | // Add needed loaders 30 | config.module.loaders.push({ 31 | test: /\.(js|jsx)$/, 32 | loader: 'babel-loader', 33 | include: [].concat( 34 | config.additionalPaths, 35 | [ path.join(__dirname, '/../src') ] 36 | ) 37 | }); 38 | 39 | module.exports = config; 40 | -------------------------------------------------------------------------------- /cfg/dist.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | let path = require('path'); 4 | let webpack = require('webpack'); 5 | let _ = require('lodash'); 6 | 7 | let baseConfig = require('./base'); 8 | 9 | // Add needed plugins here 10 | let BowerWebpackPlugin = require('bower-webpack-plugin'); 11 | 12 | let config = _.merge({ 13 | entry: path.join(__dirname, '../src/index'), 14 | cache: false, 15 | devtool: 'sourcemap', 16 | plugins: [ 17 | new webpack.optimize.DedupePlugin(), 18 | new webpack.DefinePlugin({ 19 | 'process.env.NODE_ENV': '"production"' 20 | }), 21 | new BowerWebpackPlugin({ 22 | searchResolveModulesDirectories: false 23 | }), 24 | new webpack.optimize.UglifyJsPlugin(), 25 | new webpack.optimize.OccurenceOrderPlugin(), 26 | new webpack.optimize.AggressiveMergingPlugin(), 27 | new webpack.NoErrorsPlugin() 28 | ] 29 | }, baseConfig); 30 | 31 | config.module.loaders.push({ 32 | test: /\.(js|jsx)$/, 33 | loader: 'babel', 34 | include: [].concat( 35 | config.additionalPaths, 36 | [ path.join(__dirname, '/../src') ] 37 | ) 38 | }); 39 | 40 | module.exports = config; 41 | -------------------------------------------------------------------------------- /cfg/test.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | let path = require('path'); 4 | let srcPath = path.join(__dirname, '/../src/'); 5 | 6 | let baseConfig = require('./base'); 7 | 8 | // Add needed plugins here 9 | let BowerWebpackPlugin = require('bower-webpack-plugin'); 10 | 11 | module.exports = { 12 | devtool: 'eval', 13 | module: { 14 | preLoaders: [ 15 | { 16 | test: /\.(js|jsx)$/, 17 | loader: 'isparta-instrumenter-loader', 18 | include: [ 19 | path.join(__dirname, '/../src') 20 | ] 21 | } 22 | ], 23 | loaders: [ 24 | { 25 | test: /\.(png|jpg|gif|woff|woff2|css|sass|scss|less|styl)$/, 26 | loader: 'null-loader' 27 | }, 28 | { 29 | test: /\.(js|jsx)$/, 30 | loader: 'babel-loader', 31 | include: [].concat( 32 | baseConfig.additionalPaths, 33 | [ 34 | path.join(__dirname, '/../src'), 35 | path.join(__dirname, '/../test') 36 | ] 37 | ) 38 | } 39 | ] 40 | }, 41 | resolve: { 42 | extensions: [ '', '.js', '.jsx' ], 43 | alias: { 44 | actions: srcPath + 'actions/', 45 | helpers: path.join(__dirname, '/../test/helpers'), 46 | components: srcPath + 'components/', 47 | sources: srcPath + 'sources/', 48 | stores: srcPath + 'stores/', 49 | styles: srcPath + 'styles/', 50 | config: srcPath + 'config/' + process.env.REACT_WEBPACK_ENV 51 | } 52 | }, 53 | plugins: [ 54 | new BowerWebpackPlugin({ 55 | searchResolveModulesDirectories: false 56 | }) 57 | ] 58 | }; 59 | -------------------------------------------------------------------------------- /chrome/background.js: -------------------------------------------------------------------------------- 1 | chrome.app.runtime.onLaunched.addListener(function () { 2 | chrome.app.window.create('./index.html', { 3 | 'outerBounds': { 4 | 'minWidth': 900, 5 | 'minHeight': 670 6 | } 7 | }); 8 | }); -------------------------------------------------------------------------------- /chrome/icon-128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/williamcabrera4/chrome-app-websocket-tester/ef678d5c73dca8be0905dc35354085e70502172c/chrome/icon-128.png -------------------------------------------------------------------------------- /chrome/icon-16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/williamcabrera4/chrome-app-websocket-tester/ef678d5c73dca8be0905dc35354085e70502172c/chrome/icon-16.png -------------------------------------------------------------------------------- /chrome/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "WebSocket Tester", 3 | "description": "Test WebSocket created by the WebSocket API and the Socket.IO API.", 4 | "version": "0.0.1", 5 | "manifest_version": 2, 6 | "offline_enabled": true, 7 | "app": { 8 | "background": { 9 | "scripts": ["background.js"] 10 | } 11 | }, 12 | "permissions": [ 13 | "storage" 14 | ], 15 | "icons": { "16": "icon-16.png", "128": "icon-128.png" } 16 | } -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | Hola Mundo 2 | -------------------------------------------------------------------------------- /karma.conf.js: -------------------------------------------------------------------------------- 1 | var webpackCfg = require('./webpack.config'); 2 | 3 | module.exports = function(config) { 4 | config.set({ 5 | basePath: '', 6 | browsers: [ 'PhantomJS' ], 7 | files: [ 8 | 'test/loadtests.js' 9 | ], 10 | port: 8080, 11 | captureTimeout: 60000, 12 | frameworks: [ 'phantomjs-shim', 'mocha', 'chai' ], 13 | client: { 14 | mocha: {} 15 | }, 16 | singleRun: true, 17 | reporters: [ 'mocha', 'coverage' ], 18 | preprocessors: { 19 | 'test/loadtests.js': [ 'webpack', 'sourcemap' ] 20 | }, 21 | webpack: webpackCfg, 22 | webpackServer: { 23 | noInfo: true 24 | }, 25 | coverageReporter: { 26 | dir: 'coverage/', 27 | reporters: [ 28 | { type: 'html' }, 29 | { type: 'text' } 30 | ] 31 | } 32 | }); 33 | }; 34 | -------------------------------------------------------------------------------- /main.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const { app, BrowserWindow } = require('electron'); 4 | const path = require('path'); 5 | 6 | let mainWindow = null; 7 | 8 | app.on('ready', () => { 9 | mainWindow = new BrowserWindow({ 10 | show: false, 11 | frame: true, 12 | width: 900, 13 | height: 670, 14 | minWidth: 900, 15 | minHeight: 670, 16 | }); 17 | 18 | mainWindow.loadURL(path.join('file://', __dirname , 'dist/index.html')); 19 | mainWindow.on('ready-to-show', () => { 20 | mainWindow.show(); 21 | }); 22 | }); 23 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Websocket-Tester", 3 | "version": "0.0.1", 4 | "description": "Test WebSocket created by the WebSocket API and the Socket.IO API.", 5 | "main": "main.js", 6 | "scripts": { 7 | "clean": "rimraf dist/*", 8 | "copy": "copyfiles -f ./src/index.html ./src/favicon.ico ./dist", 9 | "dist": "npm run copy & webpack --env=dist", 10 | "lint": "eslint ./src", 11 | "posttest": "npm run lint", 12 | "release:major": "npm version major && npm publish && git push --follow-tags", 13 | "release:minor": "npm version minor && npm publish && git push --follow-tags", 14 | "release:patch": "npm version patch && npm publish && git push --follow-tags", 15 | "serve": "node server.js --env=dev", 16 | "serve:dist": "node server.js --env=dist", 17 | "start": "node server.js --env=dev", 18 | "electron": "electron .", 19 | "test": "karma start", 20 | "test:watch": "karma start --autoWatch=true --singleRun=false" 21 | }, 22 | "repository": "https://github.com/williamcabrera4/chrome-app-websocket-tester", 23 | "keywords": [ 24 | "websocket", 25 | "test", 26 | "react", 27 | "redux", 28 | "socket.io" 29 | ], 30 | "author": "William Marcel Cabrera Santana", 31 | "dependencies": { 32 | "classnames": "^2.2.3", 33 | "core-js": "^2.0.0", 34 | "electron": "^1.6.11", 35 | "flexboxgrid": "^6.3.0", 36 | "immutable": "^3.7.6", 37 | "material-ui": "0.19.4", 38 | "normalize.css": "^3.0.3", 39 | "prop-types": "^15.6.0", 40 | "react": "^16.0.0", 41 | "react-dom": "^16.0.0", 42 | "react-flexbox-grid": "^1.1.5", 43 | "react-redux": "^4.4.0", 44 | "react-tap-event-plugin": "^3.0.2", 45 | "redux": "^3.3.1", 46 | "socket.io-client": "^1.4.5" 47 | }, 48 | "devDependencies": { 49 | "babel-core": "^6.0.0", 50 | "babel-eslint": "^8.0.1", 51 | "babel-loader": "^6.0.0", 52 | "babel-polyfill": "6.6.1", 53 | "babel-preset-es2015": "^6.0.15", 54 | "babel-preset-react": "^6.0.15", 55 | "bower-webpack-plugin": "^0.1.9", 56 | "chai": "^3.2.0", 57 | "copyfiles": "^0.2.1", 58 | "css-loader": "^0.23.0", 59 | "eslint": "4.10.0", 60 | "eslint-config-airbnb": "^16.1.0", 61 | "eslint-loader": "^1.0.0", 62 | "eslint-plugin-import": "^2.8.0", 63 | "eslint-plugin-jsx-a11y": "^6.0.2", 64 | "eslint-plugin-react": "^7.4.0", 65 | "file-loader": "^0.8.4", 66 | "glob": "^6.0.0", 67 | "isparta-instrumenter-loader": "^1.0.0", 68 | "karma": "^0.13.9", 69 | "karma-chai": "^0.1.0", 70 | "karma-coverage": "^0.5.3", 71 | "karma-mocha": "^0.2.0", 72 | "karma-mocha-reporter": "^1.1.1", 73 | "karma-phantomjs-launcher": "^0.2.1", 74 | "karma-phantomjs-shim": "^1.1.1", 75 | "karma-sourcemap-loader": "^0.3.5", 76 | "karma-webpack": "^1.7.0", 77 | "lodash": "^4.0.0", 78 | "minimist": "^1.2.0", 79 | "mocha": "^2.2.5", 80 | "node-sass": "^3.4.2", 81 | "null-loader": "^0.1.1", 82 | "open": "0.0.5", 83 | "phantomjs": "^1.9.18", 84 | "postcss": "^5.0.11", 85 | "postcss-loader": "^0.8.0", 86 | "react-addons-test-utils": "^15.6.2 ", 87 | "react-hot-loader": "^3.1.1", 88 | "rimraf": "^2.4.3", 89 | "sass-loader": "^3.1.2", 90 | "style-loader": "^0.13.0", 91 | "url-loader": "^0.5.6", 92 | "webpack": "^1.12.0", 93 | "webpack-dev-server": "^1.12.0" 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /server.js: -------------------------------------------------------------------------------- 1 | /*eslint no-console:0 */ 2 | require('core-js/fn/object/assign'); 3 | var webpack = require('webpack'); 4 | var WebpackDevServer = require('webpack-dev-server'); 5 | var config = require('./webpack.config'); 6 | var open = require('open'); 7 | 8 | new WebpackDevServer(webpack(config), config.devServer) 9 | .listen(config.port, 'localhost', function(err) { 10 | if (err) { 11 | console.log(err); 12 | } 13 | console.log('Listening at localhost:' + config.port); 14 | console.log('Opening your system browser...'); 15 | open('http://localhost:' + config.port + '/webpack-dev-server/'); 16 | }); 17 | -------------------------------------------------------------------------------- /src/actions/ActionsFunction.js: -------------------------------------------------------------------------------- 1 | import Immutable from 'immutable'; 2 | import { ConnectionType, ConnectionStatus } from '../constant/Constants'; 3 | import Helper from '../helpers/GlobalHelpers'; 4 | 5 | const defaultState = Immutable.fromJS({ 6 | connections: [{ 7 | name: 'Websocket.org Echo', 8 | parameters: { 9 | host: 'ws://echo.websocket.org', 10 | type: ConnectionType.ws, 11 | channel: '', 12 | }, 13 | status: ConnectionStatus.DISCONNECTED, 14 | messages: [], 15 | }], 16 | index: 0, 17 | }); 18 | 19 | const emptyState = Immutable.fromJS({ 20 | connections: [{ 21 | name: 'Default', 22 | parameters: { 23 | host: '', 24 | type: ConnectionType.ws, 25 | channel: '', 26 | }, 27 | status: ConnectionStatus.DISCONNECTED, 28 | messages: [], 29 | }], 30 | index: 0, 31 | }); 32 | 33 | function updateConnectionParameter(state, action, parameter) { 34 | const connectionIndex = state.get('index'); 35 | const parameters = ['connections', connectionIndex, 'parameters', parameter]; 36 | return state.setIn(parameters, action.value); 37 | } 38 | 39 | function updateConnectionType(state, action) { 40 | return updateConnectionParameter(state, action, 'type'); 41 | } 42 | 43 | function updateConnectionHost(state, action) { 44 | return updateConnectionParameter(state, action, 'host'); 45 | } 46 | 47 | function updateConnectionChannel(state, action) { 48 | return updateConnectionParameter(state, action, 'channel'); 49 | } 50 | 51 | function updateConnectionStatus(state, action, value) { 52 | const connectionIndex = state.get('index'); 53 | const parameters = ['connections', connectionIndex, 'status']; 54 | return state.setIn(parameters, value); 55 | } 56 | 57 | function addConnection(state, action) { 58 | const connectionParameters = Immutable.fromJS({ 59 | name: action.value, 60 | parameters: { 61 | host: '', 62 | type: ConnectionType.ws, 63 | channel: '', 64 | }, 65 | status: ConnectionStatus.DISCONNECTED, 66 | messages: [], 67 | }); 68 | const parameters = ['connections']; 69 | let newState = state.updateIn(parameters, array => array.push(connectionParameters)); 70 | const currentConnection = Helper.getCurrentConnection(state); 71 | if (currentConnection.status === ConnectionStatus.DISCONNECTED) { 72 | newState = newState.set('index', state.get('connections').size); 73 | } 74 | return newState; 75 | } 76 | 77 | function removeConnection(state) { 78 | const { size } = state.get('connections'); 79 | if (size === 1) { 80 | return emptyState; 81 | } 82 | const connectionIndex = state.get('index'); 83 | const parameters = ['connections']; 84 | if (size === connectionIndex + 1) { 85 | const newState = state.updateIn(parameters, array => array.remove(connectionIndex)); 86 | return newState.set('index', connectionIndex - 1); 87 | } 88 | return state.updateIn(parameters, array => array.remove(connectionIndex)); 89 | } 90 | 91 | function updatePlaygroundIndex(state, action) { 92 | return state.set('index', action.value); 93 | } 94 | 95 | function updateTerminalData(state, action) { 96 | const connectionIndex = state.get('index'); 97 | const message = { 98 | key: new Date().getTime(), 99 | date: new Date(), 100 | message: action.value, 101 | type: action.messageType, 102 | }; 103 | const parameters = ['connections', connectionIndex, 'messages']; 104 | return state.updateIn(parameters, array => array.push(message)); 105 | } 106 | 107 | function deleteTerminalMessages(state) { 108 | const connectionIndex = state.get('index'); 109 | const parameters = ['connections', connectionIndex, 'messages']; 110 | return state.updateIn(parameters, array => array.clear()); 111 | } 112 | 113 | function setOfflineState(state, action) { 114 | if (typeof action.value === 'undefined' || action.value === null) { 115 | return defaultState; 116 | } 117 | return Immutable.fromJS(action.value); 118 | } 119 | 120 | function getDefaultState() { 121 | return defaultState; 122 | } 123 | 124 | export const ContainerFunctions = { 125 | updateConnectionType, 126 | updateConnectionHost, 127 | updateConnectionChannel, 128 | addConnection, 129 | removeConnection, 130 | updatePlaygroundIndex, 131 | updateTerminalData, 132 | deleteTerminalMessages, 133 | }; 134 | 135 | export const ConnectionFunctions = { 136 | updateConnectionStatus, 137 | }; 138 | 139 | export const StorageFunctions = { 140 | setOfflineState, 141 | getDefaultState, 142 | }; 143 | -------------------------------------------------------------------------------- /src/actions/ActionsType.js: -------------------------------------------------------------------------------- 1 | 2 | export const SocketContainerAction = { 3 | CHANGE_CONNECTION_TYPE: 'change-connection-type', 4 | CHANGE_HOST: 'change-host', 5 | CHANGE_CHANNEL: 'change-channel', 6 | UPDATE_INDEX: 'update-playground-index', 7 | ADD_CONNECTION: 'add-connection', 8 | DELETE_TERMINAL_MESSAGES: 'delete-terminal-messages', 9 | REMOVE_CONNECTION: 'remove-connection', 10 | }; 11 | 12 | export const SocketConnectionAction = { 13 | CONNECTED: 'socket-connection-connected', 14 | DISCONNECT: 'socket-connection-disconnected', 15 | SEND: 'socket-connection-send', 16 | RECEIVED: 'socket-connection-received', 17 | }; 18 | 19 | export const StorageAction = { 20 | READ_OFFLINE: 'read-offline-state', 21 | }; 22 | -------------------------------------------------------------------------------- /src/components/Column.js: -------------------------------------------------------------------------------- 1 | import 'flexboxgrid'; // eslint-disable-line 2 | import React from 'react'; 3 | import PropTypes from 'prop-types'; 4 | 5 | class Column extends React.Component { 6 | generateClass() { 7 | let className = this.props.className || ''; 8 | className = this.generateClassName(className, 'xs'); 9 | className = this.generateClassName(className, 'sm'); 10 | className = this.generateClassName(className, 'md'); 11 | className = this.generateClassName(className, 'lg'); 12 | return className; 13 | } 14 | 15 | generateClassName(className, type) { 16 | if (this.props[type]) { 17 | return `${className} col-${type}-${this.props[type]}`; 18 | } 19 | return className; 20 | } 21 | 22 | render() { 23 | const className = this.generateClass(); 24 | return ( 25 |
26 | {this.props.children} 27 |
28 | ); 29 | } 30 | } 31 | 32 | Column.propTypes = { 33 | className: PropTypes.string, 34 | children: PropTypes.node.isRequired, 35 | style: PropTypes.object, 36 | }; 37 | 38 | Column.defaultProps = { 39 | className: '', 40 | style: {}, 41 | }; 42 | 43 | export default Column; 44 | -------------------------------------------------------------------------------- /src/components/HistoryList.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import PropTypes from 'prop-types'; 3 | import { List, ListItem } from 'material-ui/List'; 4 | import FlatButton from 'material-ui/FlatButton'; 5 | import AddIcon from 'material-ui/svg-icons/content/add-box'; 6 | import ArrowIcon from 'material-ui/svg-icons/action/compare-arrows'; 7 | import Dialog from 'material-ui/Dialog'; 8 | import TextField from 'material-ui/TextField'; 9 | import { ConnectionStatus } from '../constant/Constants'; 10 | import { SocketContainerAction } from '../actions/ActionsType'; 11 | 12 | class HistoryList extends React.Component { 13 | constructor(props) { 14 | super(props); 15 | this.state = { 16 | connectionStatusDialog: false, 17 | addConnectionDialog: false, 18 | connectionErrorMessage: '', 19 | }; 20 | } 21 | 22 | handleStatusDialogOpen() { 23 | this.setState({ connectionStatusDialog: true }); 24 | } 25 | 26 | handleStatusDialogClose() { 27 | this.setState({ connectionStatusDialog: false }); 28 | } 29 | 30 | handleAddConnectionOpen() { 31 | this.setState({ 32 | addConnectionDialog: true, 33 | connectionErrorMessage: '', 34 | }); 35 | } 36 | 37 | handleAddConnectionClose() { 38 | this.setState({ addConnectionDialog: false }); 39 | } 40 | 41 | addConnection() { 42 | const connectionName = this.connectionName.input.value; 43 | if (connectionName === '') { 44 | this.setState({ connectionErrorMessage: 'This field is required' }); 45 | return; 46 | } 47 | this.props.dispatch({ 48 | type: SocketContainerAction.ADD_CONNECTION, 49 | value: connectionName, 50 | }); 51 | this.handleAddConnectionClose(); 52 | } 53 | 54 | newConnectionTextListener(event) { 55 | if (event.keyCode === 13) { 56 | this.addConnection(); 57 | } 58 | } 59 | 60 | updatePlaygroundIndex(itemIndex) { 61 | if (this.props.status === ConnectionStatus.CONNECTED) { 62 | this.handleStatusDialogOpen(); 63 | return; 64 | } 65 | this.props.dispatch({ 66 | type: SocketContainerAction.UPDATE_INDEX, 67 | value: itemIndex, 68 | }); 69 | } 70 | 71 | createListItem(connectionItem, index) { 72 | const selectedClass = this.props.currentIndex === index ? 'selected-item' : ''; 73 | return ( 74 | } 77 | primaryText={connectionItem.name} 78 | onTouchTap={() => this.updatePlaygroundIndex(index)} 79 | className={selectedClass} 80 | /> 81 | ); 82 | } 83 | 84 | render() { 85 | const containerStyle = { height: this.props.height }; 86 | const items = this.props.connections.map((item, index) => this.createListItem(item, index)); 87 | const statusActions = [ 88 | this.handleStatusDialogClose()} 92 | />, 93 | ]; 94 | const addConnectionActions = [ 95 | this.handleAddConnectionClose()} 99 | />, 100 | this.addConnection()} 104 | />, 105 | ]; 106 | return ( 107 | 108 | } 111 | className="menu-button-item" 112 | onTouchTap={() => this.handleAddConnectionOpen()} 113 | /> 114 | {items} 115 | this.handleStatusDialogClose()} 122 | > 123 | Please close the current connection first. 124 | 125 | this.handleAddConnectionClose()} 132 | > 133 | this.newConnectionTextListener(event)} 135 | ref={(input) => { this.connectionName = input; }} 136 | hint="Connection Name" 137 | floatingLabelText="Connection Name" 138 | errorText={this.state.connectionErrorMessage} 139 | /> 140 | 141 | 142 | ); 143 | } 144 | } 145 | 146 | HistoryList.propTypes = { 147 | dispatch: PropTypes.func.isRequired, 148 | currentIndex: PropTypes.number.isRequired, 149 | connections: PropTypes.array.isRequired, 150 | status: PropTypes.string.isRequired, 151 | height: PropTypes.number.isRequired, 152 | }; 153 | 154 | export default HistoryList; 155 | -------------------------------------------------------------------------------- /src/components/Main.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import HistoryList from '../containers/HistoryList'; 3 | import SocketPlayground from '../containers/SocketPlayground'; 4 | import SocketPlaygroundBar from './SocketPlaygroundBar'; 5 | import Row from './Row'; 6 | import Column from './Column'; 7 | 8 | const appBarHeight = 70; 9 | 10 | class AppComponent extends React.Component { 11 | constructor(props) { 12 | super(props); 13 | this.state = { 14 | listHeight: window.innerHeight - appBarHeight, 15 | }; 16 | } 17 | 18 | componentDidMount() { 19 | window.addEventListener('resize', () => this.listHeight()); 20 | } 21 | 22 | componentWillUnmount() { 23 | window.removeEventListener('resize', () => this.listHeight()); 24 | } 25 | 26 | listHeight() { 27 | const height = window.innerHeight - appBarHeight; 28 | this.setState({ 29 | listHeight: height, 30 | }); 31 | } 32 | 33 | render() { 34 | return ( 35 |
36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 |
46 | ); 47 | } 48 | } 49 | 50 | export default AppComponent; 51 | -------------------------------------------------------------------------------- /src/components/Row.js: -------------------------------------------------------------------------------- 1 | import 'flexboxgrid'; // eslint-disable-line 2 | import React from 'react'; 3 | import PropTypes from 'prop-types'; 4 | 5 | const Row = ({ className, children }) => { 6 | const elementClassName = `row ${className || ''}`; 7 | return ( 8 |
9 | {children} 10 |
11 | ); 12 | }; 13 | 14 | Row.propTypes = { 15 | className: PropTypes.string, 16 | children: PropTypes.node.isRequired, 17 | }; 18 | 19 | Row.defaultProps = { 20 | className: '', 21 | }; 22 | 23 | export default Row; 24 | -------------------------------------------------------------------------------- /src/components/SocketPlayground.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import PropTypes from 'prop-types'; 3 | import Paper from 'material-ui/Paper'; 4 | import { ConnectionType } from '../constant/Constants'; 5 | import SocketSetting from '../containers/SocketSetting'; 6 | import SocketTerminal from '../containers/SocketTerminal'; 7 | import WebSocketConnection from '../helpers/WebSocketConnection'; 8 | import SocketIOConnection from '../helpers/SocketIOConnection'; 9 | 10 | const webSocket = new WebSocketConnection(); 11 | const socketIO = new SocketIOConnection(); 12 | 13 | const SocketPlayground = ({ parameters }) => { 14 | const currentSocket = parameters.type === ConnectionType.ws ? webSocket : socketIO; 15 | return ( 16 | 17 | 18 | 19 | 20 | ); 21 | }; 22 | 23 | SocketPlayground.propTypes = { 24 | parameters: PropTypes.object.isRequired, 25 | }; 26 | 27 | export default SocketPlayground; 28 | -------------------------------------------------------------------------------- /src/components/SocketPlaygroundBar.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import AppBar from 'material-ui/AppBar'; 3 | import FlatButton from 'material-ui/FlatButton'; 4 | import { REPOSITORY_URL } from '../constant/Constants'; 5 | 6 | class SocketPlaygroundBar extends React.Component { 7 | static openRepository() { 8 | window.open(REPOSITORY_URL); 9 | } 10 | 11 | render() { 12 | const codeIcon = ; 13 | return ( 14 | 19 | ); 20 | } 21 | } 22 | 23 | export default SocketPlaygroundBar; 24 | -------------------------------------------------------------------------------- /src/components/SocketSetting.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import PropTypes from 'prop-types'; 3 | import SelectField from 'material-ui/SelectField'; 4 | import TextField from 'material-ui/TextField'; 5 | import RaisedButton from 'material-ui/RaisedButton'; 6 | import MenuItem from 'material-ui/MenuItem'; 7 | import RemoveIcon from 'material-ui/svg-icons/content/remove-circle'; 8 | import { ConnectionType, ConnectionStatus } from '../constant/Constants'; 9 | import { SocketContainerAction } from '../actions/ActionsType'; 10 | import Row from './Row'; 11 | import Column from './Column'; 12 | 13 | const textFieldStyle = { 14 | width: '100%', 15 | minWidth: '100px', 16 | }; 17 | 18 | class SocketSetting extends React.Component { 19 | constructor(props) { 20 | super(props); 21 | this.state = { 22 | hostErrorMessage: '', 23 | }; 24 | } 25 | 26 | handleSelectChange(event, index, value) { 27 | this.props.dispatch({ 28 | type: SocketContainerAction.CHANGE_CONNECTION_TYPE, 29 | value, 30 | }); 31 | } 32 | 33 | handleHostChange(event) { 34 | this.setState({ hostErrorMessage: '' }); 35 | this.props.dispatch({ 36 | type: SocketContainerAction.CHANGE_HOST, 37 | value: event.target.value, 38 | }); 39 | } 40 | 41 | handleChannelChange(event) { 42 | this.props.dispatch({ 43 | type: SocketContainerAction.CHANGE_CHANNEL, 44 | value: event.target.value, 45 | }); 46 | } 47 | 48 | connectToWebSocket() { 49 | const { 50 | webSocket, 51 | parameters, 52 | dispatch, 53 | status, 54 | } = this.props; 55 | const { host, channel } = parameters; 56 | if (this.props.status === ConnectionStatus.DISCONNECTED && host !== '') { 57 | webSocket.connect(host, dispatch, channel); 58 | } else if (status === ConnectionStatus.DISCONNECTED && host === '') { 59 | this.setState({ hostErrorMessage: 'This field is required' }); 60 | } else { 61 | webSocket.close(); 62 | } 63 | } 64 | 65 | generateChannelInput(disableChanges) { 66 | if (this.props.parameters.type === ConnectionType.io) { 67 | const channelValue = this.props.parameters.channel; 68 | return ( 69 | 70 | 71 | this.handleChannelChange(event)} 76 | disabled={disableChanges} 77 | style={textFieldStyle} 78 | /> 79 | 80 | 81 | ); 82 | } 83 | return null; 84 | } 85 | 86 | removeConnection() { 87 | this.props.dispatch({ 88 | type: SocketContainerAction.REMOVE_CONNECTION, 89 | }); 90 | } 91 | 92 | render() { 93 | const connectionName = this.props.name; 94 | const connectionTypeValue = this.props.parameters.type; 95 | const hostValue = this.props.parameters.host; 96 | const disableChanges = this.props.status === ConnectionStatus.CONNECTED; 97 | const buttonLabel = this.props.status === ConnectionStatus.CONNECTED ? 'Disconnect' : 'Connect'; 98 | const channelInput = this.generateChannelInput(disableChanges); 99 | const iconColor = '#aaa'; 100 | let buttonOnErrorStyle = {}; 101 | if (this.state.hostErrorMessage !== '') { 102 | buttonOnErrorStyle = { bottom: '35px' }; 103 | } 104 | return ( 105 |
106 | 107 |

108 | Websocket Settings: 109 | {connectionName} 110 | this.removeConnection()} 113 | color={iconColor} 114 | /> 115 | 116 |

117 |
118 | 119 | 120 | this.handleSelectChange(event, index, value)} 125 | floatingLabelText="Connection Type" 126 | > 127 | 128 | 129 | 130 | 131 | 132 | this.handleHostChange(event)} 137 | disabled={disableChanges} 138 | errorText={this.state.hostErrorMessage} 139 | style={textFieldStyle} 140 | /> 141 | 142 | 143 | this.connectToWebSocket()} 147 | /> 148 | 149 | 150 | {channelInput} 151 |
152 | ); 153 | } 154 | } 155 | 156 | SocketSetting.propTypes = { 157 | dispatch: PropTypes.func.isRequired, 158 | name: PropTypes.string.isRequired, 159 | parameters: PropTypes.object.isRequired, 160 | status: PropTypes.string.isRequired, 161 | webSocket: PropTypes.object.isRequired, 162 | }; 163 | 164 | export default SocketSetting; 165 | -------------------------------------------------------------------------------- /src/components/SocketTerminal.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import PropTypes from 'prop-types'; 3 | import TextField from 'material-ui/TextField'; 4 | import RaisedButton from 'material-ui/RaisedButton'; 5 | import SocketTerminalList from '../containers/SocketTerminalList'; 6 | import { ConnectionStatus } from '../constant/Constants'; 7 | import { SocketContainerAction } from '../actions/ActionsType'; 8 | import Row from './Row'; 9 | import Column from './Column'; 10 | 11 | class SocketTerminal extends React.Component { 12 | componentDidUpdate() { 13 | const terminalComponent = this.terminalList; 14 | if (typeof terminalComponent !== 'undefined') { 15 | const terminalNode = terminalComponent.querySelector('.full-height'); 16 | terminalNode.scrollTop = terminalNode.scrollHeight; 17 | } 18 | } 19 | 20 | sendMessage() { 21 | const messageInput = this.messageText.input; 22 | this.props.webSocket.send(messageInput.value); 23 | messageInput.value = ''; 24 | } 25 | 26 | clearMessages() { 27 | this.props.dispatch({ 28 | type: SocketContainerAction.DELETE_TERMINAL_MESSAGES, 29 | }); 30 | } 31 | 32 | messageTextFieldListener(event) { 33 | if (event.keyCode === 13) { 34 | this.sendMessage(); 35 | } 36 | } 37 | 38 | render() { 39 | const disableChanges = this.props.status === ConnectionStatus.DISCONNECTED; 40 | const clearDisable = this.props.terminalData.length < 1; 41 | const connectionType = this.props.parameters.type; 42 | return ( 43 |
44 | 45 | 46 | { this.messageText = input; }} 48 | disabled={disableChanges} 49 | hint="Hello world" 50 | fullWidth 51 | floatingLabelText="Message" 52 | onKeyUp={event => this.messageTextFieldListener(event)} 53 | /> 54 | 55 | 56 | this.sendMessage()} 61 | /> 62 | this.clearMessages()} 68 | /> 69 | 70 | 71 | { this.terminalList = input; }} 73 | connectionType={connectionType} 74 | terminalData={this.props.terminalData} 75 | /> 76 |
77 | ); 78 | } 79 | } 80 | 81 | SocketTerminal.propTypes = { 82 | dispatch: PropTypes.func.isRequired, 83 | terminalData: PropTypes.array.isRequired, 84 | parameters: PropTypes.object.isRequired, 85 | status: PropTypes.string.isRequired, 86 | webSocket: PropTypes.object.isRequired, 87 | }; 88 | 89 | export default SocketTerminal; 90 | -------------------------------------------------------------------------------- /src/components/SocketTerminalList.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import PropTypes from 'prop-types'; 3 | import Row from './Row'; 4 | import Column from './Column'; 5 | import TerminalListItem from './TerminalListItem'; 6 | import { ConnectionType } from '../constant/Constants'; 7 | 8 | class SocketTerminalList extends React.Component { 9 | static createRow(messageItem) { 10 | return ; 11 | } 12 | 13 | componentDidMount() { 14 | window.addEventListener('resize', () => this.forceUpdate()); 15 | } 16 | 17 | componentWillUnmount() { 18 | window.removeEventListener('resize', () => this.forceUpdate()); 19 | } 20 | 21 | render() { 22 | const offset = this.props.connectionType === ConnectionType.ws ? 305 : 377; 23 | const terminalHeight = window.innerHeight - offset; 24 | const terminalStyle = { height: terminalHeight }; 25 | const terminalItems = this.props.terminalData.map(messageItem => this.createRow(messageItem)); 26 | return ( 27 |
28 | 29 | 30 | Date: 31 | 32 | 33 | Message: 34 | 35 | 36 |
37 | {terminalItems} 38 |
39 |
40 | ); 41 | } 42 | } 43 | 44 | SocketTerminalList.propTypes = { 45 | connectionType: PropTypes.string.isRequired, 46 | terminalData: PropTypes.array.isRequired, 47 | }; 48 | 49 | export default SocketTerminalList; 50 | -------------------------------------------------------------------------------- /src/components/TerminalListItem.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import PropTypes from 'prop-types'; 3 | import Row from './Row'; 4 | import Column from './Column'; 5 | 6 | const TerminalListItem = ({ messageItem }) => { 7 | const messageStyle = `selectable-text ${messageItem.type}`; 8 | const dateString = new Date(messageItem.date).toTimeString(); 9 | return ( 10 | 11 | {dateString} 12 | {messageItem.message} 13 | 14 | ); 15 | }; 16 | 17 | TerminalListItem.propTypes = { 18 | messageItem: PropTypes.object.isRequired, 19 | }; 20 | 21 | export default TerminalListItem; 22 | -------------------------------------------------------------------------------- /src/config/README.md: -------------------------------------------------------------------------------- 1 | # About this folder 2 | This folder holds configuration files for different environments. 3 | You can use it to provide your app with different settings based on the 4 | current environment, e.g. to configure different API base urls depending on 5 | whether your setup runs in dev mode or is built for distribution. 6 | You can include the configuration into your code like this: 7 | 8 | ```javascript 9 | let react = require('react/addons'); 10 | let config = require('config'); 11 | class MyComponent extends React.Component { 12 | constructor(props) { 13 | super(props); 14 | let currentAppEnv = config.appEnv; 15 | } 16 | } 17 | ``` 18 | -------------------------------------------------------------------------------- /src/config/base.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | // Settings configured here will be merged into the final config object. 4 | export default { 5 | }; 6 | -------------------------------------------------------------------------------- /src/config/dev.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | import baseConfig from './base'; 4 | 5 | 6 | const config = { 7 | appEnv: 'dev', // feel free to remove the appEnv property here 8 | }; 9 | 10 | export default Object.freeze(Object.assign({}, baseConfig, config)); 11 | -------------------------------------------------------------------------------- /src/config/dist.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | import baseConfig from './base'; 4 | 5 | 6 | const config = { 7 | appEnv: 'dist', // feel free to remove the appEnv property here 8 | }; 9 | 10 | export default Object.freeze(Object.assign({}, baseConfig, config)); 11 | 12 | -------------------------------------------------------------------------------- /src/config/test.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | import baseConfig from './base'; 4 | 5 | 6 | const config = { 7 | appEnv: 'test', // don't remove the appEnv property here 8 | }; 9 | 10 | export default Object.freeze(Object.assign(baseConfig, config)); 11 | 12 | -------------------------------------------------------------------------------- /src/constant/Constants.js: -------------------------------------------------------------------------------- 1 | 2 | export const ConnectionType = { 3 | ws: 'websocket', 4 | io: 'socket.io', 5 | }; 6 | 7 | export const ConnectionStatus = { 8 | CONNECTED: 'connected', 9 | DISCONNECTED: 'disconnected', 10 | }; 11 | 12 | export const MessageType = { 13 | CLIENT: 'client-message', 14 | SERVER: 'server-message', 15 | ERROR: 'error-message', 16 | STATUS: 'status-message', 17 | }; 18 | 19 | export const REPOSITORY_URL = 'https://github.com/williamcabrera4/chrome-app-websocket-tester'; 20 | -------------------------------------------------------------------------------- /src/containers/HistoryList.js: -------------------------------------------------------------------------------- 1 | import { connect } from 'react-redux'; 2 | import Helper from '../helpers/GlobalHelpers'; 3 | import HistoryList from '../components/HistoryList'; 4 | 5 | function mapStateToProps(state) { 6 | const stateObject = state.socketContainerReducer.toJS(); 7 | const currentConnection = Helper.getCurrentConnection(state.socketContainerReducer); 8 | return { 9 | connections: stateObject.connections, 10 | currentIndex: stateObject.index, 11 | status: currentConnection.status, 12 | }; 13 | } 14 | 15 | export default connect(mapStateToProps)(HistoryList); 16 | -------------------------------------------------------------------------------- /src/containers/SocketPlayground.js: -------------------------------------------------------------------------------- 1 | import { connect } from 'react-redux'; 2 | import Helper from '../helpers/GlobalHelpers'; 3 | import SocketPlayground from '../components/SocketPlayground'; 4 | 5 | function mapStateToProps(state) { 6 | const socketState = state.socketContainerReducer; 7 | const currentConnection = Helper.getCurrentConnection(socketState); 8 | return { 9 | parameters: currentConnection.parameters, 10 | }; 11 | } 12 | 13 | export default connect(mapStateToProps)(SocketPlayground); 14 | -------------------------------------------------------------------------------- /src/containers/SocketSetting.js: -------------------------------------------------------------------------------- 1 | import { connect } from 'react-redux'; 2 | import Helper from '../helpers/GlobalHelpers'; 3 | import SocketSetting from '../components/SocketSetting'; 4 | 5 | function mapStateToProps(state) { 6 | const socketState = state.socketContainerReducer; 7 | const currentConnection = Helper.getCurrentConnection(socketState); 8 | return { 9 | name: currentConnection.name, 10 | parameters: currentConnection.parameters, 11 | status: currentConnection.status, 12 | }; 13 | } 14 | 15 | export default connect(mapStateToProps)(SocketSetting); 16 | -------------------------------------------------------------------------------- /src/containers/SocketTerminal.js: -------------------------------------------------------------------------------- 1 | import { connect } from 'react-redux'; 2 | import Helper from '../helpers/GlobalHelpers'; 3 | import SocketTerminal from '../components/SocketTerminal'; 4 | 5 | function mapStateToProps(state) { 6 | const socketState = state.socketContainerReducer; 7 | const currentConnection = Helper.getCurrentConnection(socketState); 8 | return { 9 | terminalData: currentConnection.messages, 10 | status: currentConnection.status, 11 | parameters: currentConnection.parameters, 12 | }; 13 | } 14 | 15 | export default connect(mapStateToProps)(SocketTerminal); 16 | -------------------------------------------------------------------------------- /src/containers/SocketTerminalList.js: -------------------------------------------------------------------------------- 1 | import { connect } from 'react-redux'; 2 | import Helper from '../helpers/GlobalHelpers'; 3 | import SocketTerminalList from '../components/SocketTerminalList'; 4 | 5 | function mapStateToProps(state) { 6 | const socketState = state.socketContainerReducer; 7 | const currentConnection = Helper.getCurrentConnection(socketState); 8 | return { 9 | connectionType: currentConnection.parameters.type, 10 | }; 11 | } 12 | 13 | export default connect(mapStateToProps)(SocketTerminalList); 14 | -------------------------------------------------------------------------------- /src/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/williamcabrera4/chrome-app-websocket-tester/ef678d5c73dca8be0905dc35354085e70502172c/src/favicon.ico -------------------------------------------------------------------------------- /src/helpers/GlobalHelpers.js: -------------------------------------------------------------------------------- 1 | const getCurrentConnection = (state) => { 2 | const connections = state.get('connections'); 3 | const currentIndex = state.get('index'); 4 | return connections.get(currentIndex).toJS(); 5 | }; 6 | 7 | const formatMessage = (message) => { 8 | if (typeof message === 'object') { 9 | return JSON.stringify(message); 10 | } 11 | return message; 12 | }; 13 | 14 | export default { 15 | getCurrentConnection, 16 | formatMessage, 17 | }; 18 | -------------------------------------------------------------------------------- /src/helpers/SocketIOConnection.js: -------------------------------------------------------------------------------- 1 | import * as io from 'socket.io-client'; 2 | import { SocketConnectionAction } from '../actions/ActionsType'; 3 | import { MessageType } from '../constant/Constants'; 4 | import Helper from '../helpers/GlobalHelpers'; 5 | 6 | class SocketIOConnection { 7 | connect(wsUri, dispatch, channel) { 8 | this.websocket = io.connect(wsUri); 9 | this.dispatch = dispatch; 10 | this.channel = channel; 11 | this.setListeners(); 12 | } 13 | 14 | send(message) { 15 | this.websocket.emit(this.channel, message); 16 | this.dispatch({ 17 | type: SocketConnectionAction.RECEIVED, 18 | value: `CLIENT: ${message}`, 19 | messageType: MessageType.CLIENT, 20 | }); 21 | } 22 | 23 | setListeners() { 24 | this.websocket.on('connect', this.onOpen.bind(this)); 25 | this.websocket.on('disconnect', this.onClose.bind(this)); 26 | this.websocket.on(this.channel, this.onMessage.bind(this)); 27 | } 28 | 29 | onOpen() { 30 | this.dispatch({ 31 | type: SocketConnectionAction.CONNECTED, 32 | }); 33 | this.dispatch({ 34 | type: SocketConnectionAction.RECEIVED, 35 | value: 'STATUS: CONNECTED', 36 | messageType: MessageType.STATUS, 37 | }); 38 | } 39 | 40 | onMessage(rawMessage) { 41 | const message = Helper.formatMessage(rawMessage); 42 | this.dispatch({ 43 | type: SocketConnectionAction.RECEIVED, 44 | value: `SERVER: ${message}`, 45 | messageType: MessageType.SERVER, 46 | }); 47 | } 48 | 49 | onClose() { 50 | this.dispatch({ 51 | type: SocketConnectionAction.DISCONNECT, 52 | }); 53 | this.dispatch({ 54 | type: SocketConnectionAction.RECEIVED, 55 | value: 'STATUS: DISCONNECTED', 56 | messageType: MessageType.STATUS, 57 | }); 58 | } 59 | 60 | close() { 61 | this.websocket.disconnect(); 62 | } 63 | } 64 | 65 | export default SocketIOConnection; 66 | -------------------------------------------------------------------------------- /src/helpers/StorageHelper.js: -------------------------------------------------------------------------------- 1 | import proxyStorage from './StorageProxy'; 2 | import { ConnectionFunctions } from '../actions/ActionsFunction'; 3 | import { ConnectionStatus } from '../constant/Constants'; 4 | 5 | const stateKey = 'state'; 6 | 7 | class StorageHelper { 8 | constructor(store) { 9 | this.store = store; 10 | } 11 | 12 | init() { 13 | this.store.subscribe(this.subscribeAction.bind(this)); 14 | } 15 | 16 | subscribeAction() { 17 | const state = this.store.getState().socketContainerReducer; 18 | StorageHelper.saveState(state); 19 | } 20 | 21 | static saveState(state) { 22 | // Don't save the connected status 23 | const newState = ConnectionFunctions.updateConnectionStatus( 24 | state, {}, 25 | ConnectionStatus.DISCONNECTED, 26 | ); 27 | const stateJSON = JSON.stringify(newState); 28 | proxyStorage.setItem(stateKey, stateJSON); 29 | } 30 | 31 | static readState(callback) { 32 | proxyStorage.getItem(stateKey, callback); 33 | } 34 | } 35 | 36 | export default StorageHelper; 37 | -------------------------------------------------------------------------------- /src/helpers/StorageProxy.js: -------------------------------------------------------------------------------- 1 | /* global chrome */ 2 | 3 | const storageProxy = { 4 | setItem: () => {}, 5 | getItem: () => {}, 6 | }; 7 | 8 | if (typeof chrome !== 'undefined' && typeof chrome.storage !== 'undefined') { 9 | storageProxy.setItem = (key, value) => { 10 | const storageObject = {}; 11 | storageObject[key] = value; 12 | chrome.storage.local.set(storageObject); 13 | }; 14 | storageProxy.getItem = (key, callback) => chrome.storage.local.get(key, (value) => { 15 | const stateObject = JSON.parse(value[key]); 16 | callback(stateObject); 17 | }); 18 | } else if (typeof window.localStorage !== 'undefined') { 19 | storageProxy.setItem = (key, value) => window.localStorage.setItem(key, value); 20 | storageProxy.getItem = (key, callback) => { 21 | const value = window.localStorage.getItem(key); 22 | const stateObject = JSON.parse(value); 23 | callback(stateObject); 24 | }; 25 | } 26 | 27 | export default storageProxy; 28 | -------------------------------------------------------------------------------- /src/helpers/WebSocketConnection.js: -------------------------------------------------------------------------------- 1 | import { SocketConnectionAction } from '../actions/ActionsType'; 2 | import { MessageType } from '../constant/Constants'; 3 | import getCloseReason from './WebSocketErrorMessages'; 4 | import Helper from '../helpers/GlobalHelpers'; 5 | 6 | class WebSocketConnection { 7 | connect(wsUri, dispatch) { 8 | let uri = wsUri; 9 | if (!(wsUri.indexOf('ws://') === 0 || wsUri.indexOf('wss://') === 0)) { 10 | uri = `ws://${wsUri}`; 11 | } 12 | this.websocket = new WebSocket(uri); 13 | this.dispatch = dispatch; 14 | this.setListeners(); 15 | } 16 | 17 | send(message) { 18 | this.websocket.send(message); 19 | this.dispatch({ 20 | type: SocketConnectionAction.RECEIVED, 21 | value: `CLIENT: ${message}`, 22 | messageType: MessageType.CLIENT, 23 | }); 24 | } 25 | 26 | setListeners() { 27 | this.websocket.onopen = this.onOpen.bind(this); 28 | this.websocket.onmessage = this.onMessage.bind(this); 29 | this.websocket.onclose = this.onClose.bind(this); 30 | } 31 | 32 | onOpen() { 33 | this.dispatch({ 34 | type: SocketConnectionAction.CONNECTED, 35 | }); 36 | this.dispatch({ 37 | type: SocketConnectionAction.RECEIVED, 38 | value: 'STATUS: CONNECTED', 39 | messageType: MessageType.STATUS, 40 | }); 41 | } 42 | 43 | onMessage(event) { 44 | const message = Helper.formatMessage(event.data); 45 | this.dispatch({ 46 | type: SocketConnectionAction.RECEIVED, 47 | value: `SERVER: ${message}`, 48 | messageType: MessageType.SERVER, 49 | }); 50 | } 51 | 52 | onClose(event) { 53 | this.dispatch({ 54 | type: SocketConnectionAction.DISCONNECT, 55 | }); 56 | this.dispatch({ 57 | type: SocketConnectionAction.RECEIVED, 58 | value: 'STATUS: DISCONNECTED', 59 | messageType: MessageType.STATUS, 60 | }); 61 | if (event.code !== 1005) { 62 | const reason = getCloseReason(event); 63 | this.dispatch({ 64 | type: SocketConnectionAction.RECEIVED, 65 | value: `ERROR: ${reason}`, 66 | messageType: MessageType.ERROR, 67 | }); 68 | } 69 | } 70 | 71 | close() { 72 | this.websocket.close(); 73 | } 74 | } 75 | 76 | export default WebSocketConnection; 77 | -------------------------------------------------------------------------------- /src/helpers/WebSocketErrorMessages.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | 3 | // Code from StackOverflow 4 | // Reference: http://stackoverflow.com/a/28396165/3140190 5 | 6 | // See http://tools.ietf.org/html/rfc6455#section-7.4.1 7 | export default function(event) { 8 | let reason = ''; 9 | if (event.code == 1000) 10 | reason = "Normal closure, meaning that the purpose for which the connection was established has been fulfilled."; 11 | else if (event.code == 1001) 12 | reason = "An endpoint is \"going away\", such as a server going down or a browser having navigated away from a page."; 13 | else if (event.code == 1002) 14 | reason = "An endpoint is terminating the connection due to a protocol error"; 15 | else if (event.code == 1003) 16 | reason = "An endpoint is terminating the connection because it has received a type of data it cannot accept (e.g., an endpoint that understands only text data MAY send this if it receives a binary message)."; 17 | else if (event.code == 1004) 18 | reason = "Reserved. The specific meaning might be defined in the future."; 19 | else if (event.code == 1005) 20 | reason = "No status code was actually present."; 21 | else if (event.code == 1006) 22 | reason = "The connection was closed abnormally, e.g., without sending or receiving a Close control frame"; 23 | else if (event.code == 1007) 24 | reason = "An endpoint is terminating the connection because it has received data within a message that was not consistent with the type of the message (e.g., non-UTF-8 [http://tools.ietf.org/html/rfc3629] data within a text message)."; 25 | else if (event.code == 1008) 26 | reason = "An endpoint is terminating the connection because it has received a message that \"violates its policy\". This reason is given either if there is no other sutible reason, or if there is a need to hide specific details about the policy."; 27 | else if (event.code == 1009) 28 | reason = "An endpoint is terminating the connection because it has received a message that is too big for it to process."; 29 | else if (event.code == 1010) // Note that this status code is not used by the server, because it can fail the WebSocket handshake instead. 30 | reason = "An endpoint (client) is terminating the connection because it has expected the server to negotiate one or more extension, but the server didn't return them in the response message of the WebSocket handshake.
Specifically, the extensions that are needed are: " + event.reason; 31 | else if (event.code == 1011) 32 | reason = "A server is terminating the connection because it encountered an unexpected condition that prevented it from fulfilling the request."; 33 | else if (event.code == 1015) 34 | reason = "The connection was closed due to a failure to perform a TLS handshake (e.g., the server certificate can't be verified)."; 35 | else 36 | reason = "Unknown reason"; 37 | return reason; 38 | } 39 | -------------------------------------------------------------------------------- /src/images/yeoman.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/williamcabrera4/chrome-app-websocket-tester/ef678d5c73dca8be0905dc35354085e70502172c/src/images/yeoman.png -------------------------------------------------------------------------------- /src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Websocket Tester 6 | 7 | 8 | 9 | 10 | 11 |
Loading...
12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | import 'core-js/fn/object/assign'; 2 | import 'normalize.css'; 3 | import 'styles/App.scss'; // eslint-disable-line 4 | import injectTapEventPlugin from 'react-tap-event-plugin'; 5 | import React from 'react'; 6 | import ReactDOM from 'react-dom'; 7 | import { Provider } from 'react-redux'; 8 | import MuiThemeProvider from 'material-ui/styles/MuiThemeProvider'; 9 | 10 | import App from './components/Main'; 11 | import makeStore from './stores/AppStore'; 12 | import StorageHelper from './helpers/StorageHelper'; 13 | import { StorageAction } from './actions/ActionsType'; 14 | 15 | // Needed for onTouchTap 16 | // Can go away when react 1.0 release 17 | // Check this repo: 18 | // https://github.com/zilverline/react-tap-event-plugin 19 | injectTapEventPlugin(); 20 | 21 | const store = makeStore(); 22 | 23 | const storageHelper = new StorageHelper(store); 24 | storageHelper.init(); 25 | StorageHelper.readState((offlineState) => { 26 | store.dispatch({ type: StorageAction.READ_OFFLINE, value: offlineState }); 27 | }); 28 | 29 | // Render the main component into the dom 30 | ReactDOM.render( 31 | 32 | 33 | 34 | 35 | 36 | , document.getElementById('app'), 37 | ); 38 | -------------------------------------------------------------------------------- /src/reducers/RootReducer.js: -------------------------------------------------------------------------------- 1 | import { combineReducers } from 'redux'; 2 | import socketContainerReducer from './SocketContainerReducer'; 3 | 4 | export default combineReducers({ 5 | socketContainerReducer, 6 | }); 7 | -------------------------------------------------------------------------------- /src/reducers/SocketContainerReducer.js: -------------------------------------------------------------------------------- 1 | import { ConnectionStatus } from '../constant/Constants'; 2 | import { SocketContainerAction, SocketConnectionAction, StorageAction } 3 | from '../actions/ActionsType'; 4 | import { ConnectionFunctions, ContainerFunctions, StorageFunctions } 5 | from '../actions/ActionsFunction'; 6 | 7 | export default function (state = StorageFunctions.getDefaultState(), action) { 8 | switch (action.type) { 9 | case SocketContainerAction.CHANGE_CONNECTION_TYPE: 10 | return ContainerFunctions.updateConnectionType(state, action); 11 | case SocketContainerAction.CHANGE_HOST: 12 | return ContainerFunctions.updateConnectionHost(state, action); 13 | case SocketContainerAction.CHANGE_CHANNEL: 14 | return ContainerFunctions.updateConnectionChannel(state, action); 15 | case SocketContainerAction.UPDATE_INDEX: 16 | return ContainerFunctions.updatePlaygroundIndex(state, action); 17 | case SocketContainerAction.ADD_CONNECTION: 18 | return ContainerFunctions.addConnection(state, action); 19 | case SocketContainerAction.DELETE_TERMINAL_MESSAGES: 20 | return ContainerFunctions.deleteTerminalMessages(state, action); 21 | case SocketContainerAction.REMOVE_CONNECTION: 22 | return ContainerFunctions.removeConnection(state, action); 23 | 24 | case SocketConnectionAction.CONNECTED: 25 | return ConnectionFunctions.updateConnectionStatus(state, action, ConnectionStatus.CONNECTED); 26 | case SocketConnectionAction.DISCONNECT: 27 | return ConnectionFunctions.updateConnectionStatus( 28 | state, action, 29 | ConnectionStatus.DISCONNECTED, 30 | ); 31 | case SocketConnectionAction.RECEIVED: 32 | return ContainerFunctions.updateTerminalData(state, action); 33 | 34 | case StorageAction.READ_OFFLINE: 35 | return StorageFunctions.setOfflineState(state, action); 36 | 37 | default: 38 | return state; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/stores/AppStore.js: -------------------------------------------------------------------------------- 1 | import { createStore } from 'redux'; 2 | import rootReducer from '../reducers/RootReducer'; 3 | 4 | export default function makeStore() { 5 | return createStore(rootReducer); 6 | } 7 | -------------------------------------------------------------------------------- /src/stores/README.md: -------------------------------------------------------------------------------- 1 | # About this folder 2 | This folder will hold all of your **flux** stores. 3 | You can include them into your components like this: 4 | 5 | ```javascript 6 | let react = require('react/addons'); 7 | let MyStore = require('stores/MyStore'); 8 | class MyComponent extends React.Component { 9 | constructor(props) { 10 | super(props); 11 | MyStore.doSomething(); 12 | } 13 | } 14 | ``` 15 | -------------------------------------------------------------------------------- /src/styles/App.scss: -------------------------------------------------------------------------------- 1 | /* Base Application Styles */ 2 | 3 | .error-message { 4 | color: #E91E63; 5 | } 6 | 7 | .server-message { 8 | color: #3F51B5; 9 | } 10 | 11 | .client-message { 12 | color: #FF5722; 13 | } 14 | 15 | .status-message { 16 | color: #795548; 17 | } 18 | 19 | .highlight-title { 20 | color: #795548; 21 | font-weight: 500; 22 | } 23 | 24 | .cursor-pointer { 25 | cursor: pointer; 26 | } 27 | 28 | .selectable-text { 29 | -webkit-user-select: text; 30 | cursor: text; 31 | } 32 | 33 | .selected-item { 34 | background-color: #ccc; 35 | } 36 | 37 | .full-height { 38 | overflow-y: scroll; 39 | overflow-wrap: break-word; 40 | margin-right: 1px; 41 | padding-bottom: 10px; 42 | } 43 | 44 | .full-width { 45 | width: 100%; 46 | } 47 | 48 | .padding-left-30 { 49 | padding-left: 30px; 50 | } 51 | 52 | .no-padding { 53 | padding: 0 !important; 54 | } 55 | 56 | .margin-bottom-0 { 57 | margin-bottom: 0; 58 | } 59 | 60 | .margin-left-5 { 61 | margin-left: 5px; 62 | } 63 | 64 | .margin-left-15 { 65 | margin-left: 15px; 66 | } 67 | 68 | .margin-top-15 { 69 | margin-top: 15px; 70 | } 71 | 72 | .relative-container { 73 | position: relative; 74 | } 75 | 76 | .form-bottom-element { 77 | margin-top: 25px; 78 | } 79 | -------------------------------------------------------------------------------- /test/actions/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/williamcabrera4/chrome-app-websocket-tester/ef678d5c73dca8be0905dc35354085e70502172c/test/actions/.keep -------------------------------------------------------------------------------- /test/components/MainTest.js: -------------------------------------------------------------------------------- 1 | /*eslint-env node, mocha */ 2 | /*global expect */ 3 | /*eslint no-console: 0*/ 4 | 'use strict'; 5 | 6 | // Uncomment the following lines to use the react test utilities 7 | // import React from 'react/addons'; 8 | // const TestUtils = React.addons.TestUtils; 9 | import createComponent from 'helpers/shallowRenderHelper'; 10 | 11 | import Main from 'components/Main'; 12 | 13 | describe('MainComponent', () => { 14 | let MainComponent; 15 | 16 | beforeEach(() => { 17 | MainComponent = createComponent(Main); 18 | }); 19 | 20 | it('should have its component name as default className', () => { 21 | expect(MainComponent.props.className).to.equal('index'); 22 | }); 23 | }); 24 | -------------------------------------------------------------------------------- /test/config/ConfigTest.js: -------------------------------------------------------------------------------- 1 | /*eslint-env node, mocha */ 2 | /*global expect */ 3 | /*eslint no-console: 0*/ 4 | 'use strict'; 5 | 6 | import config from 'config'; 7 | 8 | describe('appEnvConfigTests', () => { 9 | it('should load app config file depending on current --env', () => { 10 | expect(config.appEnv).to.equal('test'); 11 | }); 12 | }); 13 | -------------------------------------------------------------------------------- /test/helpers/shallowRenderHelper.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Function to get the shallow output for a given component 3 | * As we are using phantom.js, we also need to include the fn.proto.bind shim! 4 | * 5 | * @see http://simonsmith.io/unit-testing-react-components-without-a-dom/ 6 | * @author somonsmith 7 | */ 8 | import React from 'react'; 9 | import TestUtils from 'react-addons-test-utils'; 10 | 11 | /** 12 | * Get the shallow rendered component 13 | * 14 | * @param {Object} component The component to return the output for 15 | * @param {Object} props [optional] The components properties 16 | * @param {Mixed} ...children [optional] List of children 17 | * @return {Object} Shallow rendered output 18 | */ 19 | export default function createComponent(component, props = {}, ...children) { 20 | const shallowRenderer = TestUtils.createRenderer(); 21 | shallowRenderer.render(React.createElement(component, props, children.length > 1 ? children : children[0])); 22 | return shallowRenderer.getRenderOutput(); 23 | } 24 | -------------------------------------------------------------------------------- /test/loadtests.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | require('core-js/fn/object/assign'); 4 | 5 | // Add support for all files in the test directory 6 | const testsContext = require.context('.', true, /(Test\.js$)|(Helper\.js$)/); 7 | testsContext.keys().forEach(testsContext); 8 | -------------------------------------------------------------------------------- /test/sources/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/williamcabrera4/chrome-app-websocket-tester/ef678d5c73dca8be0905dc35354085e70502172c/test/sources/.keep -------------------------------------------------------------------------------- /test/stores/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/williamcabrera4/chrome-app-websocket-tester/ef678d5c73dca8be0905dc35354085e70502172c/test/stores/.keep -------------------------------------------------------------------------------- /webpack.config.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var path = require('path'); 4 | var args = require('minimist')(process.argv.slice(2)); 5 | 6 | // List of allowed environments 7 | var allowedEnvs = ['dev', 'dist', 'test']; 8 | 9 | // Set the correct environment 10 | var env; 11 | if(args._.length > 0 && args._.indexOf('start') !== -1) { 12 | env = 'test'; 13 | } else if (args.env) { 14 | env = args.env; 15 | } else { 16 | env = 'dev'; 17 | } 18 | process.env.REACT_WEBPACK_ENV = env; 19 | 20 | // Get available configurations 21 | var configs = { 22 | base: require(path.join(__dirname, 'cfg/base')), 23 | dev: require(path.join(__dirname, 'cfg/dev')), 24 | dist: require(path.join(__dirname, 'cfg/dist')), 25 | test: require(path.join(__dirname, 'cfg/test')) 26 | }; 27 | 28 | /** 29 | * Get an allowed environment 30 | * @param {String} env 31 | * @return {String} 32 | */ 33 | function getValidEnv(env) { 34 | var isValid = env && env.length > 0 && allowedEnvs.indexOf(env) !== -1; 35 | return isValid ? env : 'dev'; 36 | } 37 | 38 | /** 39 | * Build the webpack configuration 40 | * @param {String} env Environment to use 41 | * @return {Object} Webpack config 42 | */ 43 | function buildConfig(env) { 44 | var usedEnv = getValidEnv(env); 45 | return configs[usedEnv]; 46 | } 47 | 48 | module.exports = buildConfig(env); 49 | --------------------------------------------------------------------------------