├── .autod.conf.js ├── .eslintignore ├── .eslintrc ├── .github └── PULL_REQUEST_TEMPLATE.md ├── .gitignore ├── LICENSE ├── README.md ├── README.zh_CN.md ├── agent.js ├── app.js ├── config └── config.default.js ├── package.json └── test ├── fixtures └── apps │ └── websocket-test │ ├── app │ └── router.js │ └── package.json └── websocket.test.js /.autod.conf.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = { 4 | write: true, 5 | prefix: '^', 6 | test: [ 7 | 'test', 8 | 'benchmark', 9 | ], 10 | devdep: [ 11 | 'egg', 12 | 'egg-ci', 13 | 'egg-bin', 14 | 'autod', 15 | 'eslint', 16 | 'eslint-config-egg', 17 | 'supertest', 18 | 'webstorm-disable-index', 19 | ], 20 | exclude: [ 21 | './test/fixtures', 22 | './docs', 23 | './coverage', 24 | ], 25 | registry: 'https://r.cnpmjs.org', 26 | }; 27 | -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | test/fixtures 2 | coverage 3 | -------------------------------------------------------------------------------- /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "eslint-config-egg" 3 | } 4 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 10 | 11 | ##### Checklist 12 | 13 | 14 | - [ ] `npm test` passes 15 | - [ ] tests and/or benchmarks are included 16 | - [ ] documentation is changed or added 17 | - [ ] commit message follows commit guidelines 18 | 19 | ##### Affected core subsystem(s) 20 | 21 | 22 | 23 | ##### Description of change 24 | 25 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | logs/ 2 | npm-debug.log 3 | node_modules/ 4 | coverage/ 5 | .idea/ 6 | run/ 7 | .DS_Store 8 | *.swp 9 | 10 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) Alibaba Group Holding Limited and other contributors. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # egg-websocket 2 | 3 | [![NPM version][npm-image]][npm-url] 4 | [![build status][travis-image]][travis-url] 5 | [![Test coverage][codecov-image]][codecov-url] 6 | [![David deps][david-image]][david-url] 7 | [![Known Vulnerabilities][snyk-image]][snyk-url] 8 | [![npm download][download-image]][download-url] 9 | 10 | [npm-image]: https://img.shields.io/npm/v/egg-websocket.svg?style=flat-square 11 | [npm-url]: https://npmjs.org/package/egg-websocket 12 | [travis-image]: https://img.shields.io/travis/eggjs/egg-websocket.svg?style=flat-square 13 | [travis-url]: https://travis-ci.org/eggjs/egg-websocket 14 | [codecov-image]: https://img.shields.io/codecov/c/github/eggjs/egg-websocket.svg?style=flat-square 15 | [codecov-url]: https://codecov.io/github/eggjs/egg-websocket?branch=master 16 | [david-image]: https://img.shields.io/david/eggjs/egg-websocket.svg?style=flat-square 17 | [david-url]: https://david-dm.org/eggjs/egg-websocket 18 | [snyk-image]: https://snyk.io/test/npm/egg-websocket/badge.svg?style=flat-square 19 | [snyk-url]: https://snyk.io/test/npm/egg-websocket 20 | [download-image]: https://img.shields.io/npm/dm/egg-websocket.svg?style=flat-square 21 | [download-url]: https://npmjs.org/package/egg-websocket 22 | 23 | Still Work in Process. 24 | 25 | ## Install 26 | 27 | ```bash 28 | $ npm i egg-websocket --save 29 | ``` 30 | 31 | ## Usage 32 | 33 | ```js 34 | // {app_root}/config/plugin.js 35 | exports.websocket = { 36 | enable: true, 37 | package: 'egg-websocket', 38 | }; 39 | ``` 40 | 41 | ## Configuration 42 | 43 | ```js 44 | // {app_root}/config/config.default.js 45 | exports.websocket = { 46 | }; 47 | ``` 48 | 49 | see [config/config.default.js](config/config.default.js) for more detail. 50 | 51 | ## Example 52 | 53 | 54 | 55 | ## Questions & Suggestions 56 | 57 | Please open an issue [here](https://github.com/eggjs/egg/issues). 58 | 59 | ## License 60 | 61 | [MIT](LICENSE) 62 | -------------------------------------------------------------------------------- /README.zh_CN.md: -------------------------------------------------------------------------------- 1 | # egg-websocket 2 | 3 | [![NPM version][npm-image]][npm-url] 4 | [![build status][travis-image]][travis-url] 5 | [![Test coverage][codecov-image]][codecov-url] 6 | [![David deps][david-image]][david-url] 7 | [![Known Vulnerabilities][snyk-image]][snyk-url] 8 | [![npm download][download-image]][download-url] 9 | 10 | [npm-image]: https://img.shields.io/npm/v/egg-websocket.svg?style=flat-square 11 | [npm-url]: https://npmjs.org/package/egg-websocket 12 | [travis-image]: https://img.shields.io/travis/eggjs/egg-websocket.svg?style=flat-square 13 | [travis-url]: https://travis-ci.org/eggjs/egg-websocket 14 | [codecov-image]: https://img.shields.io/codecov/c/github/eggjs/egg-websocket.svg?style=flat-square 15 | [codecov-url]: https://codecov.io/github/eggjs/egg-websocket?branch=master 16 | [david-image]: https://img.shields.io/david/eggjs/egg-websocket.svg?style=flat-square 17 | [david-url]: https://david-dm.org/eggjs/egg-websocket 18 | [snyk-image]: https://snyk.io/test/npm/egg-websocket/badge.svg?style=flat-square 19 | [snyk-url]: https://snyk.io/test/npm/egg-websocket 20 | [download-image]: https://img.shields.io/npm/dm/egg-websocket.svg?style=flat-square 21 | [download-url]: https://npmjs.org/package/egg-websocket 22 | 23 | 26 | 27 | ## 依赖说明 28 | 29 | ### 依赖的 egg 版本 30 | 31 | egg-websocket 版本 | egg 1.x 32 | --- | --- 33 | 1.x | 😁 34 | 0.x | ❌ 35 | 36 | ### 依赖的插件 37 | 45 | 46 | ## 开启插件 47 | 48 | ```js 49 | // config/plugin.js 50 | exports.websocket = { 51 | enable: true, 52 | package: 'egg-websocket', 53 | }; 54 | ``` 55 | 56 | ## 使用场景 57 | 58 | - Why and What: 描述为什么会有这个插件,它主要在完成一件什么事情。 59 | 尽可能描述详细。 60 | - How: 描述这个插件是怎样使用的,具体的示例代码,甚至提供一个完整的示例,并给出链接。 61 | 62 | ## 详细配置 63 | 64 | 请到 [config/config.default.js](config/config.default.js) 查看详细配置项说明。 65 | 66 | ## 单元测试 67 | 68 | 69 | 70 | ## 提问交流 71 | 72 | 请到 [egg issues](https://github.com/eggjs/egg/issues) 异步交流。 73 | 74 | ## License 75 | 76 | [MIT](LICENSE) 77 | -------------------------------------------------------------------------------- /agent.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = agent => { 4 | console.log('agent.config.env =', agent.config.env); 5 | }; 6 | -------------------------------------------------------------------------------- /app.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = app => { 4 | console.log('app.config.env =', app.config.env); 5 | }; 6 | -------------------------------------------------------------------------------- /config/config.default.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | /** 4 | * websocket default config 5 | * @member Config#websocket 6 | * @property {String} SOME_KEY - some description 7 | */ 8 | exports.websocket = { 9 | 10 | }; 11 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "egg-websocket", 3 | "version": "0.0.1", 4 | "description": "egg plugin for websocket", 5 | "eggPlugin": { 6 | "name": "websocket" 7 | }, 8 | "keywords": [ 9 | "egg", 10 | "eggPlugin", 11 | "egg-plugin", 12 | "websocket" 13 | ], 14 | "dependencies": {}, 15 | "devDependencies": { 16 | "autod": "^2.7.1", 17 | "egg": "^0.7.0", 18 | "egg-bin": "^1.10.0", 19 | "egg-ci": "^1.1.0", 20 | "egg-mock": "^2.0.0", 21 | "eslint": "^3.13.1", 22 | "eslint-config-egg": "^3.2.0", 23 | "supertest": "^2.0.1", 24 | "webstorm-disable-index": "^1.1.2" 25 | }, 26 | "engines": { 27 | "node": ">=6.0.0" 28 | }, 29 | "scripts": { 30 | "test": "npm run lint -- --fix && npm run test-local", 31 | "test-local": "egg-bin test", 32 | "cov": "egg-bin cov", 33 | "lint": "eslint .", 34 | "ci": "npm run lint && npm run cov", 35 | "autod": "autod" 36 | }, 37 | "files": [ 38 | "index.js", 39 | "app.js", 40 | "agent.js", 41 | "config", 42 | "app", 43 | "lib" 44 | ], 45 | "ci": { 46 | "version": "6, 7" 47 | }, 48 | "repository": { 49 | "type": "git", 50 | "url": "git+https://github.com/eggjs/egg-websocket.git" 51 | }, 52 | "bugs": { 53 | "url": "https://github.com/eggjs/egg/issues" 54 | }, 55 | "homepage": "https://github.com/eggjs/egg-websocket#readme", 56 | "author": "TZ ", 57 | "license": "MIT" 58 | } 59 | -------------------------------------------------------------------------------- /test/fixtures/apps/websocket-test/app/router.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | module.exports = app => { 4 | app.get('/', function* () { 5 | this.body = 'hi, ' + app.plugins['websocket'].name; 6 | }); 7 | }; 8 | -------------------------------------------------------------------------------- /test/fixtures/apps/websocket-test/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "websocket-test", 3 | "version": "0.0.1" 4 | } -------------------------------------------------------------------------------- /test/websocket.test.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const request = require('supertest'); 4 | const mm = require('egg-mock'); 5 | 6 | describe('test/websocket.test.js', () => { 7 | let app; 8 | before(() => { 9 | app = mm.app({ 10 | baseDir: 'apps/websocket-test', 11 | }); 12 | return app.ready(); 13 | }); 14 | 15 | after(() => app.close()); 16 | afterEach(mm.restore); 17 | 18 | it('should GET /', () => { 19 | return request(app.callback()) 20 | .get('/') 21 | .expect('hi, websocket') 22 | .expect(200); 23 | }); 24 | }); 25 | --------------------------------------------------------------------------------