npm stats
  • Search
  • About
  • Repo
  • Sponsor
  • more
    • Search
    • About
    • Repo
    • Sponsor

Made by Antonio Ramirez

splinky-ws

0.0.2

@rvagg

npmHomeRepoSnykSocket
Downloads:1
$ npm install splinky-ws
DailyWeeklyMonthlyYearly

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.