-
-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
3,537 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
}) |
Oops, something went wrong.