npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

websocketserverhelper

v2.1.0

Published

Minimalist wrapper for `WebSocketServer` object from NPM `websocket` package.

Downloads

6

Readme

WebSocketServerHelper

Minimalist wrapper for WebSocketServer object from NPM websocket package. https://www.npmjs.com/package/websocket

Features :

  • easy setup ;
  • transparent event logging ;
  • decouple connection handling from generic server logic.

This module is good for experimenting and quick prototyping due to its easy setup and rich log output. However it might not be suited when precise configurations, performances, or security are required.

Minimalistic example

var wsServer = require('websocketserverhelper').createServer(
  ['echo'],
  {
    handleConnection: function(pConnection) {
      pConnection.on('message', function(pMessageRaw) {
        pConnection.send(pMessageRaw.utf8Data);
      });
    }
  }
);
wsServer.start(36521);

Module documentation

Exported methods

createServer([protocols], [connectionHandler], [httpServer])

Creates and returns a new Server object with the given connection handler.

protocols is the list of websocket sub-protocols supported by the server. For every new connection the server selects the first sub-protocol requested by the client that is in this list. If none of the protocols requested by the client is supported by the server, or if no protocol is requested, no sub-protocol is selected. In this case, if the acceptUndefinedProtocol property is set to false then the connection is rejected. Otherwise the connection is accepted with no sub-protocol.
This parameter defaults to an empty array if omitted, meaning that no protocol will ever be selected.
The list of supported protocols can be (re)set via the supportedProtocols property.

connectionHandler must provide a function handleConnection which will be called for each connection the server receives, with the WebSocketConnection object passed as first parameter. The handler can be (re)set via the connectionHandler property.

httpServer is the supportive HTTP server (native Node's http.Server object) used by the websocket server. If omitted or invalid a default server is created. The server can be accessed via the httpServer property.

'Server' object Documentation

Constructor

Server([protocols], [connectionHandler], [httpServer])

Init a new WebSocket server. See createServer() above.

Properties

acceptUndefinedProtocol

If true, the server will be allowed not to select any sub-protocol, if it thinks it should do so based on the protocols requested by the client. If false, any connection that make the server not select any sub-protocol will be rejected.

Default value is true.

connectionHandler

The connection handler called each time a client connect to the server. This property is set by the constructor. See constructor documentation for more infos. This property can be (re)set at any time.

httpServer

The supportive HTTP server used by the websocket server (native Node's http.Server object). This property is set by the constructor. See constructor documentation for more infos. Re(setting) this property has no effect.

socketServer

The underlying native WebSocketServer object.

supportedProtocols

Array of websocket sub-protocols supported by the server. This property is set by the constructor. See constructor documentation for more infos. This property can be (re)set at any time.

Methods

start([port])

Start the server on specified port. If port is omitted a random port is selected.

Infos

WebSocket overview on MDN : https://developer.mozilla.org/en-US/docs/Web/API/WebSocket
NPM websocket package : https://www.npmjs.com/package/websocket

Contact

Alexandre Bintz [email protected]
Comments and suggestions are welcome.