splinky-ws

0.0.2 • Public • Published

Splinky-WS

WebSockets for Splinky

Uses Engine.IO to expose raw (relatively) WebSockets, you'll need to add sugar on top as required.

Usage

Splinky-WS exposes a simple helper function that will register startup and shutdown handlers to Splinky for you:

var splinkyWs = require('splinky-ws')
var splinky = require('splinky')({ port: 1337 })

splinkyWs(splinky)

// ... other Splinky config

splinky.listen()

Once you have Splinky-WS injected into a Splinky server you can write WebSocket handlers!

function wsHandler (server) {
  server.on('connection', function (socket) {
    socket.on('message', function (msg) {
      socket.send('pong: ' + msg)
    })
    socket.on('close', function () {
    	// ...
    })
  })
}

wsHandler.$config = {
  category: 'ws',
  path: '/splinky-websockets'
}

splinky.reg(wsHandler) // or perhaps make it available for a splinky.scan()

You can have multiple WS handlers in a Splinky server as long as you mount them at different paths. Remember to also supply a { path: '/...' } to match the path you specify in our handler config.

Use engine.io-stream if you want to turn your WS connection into a proper stream:

var EngineStream = require("engine.io-stream/eiostream")

function wsHandler (server) {
  server.on('connection', function (socket) {
    var stream = EngineStream(socket)
    // ...
  })
}

// ...

License

Splink-WS is Copyright (c) 2013 Rod Vagg @rvagg and licenced under the MIT licence. All rights not explicitly granted in the MIT license are reserved. See the included LICENSE file for more details.

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 0.0.2
    4
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 0.0.2
    4
  • 0.0.1
    2
  • 0.0.0
    2

Package Sidebar

Install

npm i splinky-ws

Weekly Downloads

4

Version

0.0.2

License

MIT

Last publish

Collaborators

  • rvagg