passing-notes-websocket
v1.1.3
Published
A middleware for accepting WebSocket connections
Downloads
4
Readme
passing-notes-websocket
A middleware for accepting WebSocket connections
Usage
Install passing-notes-websocket by running:
yarn add passing-notes-websocket
Then, compose it with other middleware, or at least a default handler:
import {compose} from 'passing-notes'
import serveWebSocket from 'passing-notes-websocket'
export default compose(
serveWebSocket((ws) => {
ws.on('message', (message) => {
console.log(message)
})
ws.send('Hello World!')
}),
() => () => ({status: 404})
)
serveWebSocket
will look for HTTP/1.1 Upgrade requests that ask for
Upgrade: websocket
. It will then negotiate the upgrade and provide a
WebSocket
object. Otherwise, it delegates
to the next middleware.