Giter Site home page Giter Site logo

nes's Introduction

@hapi/nes

WebSocket adapter plugin for hapi routes.

nes is part of the hapi ecosystem and was designed to work seamlessly with the hapi web framework and its other components (but works great on its own or with other frameworks). If you are using a different web framework and find this module useful, check out hapi โ€“ they work even better together.

Visit the hapi.dev Developer Portal for tutorials, documentation, and support

Useful resources

nes's People

Contributors

air1one avatar alfianwahid avatar buffcoder avatar cjihrig avatar devinivy avatar diego-deriv avatar dominykas avatar dwelle avatar erickwendel avatar geek avatar hueniverse avatar jarrodyellets avatar jaulz avatar kpdecker avatar lloydbenson avatar lpww avatar marsup avatar maxired avatar mtharrison avatar nallenscott avatar nargonath avatar notbobthebuilder avatar nwhitmont avatar p16 avatar peterdavehello avatar poeticninja avatar rankida avatar saboya avatar sericaia avatar sloria avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

nes's Issues

NES client required?

A potentially stupid question: does NES require the use of the NES client specifically or can any WS-compatible client be used? I only ask because I'm using Ember on the front-end and there is already a solid "emberized" client called ember-websockets that I was considering using.

Thanks as always for the great work.

Allow any authentication method when using token auth

When using token auth, there should be an option to:

  1. Use token used by the rest of the system vs. the custom token from nes
  2. Apply normal hapi authentication to the upgrade

The current system requires an additional request that can be avoided by those who have everything they need already and also seems like it would loose authentication on reconnect. If able to specify custom auth headers from the client and auth strategy on the upgrade endpoint, both of these can be avoided when already using tokens elsewhere in the system.

How will adding additional functionality work?

I'm curious if there are any plans for allowing users to add additional functionality to the library. For example, the primus project has a simple plugin system to modify and addend the simple API that it exposes. We use this to implement "rooms" and clustering across multiple app servers. It also allows addendums to the browser-facing library. I'm curious what type of pattern would be encouraged to solve similar problems.

Tests failing after latest Hapi updates

Failed tests:

  80) Listener subscription() ignores non participating connections:

      Cannot read property 'port' of null

      at nes/test/listener.js:182:82
      at hapi/lib/server.js:276:20
      at internals.Server._invoke (hapi/lib/server.js:344:16)
      at hapi/lib/server.js:268:14
      at done (hapi/node_modules/items/lib/index.js:30:25)
      at Server.finalize (hapi/lib/connection.js:176:9)
      at Server.g (events.js:260:16)
      at emitNone (events.js:72:20)
      at Server.emit (events.js:166:7)
      at emitListeningNT (net.js:1257:10)
      at doNTCallback1 (node.js:418:9)
      at process._tickDomainCallback (node.js:381:17)

  86) Listener _subscribe() subscribes to two paths on same subscription:

      actual expected

      {}

      Expected { Object (1445213006672:hayes:32242:ifx6icss:10000) } to equal specified value

      at nes/test/listener.js:356:74

Unknown response type: response

I have the following client code to be run in the browser using browserify.

var client = new Nes.Client(url);
client.connect(function () {
  client.request("/test", function (err, res) {
    console.log(err, res);
  });
});

However, when I run this code, I get an Uncaught TypeError: Illegal invocation fired at line 504 in client.js (nes).
This line is:

return self.onError(new Error('Received unknown response type: ' + update.type));

Not entirely sure what is going on there, but I added a console.log of the update.type just above that line and it returns response.

