Giter Club home page Giter Club logo

uws's Introduction

Fork of uws bindings for discord.js

This fork is for internal usage in the discord.js library only.

We will provide no support to anyone relying or using it outside of our main project.














Original README

UWS IS NOT AN ELECTRON MODULE

uws is a replacement module for ws which allows, but doesn't guarantee (certainly not when paired with Socket.IO), significant performance and memory-usage improvements. This module is specifically only compatible with Node.js and is installed only like so:

  • uws can use node-gyp and can recompile itself at installation but does not require so.
  • npm installation never fails, but require('uws') will throw if all of the below points hold true:
    • There was no C++11 compiler available at installation.
    • Your system is not an official Tier 1 Node.js platform.

Keep in mind

You can't fix a clogged up system by only fixing part of the problem. Swapping to uws can have dramatical effects if your entire pipeline works well. Socket.IO, SocketCluster and other such mass bloat will not give you desired results as those projects already, from the start, are the bottleneck.

Read more about other horrible Node.js projects here

Usage

uws tries to mimic ws as closely as possible without sacrificing too much performance. In most cases you simply swap require('ws') with require('uws'):

var WebSocketServer = require('uws').Server;
var wss = new WebSocketServer({ port: 3000 });

function onMessage(message) {
    console.log('received: ' + message);
}

wss.on('connection', function(ws) {
    ws.on('message', onMessage);
    ws.send('something');
});
Deviations from ws

There are some important incompatibilities with ws though, we aim to be ~90% compatible but will never implement behavior that is deemed too inefficient:

  • Binary data is passed zero-copy as an ArrayBuffer. This means you need to copy it to keep it past the callback. It also means you need to convert it with Buffer.from(message) if you expect a Node.js Buffer.
  • webSocket._socket is not a net.Socket, it is just a getter function with very basic functionalities.
  • webSocket._socket.remote... might fail, you need to cache it at connection.
  • webSocket acts like an EventEmitter with one listener per event maximum.
  • webSocket.upgradeReq is only valid during execution of the connection handler. If you want to keep properties of the upgradeReq for the entire lifetime of the webSocket you better attach that specific property to the webSocket at connection.

uws's People

Contributors

icrawl avatar hermanbanken avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.