GitXplorerGitXplorer
d

uvs

public
1 stars
0 forks
0 issues

Commits

List of commits on branch master.
Unverified
564522011cd0f3df50a63040234b2b25ca80d311

bumped up uws version

ddanielkov committed 8 years ago
Unverified
388244e2427a945f771c65cea52a522592d61b2f

added readme

ddanielkov committed 8 years ago
Unverified
e1fcedbd9e0753443e4f7052930c1665799c0987

removed unnecessary dependencies

ddanielkov committed 8 years ago
Unverified
7000b5c19ef601efe822277eeb02cc8b890a749b

modified tests

ddanielkov committed 8 years ago
Unverified
e7e4067910115c9bb25166f3da9850098b5ddeae

removed redundant file

ddanielkov committed 8 years ago
Unverified
449e1697f82cbbefc95196ec120f548dabcf488f

initial commit

ddanielkov committed 8 years ago

README

The README file for this repository.

Uvs

Faster WebSocket Client and Server implementation.


UVS aims to be very lightweight, yet brings some very straight-forward messaging functionality to websockets. It uses UWS as its WebSocket engine, which means it's very fast, even compared to some of the non-wrapper implemenations. The whole idea is to wrap the regular WebSocket implementation in an (also very fast) Event Emitter instance, called Evs.

Usage

Using Uvs is simple. On the server, all it takes is:

const Server = require('uvs').Server

const wss = new Server({port: 3000})

wss.on('connection', ws => {
  ws.send('id', ws.id)
  ws.on('message', data => {
    wss.send('message', data)
  })
})

The options to the Server match exactly those of UWS.

The ws is an instance of Socket, which has a unique id property. This allows you to easily differentiate between WebSocket connections and therefore handle authentication and 1 to 1 messaging very easily.

You can provide any String as the first parameter of on() and send() methods, which will identify the type of message the client will listen to. For example:

ws.send('something', {
  message: 'Hello, World!'
})

... would yield to the following message on the client:

import Client from 'uvs'

Client.on('open', ws => {
  ws.on('something', data => {
    console.log(data) // this will log a JS Object with { message: 'Hello, World!' }
  })
})

Socket instances emit the usual WebSocket events, normally, like 'error', 'close' and 'open'. These are native.

All in all, it's just a convenience wrapper for regular WebSockets, like Socket.io, but without fallbacks and of course much smaller and faster.

Some cooler methods are also added, like multiple listeners and special types of 'listener middleware'. This is because Uvs wraps WebSocket in Evs. Anything Evs can do, Uvs can also. I suggest reading up on the docs for Evs, here.

Contributing

Contributions are always welcome. You can send PR's any time, but make sure you submit an issue first.