Skip to content

Commit c5d0ec1

Browse files
author
Devendra
committed
merging node.js publish POST fix
2 parents ed6c041 + 58f0ed2 commit c5d0ec1

File tree

23 files changed

+195
-134
lines changed

23 files changed

+195
-134
lines changed

core/pubnub-common.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,7 @@ function PN_API(setup) {
620620
, auth_key = args['auth_key'] || AUTH_KEY
621621
, cipher_key = args['cipher_key']
622622
, err = args['error'] || function() {}
623+
, post = args['post'] || false
623624
, jsonp = jsonp_cb()
624625
, add_msg = 'push'
625626
, url;
@@ -655,7 +656,8 @@ function PN_API(setup) {
655656
success : function(response) {
656657
_invoke_callback(response, callback, err);
657658
publish(1);
658-
}
659+
},
660+
mode : (post)?'POST':'GET'
659661
});
660662

661663
// Send Message

modern/pubnub.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,7 @@ function PN_API(setup) {
621621
, auth_key = args['auth_key'] || AUTH_KEY
622622
, cipher_key = args['cipher_key']
623623
, err = args['error'] || function() {}
624+
, post = args['post'] || false
624625
, jsonp = jsonp_cb()
625626
, add_msg = 'push'
626627
, url;
@@ -656,7 +657,8 @@ function PN_API(setup) {
656657
success : function(response) {
657658
_invoke_callback(response, callback, err);
658659
publish(1);
659-
}
660+
},
661+
mode : (post)?'POST':'GET'
660662
});
661663

662664
// Send Message

modern/pubnub.min.js

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

node.js/examples/hello.js

+10-14
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,15 @@ var pubnub = PUBNUB({
1313
//cipher_key : "demo"
1414
});
1515

16+
pubnub.publish({
17+
post: false,
18+
channel : 'PubNubTest_RX',
19+
message : { 'test' : 'f?ds' },
20+
callback : function(details) {
21+
var success = details[0]
22+
, response = details[1];
1623

17-
console.log(pubnub.get_version());
18-
/* ---------------------------------------------------------------------------
19-
Listen for Messages
20-
--------------------------------------------------------------------------- */
21-
pubnub.subscribe({
22-
channel : "a",
23-
callback : function(message) {
24-
console.log( " > ", message );
25-
},
26-
error : function(r) {
27-
console.log(JSON.stringify(r));
28-
},
29-
presence : function(r) { console.log(JSON.stringify(r)) }
30-
24+
if (success) console.log( "Success!", response );
25+
if (!success) console.log( "Fail!", response );
26+
}
3127
});

node.js/pubnub.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,7 @@ function PN_API(setup) {
621621
, auth_key = args['auth_key'] || AUTH_KEY
622622
, cipher_key = args['cipher_key']
623623
, err = args['error'] || function() {}
624+
, post = args['post'] || false
624625
, jsonp = jsonp_cb()
625626
, add_msg = 'push'
626627
, url;
@@ -656,7 +657,8 @@ function PN_API(setup) {
656657
success : function(response) {
657658
_invoke_callback(response, callback, err);
658659
publish(1);
659-
}
660+
},
661+
mode : (post)?'POST':'GET'
660662
});
661663

662664
// Send Message
@@ -1402,6 +1404,7 @@ function xdr( setup ) {
14021404
, failed = 0
14031405
, complete = 0
14041406
, loaded = 0
1407+
, mode = setup['mode'] || 'GET'
14051408
, data = setup['data'] || {}
14061409
, xhrtme = setup.timeout || DEF_TIMEOUT
14071410
, body = ''
@@ -1433,13 +1436,11 @@ function xdr( setup ) {
14331436

14341437
data['pnsdk'] = PNSDK;
14351438

1436-
var publish = setup.url[1] === 'publish';
1437-
var mode = publish ? 'POST' : 'GET';
14381439
var options = {};
14391440
var headers = {};
14401441
var payload = '';
14411442

1442-
if (publish && mode == 'POST')
1443+
if (mode == 'POST')
14431444
payload = decodeURIComponent(setup.url.pop());
14441445

14451446
var url = build_url( setup.url, data );

node.js/tests/test.js

+37
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ var count = 0;
1919

2020
var message_string = "Hi from Javascript";
2121
var message_jsono = {"message": "Hi from Javascript"};
22+
var message_jsono_q = {"message": "How are you ?"};
2223
var message_jsona = ["message" , "Hi from javascript"];
2324
var message_num = 123;
2425
var message_num_str = "123";
@@ -146,6 +147,42 @@ describe('Pubnub', function() {
146147

147148
})
148149
})
150+
it('should publish json objects without error ( with ? in content ) ', function(done){
151+
var ch = channel + '-' + ++count;
152+
pubnub.subscribe({channel : ch ,
153+
connect : function(response) {
154+
pubnub.publish({channel: ch , message : message_jsono_q,
155+
callback : function(response) {
156+
assert.deepEqual(response[0],1);
157+
}
158+
});
159+
},
160+
callback : function(response) {
161+
assert.deepEqual(response,message_jsono_q);
162+
pubnub.unsubscribe({channel : ch});
163+
done();
164+
}
165+
166+
})
167+
})
168+
it('should publish json objects without error when encryption is enabled ( with ? in content )', function(done){
169+
var ch = channel + '-' + ++count;
170+
pubnub_enc.subscribe({channel : ch ,
171+
connect : function(response) {
172+
pubnub_enc.publish({channel: ch , message : message_jsono_q,
173+
callback : function(response) {
174+
assert.deepEqual(response[0],1);
175+
}
176+
});
177+
},
178+
callback : function(response) {
179+
assert.deepEqual(response,message_jsono_q);
180+
pubnub_enc.unsubscribe({channel : ch});
181+
done();
182+
}
183+
184+
})
185+
})
149186
it('should publish json arrays without error', function(done){
150187
var ch = channel + '-' + ++count ;
151188
pubnub.subscribe({channel : ch ,

node.js/unassembled/platform.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ function xdr( setup ) {
7575
, failed = 0
7676
, complete = 0
7777
, loaded = 0
78+
, mode = setup['mode'] || 'GET'
7879
, data = setup['data'] || {}
7980
, xhrtme = setup.timeout || DEF_TIMEOUT
8081
, body = ''
@@ -106,13 +107,11 @@ function xdr( setup ) {
106107

107108
data['pnsdk'] = PNSDK;
108109

109-
var publish = setup.url[1] === 'publish';
110-
var mode = publish ? 'POST' : 'GET';
111110
var options = {};
112111
var headers = {};
113112
var payload = '';
114113

115-
if (publish && mode == 'POST')
114+
if (mode == 'POST')
116115
payload = decodeURIComponent(setup.url.pop());
117116

118117
var url = build_url( setup.url, data );

phonegap/pubnub.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,7 @@ function PN_API(setup) {
621621
, auth_key = args['auth_key'] || AUTH_KEY
622622
, cipher_key = args['cipher_key']
623623
, err = args['error'] || function() {}
624+
, post = args['post'] || false
624625
, jsonp = jsonp_cb()
625626
, add_msg = 'push'
626627
, url;
@@ -656,7 +657,8 @@ function PN_API(setup) {
656657
success : function(response) {
657658
_invoke_callback(response, callback, err);
658659
publish(1);
659-
}
660+
},
661+
mode : (post)?'POST':'GET'
660662
});
661663

662664
// Send Message

0 commit comments

Comments
 (0)