Socket
Socket
Sign inDemoInstall

pubnub

Package Overview
Dependencies
Maintainers
1
Versions
224
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pubnub - npm Package Compare versions

Comparing version 3.6.2 to 3.6.3

examples/publish-via-proxy.js

24

examples/hello.js

@@ -16,17 +16,13 @@ /* ---------------------------------------------------------------------------

pubnub.publish({
post: false,
channel : 'PubNubTest_RX',
message : { 'test' : 'f?ds' },
callback : function(details) {
var success = details[0]
, response = details[1];
console.log(pubnub.get_version());
/* ---------------------------------------------------------------------------
Listen for Messages
--------------------------------------------------------------------------- */
pubnub.subscribe({
channel : "a",
callback : function(message) {
console.log( " > ", message );
},
error : function(r) {
console.log(JSON.stringify(r));
},
presence : function(r) { console.log(JSON.stringify(r)) }
if (success) console.log( "Success!", response );
if (!success) console.log( "Fail!", response );
}
});
{
"name": "pubnub",
"preferGlobal": false,
"version": "3.6.2",
"version": "3.6.3",
"author": "PubNub <stephen@pubnub.com>",

@@ -6,0 +6,0 @@ "description": "Publish & Subscribe Real-time Messaging with PubNub",

@@ -1,2 +0,2 @@

// Version: 3.6.2
// Version: 3.6.3
var NOW = 1

@@ -15,3 +15,3 @@ , READY = false

, PRESENCE_HB_DEFAULT = 30
, SDK_VER = '3.6.2'
, SDK_VER = '3.6.3'
, REPL = /{([\w\-]+)}/g;

@@ -133,5 +133,5 @@

}
function isArray(arg) {
var type = Object.prototype.toString.call(arg);
return ( type === "[object Array]" || type === "[object NodeList]" || type === "[object ScriptBridgingArrayProxyObject]");
return !!arg && (Array.isArray && Array.isArray(arg) || typeof(arg.length) === "number")
}

@@ -144,6 +144,6 @@

*/
function each( o, f, old_logic) {
function each( o, f) {
if ( !o || !f ) return;
if ( isArray(o) || ( old_logic && typeof o[0] != 'undefined' ) )
if ( isArray(o) )
for ( var i = 0, l = o.length; i < l; )

@@ -212,3 +212,2 @@ f.call( o[i], o[i], i++ );

, SECRET_KEY = setup['secret_key'] || ''
, PNSDK = setup['PNSDK'] || ''
, hmac_SHA256 = setup['hmac_SHA256']

@@ -238,2 +237,3 @@ , SSL = setup['ssl'] ? 's' : ''

, xdr = setup['xdr']
, params = setup['params'] || {}
, error = setup['error'] || function() {}

@@ -252,2 +252,33 @@ , _is_online = setup['_is_online'] || function() { return 1 }

function _get_url_params(data) {
if (!data) data = {};
each( params , function( key, value ) {
data[key] = value;
});
return data;
}
function _object_to_key_list(o) {
var l = []
each( o , function( key, value ) {
l.push(key);
});
return l;
}
function _object_to_key_list_sorted(o) {
return _object_to_key_list(o).sort();
}
function _get_pam_sign_input_from_params(params) {
var si = "";
var l = _object_to_key_list_sorted(params);
for (var i in l) {
var k = l[i]
si += k + "=" + encode(params[k]) ;
if (i != l.length - 1) si += "&"
}
return si;
}
function validate_presence_heartbeat(heartbeat, cur_heartbeat, error) {

@@ -389,3 +420,3 @@ var err = false;

callback : jsonp,
data : data,
data : _get_url_params(data),
success : function(response) {

@@ -438,2 +469,5 @@ _invoke_callback(response, callback, err);

},
'_add_param' : function(key,val) {
params[key] = val;
},

@@ -479,3 +513,3 @@ /*

callback : jsonp,
data : params,
data : _get_url_params(params),
success : function(response) {

@@ -559,3 +593,3 @@ if (typeof response == 'object' && response['error']) {

url : url,
data : data
data : _get_url_params(data)
});

@@ -579,3 +613,3 @@ },

callback : jsonp,
data : { 'uuid' : UUID, 'auth' : AUTH_KEY },
data : _get_url_params({ 'uuid' : UUID, 'auth' : AUTH_KEY }),
timeout : SECOND * 5,

@@ -601,2 +635,3 @@ url : [STD_ORIGIN, 'time', jsonp],

, err = args['error'] || function() {}
, post = args['post'] || false
, jsonp = jsonp_cb()

@@ -629,3 +664,3 @@ , add_msg = 'push'

url : url,
data : { 'uuid' : UUID, 'auth' : auth_key },
data : _get_url_params({ 'uuid' : UUID, 'auth' : auth_key }),
fail : function(response){

@@ -638,3 +673,4 @@ _invoke_error(response, err);

publish(1);
}
},
mode : (post)?'POST':'GET'
});

@@ -820,3 +856,3 @@

var data = { 'uuid' : UUID, 'auth' : auth_key };
var data = _get_url_params({ 'uuid' : UUID, 'auth' : auth_key });

@@ -837,3 +873,3 @@ var st = JSON.stringify(STATE);

},
data : data,
data : _get_url_params(data),
url : [

@@ -966,3 +1002,3 @@ SUB_ORIGIN, 'subscribe',

callback : jsonp,
data : data,
data : _get_url_params(data),
success : function(response) {

@@ -997,3 +1033,3 @@ _invoke_callback(response, callback, err);

callback : jsonp,
data : data,
data : _get_url_params(data),
success : function(response) {

@@ -1022,3 +1058,3 @@ _invoke_callback(response, callback, err);

, url
, data = { 'auth' : auth_key };
, data = _get_url_params({ 'auth' : auth_key });

@@ -1054,3 +1090,3 @@ // Make sure we have a Channel

callback : jsonp,
data : data,
data : _get_url_params(data),
success : function(response) {

@@ -1100,23 +1136,5 @@ _invoke_callback(response, callback, err);

if (auth_key) sign_input += ("auth=" + encode(auth_key) + "&");
if (jsonp != '0') sign_input += ("callback=" + encode(jsonp) + "&") ;
if (channel) sign_input += ("channel=" + encode(channel) + "&") ;
sign_input += "pnsdk=" + encode(PNSDK) + "&"
+ "r=" + r + "&"
+ "timestamp=" + encode(timestamp);
if (ttl || ttl === 0) sign_input += "&" + "ttl=" + ttl;
sign_input += "&" + "w=" + w;
var signature = hmac_SHA256( sign_input, SECRET_KEY );
signature = signature.replace( /\+/g, "-" );
signature = signature.replace( /\//g, "_" );
var data = {
'w' : w,
'r' : r,
'signature' : signature,
'channel' : channel,

@@ -1130,2 +1148,13 @@ 'timestamp' : timestamp

data = _get_url_params(data)
sign_input += _get_pam_sign_input_from_params(data);
var signature = hmac_SHA256( sign_input, SECRET_KEY );
signature = signature.replace( /\+/g, "-" );
signature = signature.replace( /\//g, "_" );
data['signature'] = signature;
xdr({

@@ -1175,8 +1204,11 @@ callback : jsonp,

if (auth_key) sign_input += ("auth=" + encode(auth_key) + "&");
if (jsonp != '0') sign_input += ("callback=" + encode(jsonp) + "&") ;
if (channel) sign_input += ("channel=" + encode(channel) + "&") ;
var data = {'timestamp' : timestamp };
if (jsonp != '0') { data['callback'] = jsonp; }
if (channel) data['channel'] = channel;
if (auth_key) data['auth'] = auth_key;
sign_input += "pnsdk=" + encode(PNSDK) + "&" + "timestamp=" + timestamp;
data = _get_url_params(data)
sign_input += _get_pam_sign_input_from_params(data);
var signature = hmac_SHA256( sign_input, SECRET_KEY );

@@ -1187,8 +1219,3 @@

var data = { 'signature' : signature, 'timestamp' : timestamp };
if (jsonp != '0') { data['callback'] = jsonp; }
if (channel) data['channel'] = channel;
if (auth_key) data['auth'] = auth_key;
data['signature'] = signature;
xdr({

@@ -1243,3 +1270,3 @@ callback : jsonp,

callback : jsonp,
data : data,
data : _get_url_params(data),
timeout : SECOND * 5,

@@ -1362,11 +1389,12 @@ url : [

*/
var NOW = 1
, http = require('http')
, https = require('https')
, XHRTME = 310000
, DEF_TIMEOUT = 10000
, SECOND = 1000
, PNSDK = 'PubNub-JS-' + 'Nodejs' + '/' + '3.6.2'
, crypto = require('crypto')
, XORIGN = 1;
var NOW = 1
, http = require('http')
, https = require('https')
, XHRTME = 310000
, DEF_TIMEOUT = 10000
, SECOND = 1000
, PNSDK = 'PubNub-JS-' + 'Nodejs' + '/' + '3.6.3'
, crypto = require('crypto')
, proxy = null
, XORIGN = 1;

@@ -1406,2 +1434,3 @@

, loaded = 0
, mode = setup['mode'] || 'GET'
, data = setup['data'] || {}

@@ -1438,4 +1467,2 @@ , xhrtme = setup.timeout || DEF_TIMEOUT

var publish = setup.url[1] === 'publish';
var mode = publish ? 'POST' : 'GET';
var options = {};

@@ -1445,3 +1472,3 @@ var headers = {};

if (publish && mode == 'POST')
if (mode == 'POST')
payload = decodeURIComponent(setup.url.pop());

@@ -1452,5 +1479,8 @@

options.hostname = setup.url[0].split("//")[1];
options.port = ssl ? 443 : 80;
options.path = url;
var origin = setup.url[0].split("//")[1]
options.hostname = proxy ? proxy.hostname : setup.url[0].split("//")[1];
options.port = proxy ? proxy.port : ssl ? 443 : 80;
options.path = proxy ? "http://" + origin + url:url;
options.headers = proxy ? { 'Host': origin }:null;
options.method = mode;

@@ -1460,3 +1490,2 @@ options.agent = false;

require('http').globalAgent.maxSockets = Infinity;

@@ -1466,4 +1495,4 @@ try {

response.setEncoding('utf8');
response.on( 'error', function(){done(1, body || { "error" : "Network Connection Error"})});
response.on( 'abort', function(){done(1, body || { "error" : "Network Connection Error"})});
response.on( 'error', function(){console.log('error');done(1, body || { "error" : "Network Connection Error"})});
response.on( 'abort', function(){console.log('abort');done(1, body || { "error" : "Network Connection Error"})});
response.on( 'data', function (chunk) {

@@ -1488,3 +1517,2 @@ if (chunk) body += chunk;

}
finished();

@@ -1554,8 +1582,9 @@ });

var CREATE_PUBNUB = function(setup) {
proxy = setup['proxy'];
setup['xdr'] = xdr;
setup['db'] = db;
setup['error'] = setup['error'] || error;
setup['PNSDK'] = PNSDK;
setup['hmac_SHA256'] = get_hmac_SHA256;
setup['crypto_obj'] = crypto_obj();
setup['params'] = {'pnsdk' : PNSDK};
SELF = function(setup) {

@@ -1562,0 +1591,0 @@ return CREATE_PUBNUB(setup);

var pubnub = require('../pubnub.js').init({})
function error(result) {
console.log( 'Error with', result }
console.log( 'Error with', result )
}
console.log('Publishing... Waiting for Result!\n')
pubnub.publish({
channel : 'bbq',
message : { 'hah?' : 'lol' },
callback : function(result){ console.log(result) },
error : error
})
pub({ 'hah' : 'lol' });
pub({ 'hah?' : 'lol' });
function pub(msg) {
pubnub.publish({
channel : 'bbq',
message : msg,
callback : function(result){ console.log(result) },
error : error
})
}

@@ -35,11 +35,12 @@ /* ---------------------------------------------------------------------------

*/
var NOW = 1
, http = require('http')
, https = require('https')
, XHRTME = 310000
, DEF_TIMEOUT = 10000
, SECOND = 1000
, PNSDK = 'PubNub-JS-' + PLATFORM + '/' + VERSION
, crypto = require('crypto')
, XORIGN = 1;
var NOW = 1
, http = require('http')
, https = require('https')
, XHRTME = 310000
, DEF_TIMEOUT = 10000
, SECOND = 1000
, PNSDK = 'PubNub-JS-' + PLATFORM + '/' + VERSION
, crypto = require('crypto')
, proxy = null
, XORIGN = 1;

@@ -79,2 +80,3 @@

, loaded = 0
, mode = setup['mode'] || 'GET'
, data = setup['data'] || {}

@@ -111,4 +113,2 @@ , xhrtme = setup.timeout || DEF_TIMEOUT

var publish = setup.url[1] === 'publish';
var mode = publish ? 'POST' : 'GET';
var options = {};

@@ -118,3 +118,3 @@ var headers = {};

if (publish && mode == 'POST')
if (mode == 'POST')
payload = decodeURIComponent(setup.url.pop());

@@ -125,5 +125,8 @@

options.hostname = setup.url[0].split("//")[1];
options.port = ssl ? 443 : 80;
options.path = url;
var origin = setup.url[0].split("//")[1]
options.hostname = proxy ? proxy.hostname : setup.url[0].split("//")[1];
options.port = proxy ? proxy.port : ssl ? 443 : 80;
options.path = proxy ? "http://" + origin + url:url;
options.headers = proxy ? { 'Host': origin }:null;
options.method = mode;

@@ -133,3 +136,2 @@ options.agent = false;

require('http').globalAgent.maxSockets = Infinity;

@@ -139,4 +141,4 @@ try {

response.setEncoding('utf8');
response.on( 'error', function(){done(1, body || { "error" : "Network Connection Error"})});
response.on( 'abort', function(){done(1, body || { "error" : "Network Connection Error"})});
response.on( 'error', function(){console.log('error');done(1, body || { "error" : "Network Connection Error"})});
response.on( 'abort', function(){console.log('abort');done(1, body || { "error" : "Network Connection Error"})});
response.on( 'data', function (chunk) {

@@ -161,3 +163,2 @@ if (chunk) body += chunk;

}
finished();

@@ -227,8 +228,9 @@ });

var CREATE_PUBNUB = function(setup) {
proxy = setup['proxy'];
setup['xdr'] = xdr;
setup['db'] = db;
setup['error'] = setup['error'] || error;
setup['PNSDK'] = PNSDK;
setup['hmac_SHA256'] = get_hmac_SHA256;
setup['crypto_obj'] = crypto_obj();
setup['params'] = {'pnsdk' : PNSDK};
SELF = function(setup) {

@@ -235,0 +237,0 @@ return CREATE_PUBNUB(setup);

Sorry, the diff of this file is too big to display

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