If i change line 483 in the same file from if (update.type === 'request') { to if (update.type === 'response') { the error goes away, and everything works as expected.

I have tried this using node v0.12.7 and v4.1.0 both server and client, reinstalling all node modules each time I switched but no luck. I am testing this in Google Chrome 46.0.2490.22

As a fix for now I am just changing the line as above, an actual fix would appreciated if possible, or tell me I am doing it wrong.

Subscribe Error

Not sure what I'm doing wrong but after reading the docs and setting up Nes with Hapi; upon trying to subscribe to a route from a client the Hapi server is crashing with this error.

var auth = this._connection.auth.lookup({ settings: { auth: match.route.au
TypeError: undefined is not a function

I have set auth to false but it seems to be trying to auth upon subscribing. I can gist the src code of Hapi and the Client if you want to take a look?

Drop support for non-protocol messages

Remove onUnknownMessage and change nes back to type since custom messages allow for similar behaviors with little overhead and the client doesn't handle unknown messages well currently.

How do I connect to specific "route id" from a client that are not using Nes/client?

I need to connect my client in that id = "hello", it's possible to do it without nes/client?
I'm able to receive PING and send data, but I only receive it from server:

{"type":"hello","id":1,"heartbeat":{"interval":15000,"timeout":5000}}

Here's the server implementation:

server.register(nes, function (err) {
  server.route({
    method: 'GET',
    path: '/h',
    config: {
      id: 'hello',
      handler: function (request, reply) {
        console.log('WS REQUEST: ', request);
        return reply('Hello: ', request.auth.credentials.name);
      }
    }
});

server.start(function (err) {
  if (err) {
    console.log('WEBSOCKET ERROR: ', err);
  }
});

Client side (using browser's websocket & angularjs):

var ws = new WebSocket("ws://localhost:5000");

ws.onopen = function () {
  console.log("Succeeded to open a connection");
};

ws.onerror = function () {
  console.log("Failed to open a connection");
};

ws.onmessage = function (message) {
  if (message.data) {
    console.log('MESSAGE: ', message.data);
  }
};

Function that send message to server:

var message = {
  "type": "hello",
  "id": 1,
  "auth": {
    "headers": {
      "authorization": 'token'
    }
  }
};

svc.ws.send(JSON.stringify(message));

Any help is appreciated, thanks.

Add disconnection callback

Ideally something like onDisconnect for the plugin options or a calllback or event on the socket instances themselves.

The goal here is to allow cleanup of anything that may have been setup in the socket's state during setup or exec.

Add message metadata for publish

Add the ability to include metadata to a particular message that is passed to the filter method, but is not sent to the final consumer.

This may be used, for example, to prevent sending a message to the session that generated the message in the first place.

Subscriptions are not cleaned on client disconnect

It does not look like subscriptions are being cleaned when the client disconnects, leaving the possibility of leaking.

With this diff, this test will now fail as the subscribers object has length of 2, maintaining a reference to the disconnected client.

diff --git a/test/client.js b/test/client.js
index a61a833..e19c6df 100755
--- a/test/client.js
+++ b/test/client.js
@@ -748,6 +748,10 @@ describe('Browser', function () {
                                     client2.disconnect();
                                     setTimeout(function () {

+                                        var listener = server.connections[0].plugins.nes._listener;
+                                        var match = listener._router.route('sub', '/');
+                                        expect(match.route.subscribers.length).to.equal(1);
+
                                         server.publish('/', 'heya');
                                     }, 10);
                                 }, 10);

Allow handler to handle unknown message types

Users should be able to handle messages not understood by nes on the websocket channel with a custom handler. The primary use case here is supporting legacy clients who are not using the nes-based protocol and routing.

Provide method to iterate over currently connected sockets

Ideally there would be something like server.sockets() that returns an array of all connected sockets, but generally looking for a way to access the Socket instances without having apps keep their own records of who is connected and not.

Document protocol schema

We should document all of the messages that can be sent to allow for non-javascript implementations to have something somewhat formalized to work from.

Allow for custom callback data to Client.connect()

It would be nice to allow for the server to push init data to the client on connection, ex:

client.connect(function(err, data) {
  myState.clientId = data.clientId;
});

Not sure if this is possible through current hello implementation, but filing to track the feature.

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.