Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
ngot committed Feb 10, 2017
0 parents commit fc94a6a
Show file tree
Hide file tree
Showing 15 changed files with 352 additions and 0 deletions.
26 changes: 26 additions & 0 deletions .autod.conf.js
@@ -0,0 +1,26 @@
'use strict';

module.exports = {
write: true,
prefix: '^',
test: [
'test',
'benchmark',
],
devdep: [
'egg',
'egg-ci',
'egg-bin',
'autod',
'eslint',
'eslint-config-egg',
'supertest',
'webstorm-disable-index',
],
exclude: [
'./test/fixtures',
'./docs',
'./coverage',
],
registry: 'https://r.cnpmjs.org',
};
2 changes: 2 additions & 0 deletions .eslintignore
@@ -0,0 +1,2 @@
test/fixtures
coverage
3 changes: 3 additions & 0 deletions .eslintrc
@@ -0,0 +1,3 @@
{
"extends": "eslint-config-egg"
}
9 changes: 9 additions & 0 deletions .gitignore
@@ -0,0 +1,9 @@
logs/
npm-debug.log
node_modules/
coverage/
.idea/
.vscode/
run/
.DS_Store
*.swp
11 changes: 11 additions & 0 deletions .travis.yml
@@ -0,0 +1,11 @@
sudo: false
language: node_js
node_js:
- '6'
- '7'
install:
- npm i npminstall && npminstall
script:
- npm run ci
after_script:
- npminstall codecov && codecov
21 changes: 21 additions & 0 deletions LICENSE
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) Alibaba Group Holding Limited and other contributors.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
61 changes: 61 additions & 0 deletions README.md
@@ -0,0 +1,61 @@
# egg-socket.io

[![NPM version][npm-image]][npm-url]
[![build status][travis-image]][travis-url]
[![Test coverage][codecov-image]][codecov-url]
[![David deps][david-image]][david-url]
[![Known Vulnerabilities][snyk-image]][snyk-url]
[![npm download][download-image]][download-url]

[npm-image]: https://img.shields.io/npm/v/egg-socket.io.svg?style=flat-square
[npm-url]: https://npmjs.org/package/egg-socket.io
[travis-image]: https://img.shields.io/travis/eggjs/egg-socket.io.svg?style=flat-square
[travis-url]: https://travis-ci.org/eggjs/egg-socket.io
[codecov-image]: https://img.shields.io/codecov/c/github/eggjs/egg-socket.io.svg?style=flat-square
[codecov-url]: https://codecov.io/github/eggjs/egg-socket.io?branch=master
[david-image]: https://img.shields.io/david/eggjs/egg-socket.io.svg?style=flat-square
[david-url]: https://david-dm.org/eggjs/egg-socket.io
[snyk-image]: https://snyk.io/test/npm/egg-socket.io/badge.svg?style=flat-square
[snyk-url]: https://snyk.io/test/npm/egg-socket.io
[download-image]: https://img.shields.io/npm/dm/egg-socket.io.svg?style=flat-square
[download-url]: https://npmjs.org/package/egg-socket.io

Still Work in Process.

## Install

```bash
$ npm i egg-socket.io --save
```

## Usage

```js
// {app_root}/config/plugin.js
exports.websocket = {
enable: true,
package: 'egg-socket.io',
};
```

## Configuration

```js
// {app_root}/config/config.default.js
exports.websocket = {
};
```

see [config/config.default.js](config/config.default.js) for more detail.

## Example

<!-- example here -->

## Questions & Suggestions

