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

omega-supreme

v3.0.1

Published

Known for his great strength and greater courage, Omega Supreme is the Autobots’ last line of defense against the Decepticons

Downloads

257

Readme

Omega Supreme

Version npmBuild StatusDependenciesCoverage StatusIRC channel

Known for his great strength and greater courage, Omega Supreme is the Autobots’ last line of defense against the Decepticons. He will stand unwaveringly against overwhelming odds, and although outwardly grim, he is known by those with enough insight to actually relish the importance of his task – Omega knows that if he falls, it is unlikely there will be any remaining Autobots to take his place, but he would not have it any other way.

In Primus mode, Omega Supreme has an incredible configurability, is able to broadcast a message with a single request and can distribute messages to single sparks. In place of his left hand, he is armed with authentication which can pulverize any attacker.

Or in plain English, omega-supreme allows you to broadcast messages to Primus using a regular HTTP request. These messages can be broadcasted to every single connection on the server, a single spark or an array of sparks. This allows other languages to easily write messages to your server without the need of creating a complex architecture.

Installation

npm install --save omega-supreme

Adding Omega Supreme to Primus

Omega Supreme should be added as a plugin in Primus. The plugin will also add a omega-supreme middleware which will intercept the incoming HTTP requests and will take care of the actual distribution of the message to every single connected client. Adding plugins in Primus is done using the .plugin(name, plugin) method. The options for the plugin can directly be added to the constructor of your Primus server so all the configuration of the server and the plugins is in one central location as illustrated in the example below:

'use strict';

var Primus = require('primus')
  , server = require('http').createServer();

var primus = new Primus(server, {
  /* Add the options here, in the Primus's options */
});

primus.plugin('omega-supreme', require('omega-supreme'));

server.listen(8080);

There are various options available, they are all optional but we highly recommend to change the password and username options to something unique. User name and password are used to authenticate the HTTP requests containing the information to bradcast. The following options can be configured:

  • method: HTTP method we should respond to, defaults to PUT.
  • password: Password for basic authorization, defaults to supreme.
  • username: Username for basic authorization, defaults to omega.
  • url: Access path, defaults to /primus/omega/supreme.
  • concurrently: How many servers can we broadcast to at once, defaults to 10.

Messaging

Now that you've added the omega-supreme plugin to your Primus server you can communicate/broadcast with it using plain HTTP requests. We make a couple assumptions to the data that is sent to the server:

  • The POST/PUT data is JSON encoded.
  • The request is made against the supplied URL option.
  • The request uses Basic Authentication with the supplied username and password.
  • The msg Property contains the data that needs to be sent to the connections.
  • The sparks Property can be an array of spark ids or a string which is the spark id. If no sparks property is supplied we assume that the given message needs to be broadcasted to every single connection on this server.

When your message has been successfully processed by the server it returns a JSON object with some information:

{
  ok: true,
  send: 10
}

The send property indicates the amount of connections we've written the message payload to. If your request has failed a 500 or 401 status code will be set and a slightly different JSON object will be returned:

{
  ok: false,
  reason: 'invalid data structure'
}

Primus.forward

primus.forward(server, msg, [sparks], fn);

In order to make the messaging even easier to use, omega-supreme adds a primus.forward method to your Primus server instance. It allows you to broadcast messages to the supplied server. It will only write the message to the supplied server if the supplied sparks are not on the current server.

Sending a message to a spark on a different server:

primus.forward('http://localhost:8080', {
  event: 'name'
}, 'ad8a-280z-18', function (err, data) {
  // data.send = 1 if it was successful.
});

Sending to a group of sparks:

primus.forward('http://localhost:8080', {
  event: 'name'
}, ['ad8a-280z-18', 'y97x-42480-13', /* more spark.id's */ ], function (err, data) {

});

Or just broadcasting by not supplying the optional sparks argument:

primus.forward('http://localhost:8080', {
  event: 'name'
}, function (err, data) {

});

In all the examples above, we've sent an event packet. If you're using primus-emit and you want to trigger custom events you should use this format:

primus.forward('http://localhost:8080', { emit: [ eventName, ...args ] }, fn);

Keep in mind that you don't have to write event blobs, you can write anything you want.

Customize the middleware behavior

omega-supreme allows you to customize the behavior of the middleware that is added with the plugin.

To define a custom logic, you can use the middleware option.

primus.options.middleware = middleware;

where middleware is a function which takes the following arguments:

Name | Type | Description --------------------|----------|---------------------- primus | Object | The Primus server instance parse | Function | The default parsing function has the following signature parse(primus, buff, res) where buff is the raw request body req | Object | The HTTP request res | Object | The HTTP response next | Function | The next callback

Example

This example adds a custom header to the response.

function middleware(primus, parse, req, res, next) {
  var raw = '';

  res.setHeader('omegamiddleware', 'true');

  req.setEncoding('utf8');
  req.on('data', function data(chunk) {
    raw += chunk;
  }).on('end', function end() {
    parse(primus, raw, res);
  });
}

Unofficial middleware

Omega Supreme Rooms Middleware

Version npm Build Status Dependencies Coverage Status

This middleware adds support for primus-rooms and automatically integrates with metroplex if included.

License

MIT

Omega Supreme