Skip to content

Commit

Permalink
updated Node.JS PubNub API with latest Node.JS interface and better S…
Browse files Browse the repository at this point in the history
…SL support.
  • Loading branch information
stephenlb committed Feb 13, 2012
1 parent 6b58cbb commit 54ac875
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 24 deletions.
2 changes: 1 addition & 1 deletion nodejs/package.json
@@ -1,7 +1,7 @@
{
"name": "pubnub",
"preferGlobal": false,
"version": "3.1.6",
"version": "3.1.7",
"author": "Pubnub <stephen@pubnub.com>",
"description": "Publish & Subscribe Real-time Messaging with PubNub",
"contributors": [
Expand Down
45 changes: 22 additions & 23 deletions nodejs/pubnub.js
Expand Up @@ -105,33 +105,32 @@ function xdr( setup ) {
, origin = setup.origin
, ssl = setup.ssl
, failed = 0
, body = ''
, fail = function(e) {
if (failed) return;
failed = 1;
(setup.fail||function(){})(e);
}, body = ''
, client = http.createClient( 80, origin, ssl )
, request = client.request( 'GET', url, { 'host': origin });

request.end();
request.on( 'error', fail );
request.on( 'response', function (response) {
response.setEncoding('utf8');

response.on( 'error', fail );
response.on( 'data', function (chunk) {
if (chunk) body += chunk;
} );
response.on( 'end', function () {
try {
if (body) return success(JSON.parse(body));
else fail();
}
catch(e) {
fail();
}
} );
} );
};

try {
http.get( {

This comment has been minimized.

Copy link
@tristanls

tristanls Feb 13, 2012

In reference to #70

I hacked it locally to something like below and it now delivers messages when ssl is true.

try {
    var _http = ssl ? require( 'https' ) : http;
    _http.get({
host : origin,
port : ssl ? 443 : 80,
path : url
}, function(response) {
response.setEncoding('utf8');
response.on( 'error', fail );
response.on( 'data', function (chunk) {
if (chunk) body += chunk;
} );
response.on( 'end', function () {
try {
if (body) return success(JSON.parse(body));
else fail();
} catch(e) { fail(); }
} );
}).on( 'error', fail );
} catch(e) { fail(); }
}


Expand Down

0 comments on commit 54ac875

Please sign in to comment.