Please open an issue [here](https://github.com/eggjs/egg/issues).

## License

[MIT](LICENSE)
76 changes: 76 additions & 0 deletions README.zh_CN.md
@@ -0,0 +1,76 @@
# egg-socket.io

[![NPM version][npm-image]][npm-url]
[![build status][travis-image]][travis-url]
[![Test coverage][codecov-image]][codecov-url]
[![David deps][david-image]][david-url]
[![Known Vulnerabilities][snyk-image]][snyk-url]
[![npm download][download-image]][download-url]

[npm-image]: https://img.shields.io/npm/v/egg-socket.io.svg?style=flat-square
[npm-url]: https://npmjs.org/package/egg-socket.io
[travis-image]: https://img.shields.io/travis/eggjs/egg-socket.io.svg?style=flat-square
[travis-url]: https://travis-ci.org/eggjs/egg-socket.io
[codecov-image]: https://img.shields.io/codecov/c/github/eggjs/egg-socket.io.svg?style=flat-square
[codecov-url]: https://codecov.io/github/eggjs/egg-socket.io?branch=master
[david-image]: https://img.shields.io/david/eggjs/egg-socket.io.svg?style=flat-square
[david-url]: https://david-dm.org/eggjs/egg-socket.io
[snyk-image]: https://snyk.io/test/npm/egg-socket.io/badge.svg?style=flat-square
[snyk-url]: https://snyk.io/test/npm/egg-socket.io
[download-image]: https://img.shields.io/npm/dm/egg-socket.io.svg?style=flat-square
[download-url]: https://npmjs.org/package/egg-socket.io

<!--
Description here.
-->

## 依赖说明

### 依赖的 egg 版本

egg-socket.io 版本 | egg 1.x
--- | ---
1.x | 😁
0.x | ❌

### 依赖的插件
<!--
如果有依赖其它插件,请在这里特别说明。如
- security
- multipart
-->

## 开启插件

```js
// config/plugin.js
exports['socket.io'] = {
enable: true,
package: 'egg-socket.io',
};
```

## 使用场景

- Why and What: 描述为什么会有这个插件,它主要在完成一件什么事情。
尽可能描述详细。
- How: 描述这个插件是怎样使用的,具体的示例代码,甚至提供一个完整的示例,并给出链接。

## 详细配置

请到 [config/config.default.js](config/config.default.js) 查看详细配置项说明。

## 单元测试

<!-- 描述如何在单元测试中使用此插件,例如 schedule 如何触发。无则省略。-->

## 提问交流

请到 [egg issues](https://github.com/eggjs/egg/issues) 异步交流。

## License

[MIT](LICENSE)
18 changes: 18 additions & 0 deletions app.js
@@ -0,0 +1,18 @@
'use strict';

const sio = require('socket.io');
const sio_redis = require('socket.io-redis');

module.exports = app => {
const done = app.readyCallback('egg-websocket');

app.on('server', server => {
const io = sio(server);
io.adapter(sio_redis({
host: app.config['socket.io'].redis.host,
port: app.config['socket.io'].redis.port,
}));
app['socket.io'] = io;
done();
});
};
15 changes: 15 additions & 0 deletions appveyor.yml
@@ -0,0 +1,15 @@
environment:
matrix:
- nodejs_version: '6'
- nodejs_version: '7'

install:
- ps: Install-Product node $env:nodejs_version
- npm i npminstall && node_modules\.bin\npminstall

test_script:
- node --version
- npm --version
- npm run ci

build: off
13 changes: 13 additions & 0 deletions config/config.default.js
@@ -0,0 +1,13 @@
'use strict';

/**
* websocket default config
* @member Config#websocket
* @property {String} SOME_KEY - some description
*/
exports['socket.io'] = {
redis: {
host: '127.0.0.1',
port: 6379,
},
};
62 changes: 62 additions & 0 deletions package.json
@@ -0,0 +1,62 @@
{
"name": "egg-socket.io",
"version": "0.0.1",
"description": "egg plugin for socket.io",
"eggPlugin": {
"name": "socket.io"
},
"keywords": [
"egg",
"eggPlugin",
"egg-plugin",
"socket.io",
"websocket"
],
"dependencies": {
"socket.io": "^1.7.2",
"socket.io-redis": "^3.1.0"
},
"devDependencies": {
"autod": "^2.7.1",
"egg": "^0.7.0",
"egg-bin": "^1.10.0",
"egg-ci": "^1.1.0",
"egg-mock": "^2.0.0",
"eslint": "^3.13.1",
"eslint-config-egg": "^3.2.0",
"supertest": "^2.0.1",
"webstorm-disable-index": "^1.1.2"
},
"engines": {
"node": ">=6.0.0"
},
"scripts": {
"test": "npm run lint -- --fix && npm run test-local",
"test-local": "egg-bin test",
"cov": "egg-bin cov",
"lint": "eslint .",
"ci": "npm run lint && npm run cov",
"autod": "autod"
},
"files": [
"index.js",
"app.js",
"agent.js",
"config",
"app",
"lib"
],
"ci": {
"version": "6, 7"
},
"repository": {
"type": "git",
"url": "git+https://github.com/eggjs/egg-socket.io.git"
},
"bugs": {
"url": "https://github.com/eggjs/egg/issues"
},
"homepage": "https://github.com/eggjs/egg-socket.io#readme",
"author": "ngot <zhuanghengfei@gmail.com>",
"license": "MIT"
}
7 changes: 7 additions & 0 deletions test/fixtures/apps/websocket-test/app/router.js
@@ -0,0 +1,7 @@
'use strict';

module.exports = app => {
app.get('/', function* () {
this.body = 'hi, ' + app.plugins['socket.io'].name;
});
};
4 changes: 4 additions & 0 deletions test/fixtures/apps/websocket-test/package.json
@@ -0,0 +1,4 @@
{
"name": "socket.io-test",
"version": "0.0.1"
}
24 changes: 24 additions & 0 deletions test/websocket.test.js
@@ -0,0 +1,24 @@
'use strict';

const request = require('supertest');
const mm = require('egg-mock');

describe('test/socketio.test.js', () => {
let app;
before(() => {
app = mm.app({
baseDir: 'apps/socketio-test',
});
return app.ready();
});

after(() => app.close());
afterEach(mm.restore);

it('should GET /', () => {
return request(app.callback())
.get('/')
.expect('hi, websocket')
.expect(200);
});
});

0 comments on commit fc94a6a

Please sign in to comment.