Skip to content

Commit 2f11536

Browse files
author
Devendra
committed
fixing jsonp issue, adding patch by jordan
1 parent 1171dc9 commit 2f11536

File tree

26 files changed

+2648
-231
lines changed

26 files changed

+2648
-231
lines changed

core/pubnub-common.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -1074,21 +1074,20 @@ function PN_API(setup) {
10741074

10751075
var timestamp = Math.floor(new Date().getTime() / 1000)
10761076
, sign_input = SUBSCRIBE_KEY + "\n" + PUBLISH_KEY + "\n"
1077-
+ "grant" + "\n"
1078-
+ ((
1079-
(auth_key && encode(auth_key).length > 0) ?
1080-
"auth=" + encode(auth_key) + "&" :
1081-
""
1082-
))
1083-
+ "channel=" + encode(channel) + "&"
1084-
+ "pnsdk=" + encode(PNSDK) + "&"
1077+
+ "grant" + "\n";
1078+
1079+
1080+
if (auth_key) sign_input += ("auth=" + encode(auth_key) + "&");
1081+
if (jsonp != '0') sign_input += ("callback=" + encode(jsonp) + "&") ;
1082+
if (channel) sign_input += ("channel=" + encode(channel) + "&") ;
1083+
1084+
sign_input += "pnsdk=" + encode(PNSDK) + "&"
10851085
+ "r=" + r + "&"
10861086
+ "timestamp=" + encode(timestamp);
1087-
1087+
10881088
if (ttl || ttl === 0) sign_input += "&" + "ttl=" + ttl;
10891089

10901090
sign_input += "&" + "w=" + w;
1091-
10921091
var signature = hmac_SHA256( sign_input, SECRET_KEY );
10931092

10941093
signature = signature.replace( /\+/g, "-" );
@@ -1151,6 +1150,7 @@ function PN_API(setup) {
11511150
+ "audit" + "\n";
11521151

11531152
if (auth_key) sign_input += ("auth=" + encode(auth_key) + "&");
1153+
if (jsonp != '0') sign_input += ("callback=" + encode(jsonp) + "&") ;
11541154
if (channel) sign_input += ("channel=" + encode(channel) + "&") ;
11551155

11561156
sign_input += "pnsdk=" + encode(PNSDK) + "&" + "timestamp=" + timestamp;

modern/pubnub.js

+23-18
Original file line numberDiff line numberDiff line change
@@ -1075,21 +1075,20 @@ function PN_API(setup) {
10751075

10761076
var timestamp = Math.floor(new Date().getTime() / 1000)
10771077
, sign_input = SUBSCRIBE_KEY + "\n" + PUBLISH_KEY + "\n"
1078-
+ "grant" + "\n"
1079-
+ ((
1080-
(auth_key && encode(auth_key).length > 0) ?
1081-
"auth=" + encode(auth_key) + "&" :
1082-
""
1083-
))
1084-
+ "channel=" + encode(channel) + "&"
1085-
+ "pnsdk=" + encode(PNSDK) + "&"
1078+
+ "grant" + "\n";
1079+
1080+
1081+
if (auth_key) sign_input += ("auth=" + encode(auth_key) + "&");
1082+
if (jsonp != '0') sign_input += ("callback=" + encode(jsonp) + "&") ;
1083+
if (channel) sign_input += ("channel=" + encode(channel) + "&") ;
1084+
1085+
sign_input += "pnsdk=" + encode(PNSDK) + "&"
10861086
+ "r=" + r + "&"
10871087
+ "timestamp=" + encode(timestamp);
1088-
1088+
10891089
if (ttl || ttl === 0) sign_input += "&" + "ttl=" + ttl;
10901090

10911091
sign_input += "&" + "w=" + w;
1092-
10931092
var signature = hmac_SHA256( sign_input, SECRET_KEY );
10941093

10951094
signature = signature.replace( /\+/g, "-" );
@@ -1152,6 +1151,7 @@ function PN_API(setup) {
11521151
+ "audit" + "\n";
11531152

11541153
if (auth_key) sign_input += ("auth=" + encode(auth_key) + "&");
1154+
if (jsonp != '0') sign_input += ("callback=" + encode(jsonp) + "&") ;
11551155
if (channel) sign_input += ("channel=" + encode(channel) + "&") ;
11561156

11571157
sign_input += "pnsdk=" + encode(PNSDK) + "&" + "timestamp=" + timestamp;
@@ -2763,18 +2763,23 @@ function CREATE_PUBNUB(setup) {
27632763
SELF['css'] = css;
27642764
SELF['create'] = create;
27652765

2766-
2767-
// Add Leave Functions
2768-
bind( 'beforeunload', window, function() {
2769-
SELF['each-channel'](function(ch){ SELF['LEAVE']( ch.name, 1 ) });
2770-
return true;
2771-
} );
2766+
if (typeof(window) !== 'undefined'){
2767+
bind( 'beforeunload', window, function() {
2768+
SELF['each-channel'](function(ch){ SELF['LEAVE']( ch.name, 1 ) });
2769+
return true;
2770+
});
2771+
}
27722772

27732773
// Return without Testing
27742774
if (setup['notest']) return SELF;
27752775

2776-
bind( 'offline', window, SELF['_reset_offline'] );
2777-
bind( 'offline', document, SELF['_reset_offline'] );
2776+
if (typeof(window) !== 'undefined'){
2777+
bind( 'offline', window, SELF['_reset_offline'] );
2778+
}
2779+
2780+
if (typeof(document) !== 'undefined'){
2781+
bind( 'offline', document, SELF['_reset_offline'] );
2782+
}
27782783

27792784
SELF['ready']();
27802785
return SELF;

modern/pubnub.min.js

+7-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

modern/unassembled/platform.js

+13-8
Original file line numberDiff line numberDiff line change
@@ -311,18 +311,23 @@ function CREATE_PUBNUB(setup) {
311311
SELF['css'] = css;
312312
SELF['create'] = create;
313313

314-
315-
// Add Leave Functions
316-
bind( 'beforeunload', window, function() {
317-
SELF['each-channel'](function(ch){ SELF['LEAVE']( ch.name, 1 ) });
318-
return true;
319-
} );
314+
if (typeof(window) !== 'undefined'){
315+
bind( 'beforeunload', window, function() {
316+
SELF['each-channel'](function(ch){ SELF['LEAVE']( ch.name, 1 ) });
317+
return true;
318+
});
319+
}
320320

321321
// Return without Testing
322322
if (setup['notest']) return SELF;
323323

324-
bind( 'offline', window, SELF['_reset_offline'] );
325-
bind( 'offline', document, SELF['_reset_offline'] );
324+
if (typeof(window) !== 'undefined'){
325+
bind( 'offline', window, SELF['_reset_offline'] );
326+
}
327+
328+
if (typeof(document) !== 'undefined'){
329+
bind( 'offline', document, SELF['_reset_offline'] );
330+
}
326331

327332
SELF['ready']();
328333
return SELF;

node.js/examples/publish.js

+10-3
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,19 @@ var pubnub = require("./../pubnub.js").init({
1414
/* ---------------------------------------------------------------------------
1515
Listen for Messages
1616
--------------------------------------------------------------------------- */
17+
18+
function publish(channel, msg) {
1719
pubnub.publish({
18-
channel : "JAY",
19-
message : "askldjflksjd_POST",
20+
channel : channel,
21+
message : msg,
2022
callback : log,
2123
error : retry
2224
});
23-
25+
}
2426
function log(e) { console.log(e) }
2527
function retry() { console.log('retry?') }
28+
29+
30+
for (var i = 0; i < 1000; i++) {
31+
publish('dsm-test',i);
32+
}

node.js/pubnub.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -1075,21 +1075,20 @@ function PN_API(setup) {
10751075

10761076
var timestamp = Math.floor(new Date().getTime() / 1000)
10771077
, sign_input = SUBSCRIBE_KEY + "\n" + PUBLISH_KEY + "\n"
1078-
+ "grant" + "\n"
1079-
+ ((
1080-
(auth_key && encode(auth_key).length > 0) ?
1081-
"auth=" + encode(auth_key) + "&" :
1082-
""
1083-
))
1084-
+ "channel=" + encode(channel) + "&"
1085-
+ "pnsdk=" + encode(PNSDK) + "&"
1078+
+ "grant" + "\n";
1079+
1080+
1081+
if (auth_key) sign_input += ("auth=" + encode(auth_key) + "&");
1082+
if (jsonp != '0') sign_input += ("callback=" + encode(jsonp) + "&") ;
1083+
if (channel) sign_input += ("channel=" + encode(channel) + "&") ;
1084+
1085+
sign_input += "pnsdk=" + encode(PNSDK) + "&"
10861086
+ "r=" + r + "&"
10871087
+ "timestamp=" + encode(timestamp);
1088-
1088+
10891089
if (ttl || ttl === 0) sign_input += "&" + "ttl=" + ttl;
10901090

10911091
sign_input += "&" + "w=" + w;
1092-
10931092
var signature = hmac_SHA256( sign_input, SECRET_KEY );
10941093

10951094
signature = signature.replace( /\+/g, "-" );
@@ -1152,6 +1151,7 @@ function PN_API(setup) {
11521151
+ "audit" + "\n";
11531152

11541153
if (auth_key) sign_input += ("auth=" + encode(auth_key) + "&");
1154+
if (jsonp != '0') sign_input += ("callback=" + encode(jsonp) + "&") ;
11551155
if (channel) sign_input += ("channel=" + encode(channel) + "&") ;
11561156

11571157
sign_input += "pnsdk=" + encode(PNSDK) + "&" + "timestamp=" + timestamp;

phonegap/pubnub.js

+23-18
Original file line numberDiff line numberDiff line change
@@ -1075,21 +1075,20 @@ function PN_API(setup) {
10751075

10761076
var timestamp = Math.floor(new Date().getTime() / 1000)
10771077
, sign_input = SUBSCRIBE_KEY + "\n" + PUBLISH_KEY + "\n"
1078-
+ "grant" + "\n"
1079-
+ ((
1080-
(auth_key && encode(auth_key).length > 0) ?
1081-
"auth=" + encode(auth_key) + "&" :
1082-
""
1083-
))
1084-
+ "channel=" + encode(channel) + "&"
1085-
+ "pnsdk=" + encode(PNSDK) + "&"
1078+
+ "grant" + "\n";
1079+
1080+
1081+
if (auth_key) sign_input += ("auth=" + encode(auth_key) + "&");
1082+
if (jsonp != '0') sign_input += ("callback=" + encode(jsonp) + "&") ;
1083+
if (channel) sign_input += ("channel=" + encode(channel) + "&") ;
1084+
1085+
sign_input += "pnsdk=" + encode(PNSDK) + "&"
10861086
+ "r=" + r + "&"
10871087
+ "timestamp=" + encode(timestamp);
1088-
1088+
10891089
if (ttl || ttl === 0) sign_input += "&" + "ttl=" + ttl;
10901090

10911091
sign_input += "&" + "w=" + w;
1092-
10931092
var signature = hmac_SHA256( sign_input, SECRET_KEY );
10941093

10951094
signature = signature.replace( /\+/g, "-" );
@@ -1152,6 +1151,7 @@ function PN_API(setup) {
11521151
+ "audit" + "\n";
11531152

11541153
if (auth_key) sign_input += ("auth=" + encode(auth_key) + "&");
1154+
if (jsonp != '0') sign_input += ("callback=" + encode(jsonp) + "&") ;
11551155
if (channel) sign_input += ("channel=" + encode(channel) + "&") ;
11561156

11571157
sign_input += "pnsdk=" + encode(PNSDK) + "&" + "timestamp=" + timestamp;
@@ -2763,18 +2763,23 @@ function CREATE_PUBNUB(setup) {
27632763
SELF['css'] = css;
27642764
SELF['create'] = create;
27652765

2766-
2767-
// Add Leave Functions
2768-
bind( 'beforeunload', window, function() {
2769-
SELF['each-channel'](function(ch){ SELF['LEAVE']( ch.name, 1 ) });
2770-
return true;
2771-
} );
2766+
if (typeof(window) !== 'undefined'){
2767+
bind( 'beforeunload', window, function() {
2768+
SELF['each-channel'](function(ch){ SELF['LEAVE']( ch.name, 1 ) });
2769+
return true;
2770+
});
2771+
}
27722772

27732773
// Return without Testing
27742774
if (setup['notest']) return SELF;
27752775

2776-
bind( 'offline', window, SELF['_reset_offline'] );
2777-
bind( 'offline', document, SELF['_reset_offline'] );
2776+
if (typeof(window) !== 'undefined'){
2777+
bind( 'offline', window, SELF['_reset_offline'] );
2778+
}
2779+
2780+
if (typeof(document) !== 'undefined'){
2781+
bind( 'offline', document, SELF['_reset_offline'] );
2782+
}
27782783

27792784
SELF['ready']();
27802785
return SELF;

0 commit comments

Comments
 (0)