Socket
Book a DemoInstallSign in
Socket

splinky-ws

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

splinky-ws

WebSockets for Splinky

latest
Source
npmnpm
Version
0.0.2
Version published
Maintainers
1
Created
Source

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.

Keywords

splinky

FAQs

Package last updated on 02 Dec 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts