Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

primus

Package Overview
Dependencies
Maintainers
1
Versions
109
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

primus - npm Package Compare versions

Comparing version 1.1.2 to 1.1.3

6

example/index.js

@@ -67,4 +67,10 @@ 'use strict';

//
// Save the compiled file to the hard disk so it can also be distributed over
// cdn's or just be served by something else than the build-in path.
//
primus.save('primus.js');
//
// Everything is ready, listen to a port number to start the server.
//
server.listen(+argh.port || 8080);

12

forwarded.js

@@ -5,3 +5,3 @@ 'use strict';

* List of possible proxy headers that should be checked for the original client
* ip address and forwarded port.
* IP address and forwarded port.
*

@@ -46,3 +46,3 @@ * @type {Array}

* @param {Object} headers The received HTTP headers.
* @returns {String|Undefined} A ip address or nothing.
* @returns {String|Undefined} A IP address or nothing.
* @api private

@@ -56,7 +56,7 @@ */

// We've gotten a match on a HTTP header, we need to parse it further as it
// could consist of multiple hops. The pattern for multipe hops is:
// could consist of multiple hops. The pattern for multiple hops is:
//
// client, proxy, proxy, proxy, etc
// client, proxy, proxy, proxy, etc.
//
// So extracting the first ip should be suffecient.
// So extracting the first IP should be sufficient.
//

