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

comunicator

v3.1.0

Published

The 720kb notifier api (atm it uses websockets)

Downloads

20

Readme

Comunicator

A way to enstablish a websocket connection between users, using your application and your back end.

It uses a well defined protocol in order to simplify the integration with other back ends (even if in different languages).

The client could be used in AngularJS, via provider, or in plain javascript.

Comunicator is developed by 720kb.

Requirements and Dependencies

This implementation needs a browser that is capable to instantiate websockets, due to the fact that it wraps a websocket.

The comunicator is an Observable and uses the RxJs implementation.

The AngularJS provider needs at least AngularJS version 1.2.

Installation

Comunicator could be installed via npm or bower:

NPM

$ npm install --save comunicator

Bower

$ bower install --save comunicator

Node.js side

In node.js you have to instantiate Comunicator passing a websocket configuration object and a jwtSalt as showed here:

const jwtSalt = '_super_secret_salt_12345'
  , Comunicator = require('comunicator').Comunicator
  , theComunicator = new Comunicator({
    'host': '::',
    'port': 3000
  }, jwtSalt);

The websocket configuration object refers to the options passed to ws.Server constructor.

The methods exposed are:

  • broadcast(whoami, what): this sends what to everyone who is connected. The message is sent to the others with whoami as sender;

  • sendTo(whoami, who, what): this sends what to who. The message is sent to who with whoami as sender;

  • isUserPresent(who): checks if who is connected to Comunicator.

A subscriber to the comunicator could receive:

{
  'type': 'ready'
}

When the underlined websocket is instantiated;

{
  'type': 'open',
  'whoami': <a_websocket>
}

When a user is conneced to the server;

{
  'type': 'user-leave',
  'whoami': <the_user_identifier>
}

When a user closes the Comunicator connection;

{
  'type': 'user-joined',
  'whoami': <the_user_identifier>
}

When a user fulfills the connection in Comunicator;

{
  'type': 'no-pending-messages',
  'whoami': <the_user_identifier>
}

When there aren't messages for the identified user;

{
  'type': 'message-arrived',
  'whoami': <sender>,  
  'who': <recipient | *>,
  'what': <message payload>
}

When a message is arrived.

In broadcast-ed messages the recipient is * due to the fact that the message is for everyone;

Client side

The files you need are:

  • dist/frontend/comunicator-min.js for the plain javascript implementation;
  • dist/frontend/angular-comunicator-min.js for the AngularJS implementation.

There are also the not minified versions available in the same folder (without min).

If you are about to use the AngularJS provider you have to include the module that brings the provider, for example:

angular.module('app', [
  '720kb.comunicator'
 ]);

Plain javascript

Comunicator client is an UMD module (it can be used also in node.js programs). After you load the comunicator file with what you prefer (SystemJS, RequireJs, Browserify, ...) to use it you need to create an instance of comunicator, for example:

  const comunicator = new Comunicator(<backend comunicator url>);

or

  const comunicator = new Comunicator(<an already instantiated websocket>);

The comunicator client object expose this methods:

  • userIsPresent(whoami, token): this sends to comunicator server who the client is and which jwt token will be used;

  • broadcast(what, managed): this sends what to everyone who is connected;

  • sendTo(who, what, managed): this sends what to who.

and also have the whoAmI property that returns the client identifier stored in comunicator client.

As you can see sendTo and broadcast methods have the managed parameter. Comunicator server forwards messages from client to client by default. If a client doesn't want this behaviour, should call the method with a truthy value to managed parameter.

A subscriber to the comunicator client could receive:

{
  'type': 'open',
  'whoami': <websocket_opened>
}

When the underlined comunicator websocket is opened;

{
  'type': 'joined',
  'whoami': <the_user_identifier>
}

When the comunicator client has finished the joining process;

{
  'type': 'to-me',
  'whoami': <sender>,
  'who': <recipient>,
  'what': <message payload>
}

When the comunicator client receives a directly sent message.

{
  'type': 'to-all',
  'whoami': <sender>,
  'what': <message payload>
}

When the comunicator client receives a broadcasted message.

AngularJS

The provider exposes the setComunicatorServerURL(<backend comunicator url>|<already instantiated websocket>) that must be called to instantiate and configure the Comunicator object.

Done that, the Comunicator object is available via the provider. Please note that you need to run $scope.$apply() method to update your view after a reaction from comunicator.

Contributing

We will be very grateful if you help us making this project grow up. Feel free to contribute by forking, opening issues, pull requests etc.

License

The MIT License (MIT)

Copyright (c) 2014 Dario Andrei, Filippo Oretti

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.