Skip to content

Commit

Permalink
Initial implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
mcollina committed Jun 4, 2017
1 parent fbbfa7b commit ffa34ac
Show file tree
Hide file tree
Showing 6 changed files with 3,537 additions and 1 deletion.
10 changes: 10 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
language: node_js
node_js:
- "8"
- "7"
- "6"
- "4"
notifications:
email:
on_success: never
on_failure: always
32 changes: 31 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,32 @@
# fastify-websocket
basic websocket support for fastify

WebSocket support for [Fastify](https://github.com/fastify/fastify).
Built upon [websocket-stream](http://npm.im/websocket-stream).

## Example

```js
'use strict'

const fastify = require('fastify')()

fastify.register(require('fastify-websocket'), { handle })

function handle (conn) {
conn.pipe(conn) // creates a echo server
}

fastify.listen(0)
```

## TODO

* [ ] Support Hooks?

## Acknowledgements

This project is kindly sponsored by [nearForm](http://nearform.com).

## License

Licensed under [MIT](./LICENSE).
20 changes: 20 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'use strict'

const fp = require('fastify-plugin')
const websocket = require('websocket-stream')

module.exports = fp(function (fastify, opts, next) {
var handle = opts.handle

if (typeof handle !== 'function') {
return next(new Error('invalid handle function'))
}

var wss = websocket.createServer({
server: fastify.server
}, handle)

fastify.decorate('websocketServer', wss)

next()
})
Loading

0 comments on commit ffa34ac

Please sign in to comment.