@@ -73,3 +73,3 @@ return {

*
* @param {Object} obj A socket like object that could contain a remoteAddress.
* @param {Object} obj A socket like object that could contain a `remoteAddress`.
* @param {Object} headers The received HTTP headers.

@@ -76,0 +76,0 @@ * @returns {String} The IP address.

@@ -231,2 +231,16 @@ 'use strict';

/**
* Broadcast the message to all connections.
*
* @param {Mixed} data The data you want to send.
* @api public
*/
Primus.prototype.write = function write(data) {
this.forEach(function forEach(spark) {
spark.write(data);
});
return this;
};
/**
* Install message parsers.

@@ -272,3 +286,3 @@ *

* Register a new message transformer. This allows you to easily manipulate incoming
* and outgoing data which is particulairy handy for plugins that want to send
* and outgoing data which is particularity handy for plugins that want to send
* meta data together with the messages.

@@ -303,3 +317,3 @@ *

//
// Add a simple export wrapper so it can be used as Node.js, amd or browser
// Add a simple export wrapper so it can be used as Node.js, AMD or browser
// client.

@@ -306,0 +320,0 @@ //

{
"name": "primus",
"version": "1.1.2",
"version": "1.1.3",
"description": "Primus is a simple abstraction around real-time frameworks. It allows you to easily switch between different frameworks without any code changes.",

@@ -8,3 +8,4 @@ "main": "index.js",

"integration": "NODE_ENV=testing ./node_modules/.bin/mocha $(find test -name '*.integration.js')",
"test": "NODE_ENV=testing ./node_modules/.bin/mocha $(find test -name '*.test.js')"
"test": "NODE_ENV=testing ./node_modules/.bin/mocha $(find test -name '*.test.js')",
"browserify": "browserify example/primus.js -o example/primus.browserify.js --standalone Primus"
},

@@ -11,0 +12,0 @@ "repository": {

@@ -139,10 +139,10 @@ 'use strict';

this.buffer = []; // Stores premature send data.
this.writable = true; // Silly stream compatibility.
this.readable = true; // Silly stream compatibility.
this.url = this.parse(url); // Parse the URL to a readable format.
this.backoff = options.reconnect || {}; // Stores the back off configuration.
this.attempt = null; // Current back off attempt.
this.readyState = Primus.CLOSED; // The readyState of the connection.
this.transformers = { // Message transformers.
this.buffer = []; // Stores premature send data.
this.writable = true; // Silly stream compatibility.
this.readable = true; // Silly stream compatibility.
this.url = this.parse(url); // Parse the URL to a readable format.
this.backoff = options.reconnect || {}; // Stores the back off configuration.
this.attempt = null; // Current back off attempt.
this.readyState = Primus.CLOSED; // The readyState of the connection.
this.transformers = { // Message transformers.
outgoing: [],

@@ -196,2 +196,3 @@ incoming: []

// etc.
// Remark: will this work for handling auth as well?
//

@@ -202,2 +203,10 @@ parse = function parse(url) {

//
// Browsers do not parse auth information, so we need to extract that from
// the URL.
//
if (~url.indexOf('@') && !a.auth) {
a.auth = a.href.slice(a.protocol.length + 2, a.href.indexOf(a.pathname)).split('@')[0];
}
return a;

@@ -540,3 +549,3 @@ };

server.push(this.url.protocol === 'https:' ? protocol +'s:' : protocol +':', '');
server.push(this.url.host, this.pathname.slice(1));
server.push(this.url.auth ? this.url.auth + '@' + this.url.host : this.url.host, this.pathname.slice(1));

@@ -543,0 +552,0 @@ //

@@ -36,2 +36,3 @@ # Primus

- [Connecting from the server](#connecting-from-the-server)
- [Events](#events)
- [Supported real-time frameworks](#supported-real-time-frameworks)

@@ -173,3 +174,3 @@ - [Engine.IO](#engineio)

silly transformer refuses to support it. Yes.. I'm looking at you,
browserchannel.
browserchannel and SockJS.

@@ -338,3 +339,3 @@ #### spark.id

```js
primus.on('reconnect', function (opts) {
primus.on('reconnecting', function (opts) {
console.log('Reconnecting in %d ms', opts.timeout);

@@ -452,2 +453,27 @@ console.log('This is attempt %d out of %d', opts.attempt, opts.retries);

### Events
Primus is build upon the Stream and EventEmitter interfaces. This is a summary
of the events emitted by Primus.
Event | Usage | Location | Description
----------------------|-------------|---------------|----------------------------------------
`outgoing::reconnect` | private | client | Transformer should reconnect.
`reconnecting` | **public** | client | We're scheduling a reconnect.
`reconnect` | **public** | client | Reconnect attempt is about to be made.
`outgoing::open` | private | client/spark | Transformer should connect.
`incoming::open` | private | client/spark | Transformer has connected.
`open` | **public** | client | Connection is open.
`incoming::error` | private | client | Transformer received error.
`error` | **public** | client/spark | An error happened.
`incoming::data` | private | client/server | Transformer received data.
`outgoing::data` | private | client | Transformer should write data.
`data` | **public** | client | We received data.
`incoming::end` | private | client | Transformer closed the connection.
`outgoing::end` | private | client | Transformer should close connection.
`end` | **public** | client | The connection has closed.
`connection` | **public** | server | We received a new connection.
`disconnection` | **public** | server | A connection closed.
`initialised` | **public** | server | The server is initialised.
### Supported Real-time Frameworks

@@ -459,3 +485,3 @@

Engine.io is the low level transport functionality of Socket.io 1.0. It supports
Engine.IO is the low level transport functionality of Socket.IO 1.0. It supports
multiple transports for creating a real-time connection. It uses transport

@@ -462,0 +488,0 @@ upgrading instead of downgrading which makes it more resilient to blocking

@@ -28,4 +28,4 @@ 'use strict';

this.writable = true; // Silly stream compatiblity.
this.readable = true; // Silly stream compatiblity.
this.writable = true; // Silly stream compatibility.
this.readable = true; // Silly stream compatibility.

@@ -43,3 +43,3 @@ //

//
// Lazy parse interface for ip address information. As nobody is always
// Lazy parse interface for IP address information. As nobody is always
// interested in this, we're going to defer parsing until it's actually needed.

@@ -46,0 +46,0 @@ //

@@ -7,3 +7,3 @@ 'use strict';

//
// Used to fake middleware's
// Used to fake middleware's as we don't have a next callback.
//

@@ -16,3 +16,3 @@ function noop() {}

* @constructor
* @param {Primus} primus Reference to the primus.
* @param {Primus} primus Reference to the Primus.
* @api public

@@ -22,3 +22,3 @@ */

this.Spark = primus.Spark; // Used by the Server to create a new connection.
this.primus = primus; // Reference to the primus instance.
this.primus = primus; // Reference to the Primus instance.
this.primusjs = null; // Path to the client library.

@@ -59,3 +59,3 @@ this.specfile = null; // Path to the Primus specification.

/**
* Create the server and attach the apropriate event listeners.
* Create the server and attach the appropriate event listeners.
*

@@ -99,3 +99,3 @@ * @api private

//
// Create a client url, this where we respond with our library. The path to
// Create a client URL, this where we respond with our library. The path to
// the server specification which can be used to retrieve the transformer that

@@ -162,3 +162,3 @@ // was used.

var buffy = new Buffer(head.length);
head.copy(upgrade);
head.copy(buffy);

@@ -165,0 +165,0 @@ if (!this.test(req)) return this.emit('previous::upgrade', req, socket, buffy);

@@ -26,3 +26,3 @@ 'use strict';

, socket // IP address location.
, {} // Optional query string.
, {} // Query string, not allowed by SockJS.
, socket.id // Unique connection id.

@@ -29,0 +29,0 @@ );

@@ -63,3 +63,3 @@ 'use strict';

//
// Attempt to reconnect the socket. It asumes that the `close` event is
// Attempt to reconnect the socket. It assumes that the `close` event is
// called if it failed to disconnect.

@@ -66,0 +66,0 @@ //

@@ -10,4 +10,4 @@ 'use strict';

// The client-logic to connect with the a server.
// The client-logic to connect with the server.
client: require('./client')
});

@@ -18,4 +18,4 @@ 'use strict';

var service = this.service = new WebSocketServer({
noServer: true,
clientTracking: false
clientTracking: false,
noServer: true
});

@@ -30,3 +30,3 @@

socket.upgradeReq.headers // HTTP request headers.
, socket.upgradeReq // Ip address location.
, socket.upgradeReq // IP address location.
, parse(socket.upgradeReq.url).query // Optional query string.

@@ -33,0 +33,0 @@ );

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc