Skip to content

Commit d1d33a5

Browse files
committed
added ULS upgrade support for JavaScript which allows "error" message dictionary format.
1 parent 520bc32 commit d1d33a5

File tree

23 files changed

+372
-266
lines changed

23 files changed

+372
-266
lines changed

CHANGELOG

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
06-07-13 * NEW VERSION 3.5.1 *
2+
. added `error` callback on subscribe.
3+
. added fix for instant disconnect detection in webkit.
4+
. added support for error details from ULS response.
5+
16
05-23-13 * NEW VERSION 3.5.0 *
27
. added auth_key for ULS support.
38
. added SmartTV Platform SDK.

README.md

+39-16
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# YOU MUST HAVE A PUBNUB ACCOUNT TO USE THE API.
22
Create an account at http://www.pubnub.com/account
33

4-
## The PubNub Network JavaScript Real-time SDK v3.5.0
4+
## The PubNub Network JavaScript Real-time SDK v3.5.1
55
http://www.pubnub.com - PubNub Real-time Push Service in the Cloud.
66

77
The PubNub Network is a blazingly fast Global Messaging Service for building
@@ -16,7 +16,7 @@ business collaborative solutions, and more.
1616
You may access the latest PubNub JavaScript SDK on The PubNub Network CDN.
1717

1818
```html
19-
<script src=http://cdn.pubnub.com/pubnub-3.5.0.min.js ></script>
19+
<script src=http://cdn.pubnub.com/pubnub-3.5.1.min.js ></script>
2020
<script>(function(){
2121
var pubnub = PUBNUB.init({
2222
publish_key : 'demo',
@@ -34,7 +34,7 @@ and for security considerations,
3434
use this following method for initialization:
3535

3636
```html
37-
<script src=http://cdn.pubnub.com/pubnub-3.5.0.min.js ></script>
37+
<script src=http://cdn.pubnub.com/pubnub-3.5.1.min.js ></script>
3838
<script>(function(){
3939
4040
var pubnub = PUBNUB.init({ subscribe_key : 'demo' });
@@ -145,7 +145,7 @@ JavaScript SDK using the **web** build. It's as easy as `copy/paste`.
145145
146146
```html
147147
<div id=pubnub pub-key=demo sub-key=demo></div>
148-
<script src=http://cdn.pubnub.com/pubnub-3.5.0.min.js ></script>
148+
<script src=http://cdn.pubnub.com/pubnub-3.5.1.min.js ></script>
149149
<script>
150150
151151
// LISTEN
@@ -169,11 +169,11 @@ JavaScript SDK using the **web** build. It's as easy as `copy/paste`.
169169
## ADVANCED SUBSCRIBE CONNECTIVITY OPTIONS/CALLBACKS
170170
```html
171171
<div id=pubnub pub-key=demo sub-key=demo></div>
172-
<script src=http://cdn.pubnub.com/pubnub-3.5.0.min.js ></script>
172+
<script src=http://cdn.pubnub.com/pubnub-3.5.1.min.js ></script>
173173
<script>(function(){
174174
PUBNUB.subscribe({
175175
channel : "hello_world", // CONNECT TO THIS CHANNEL.
176-
restore : false, // FETCH MISSED MESSAGES ON PAGE CHANGES.
176+
restore : true, // FETCH MISSED MESSAGES ON PAGE CHANGES.
177177
message : function( message, env, channel ) {}, // RECEIVED A MESSAGE.
178178
presence : function( message, env, channel ) {}, // OTHER USERS JOIN/LEFT CHANNEL.
179179
connect : function() {}, // CONNECTION ESTABLISHED.
@@ -184,6 +184,29 @@ JavaScript SDK using the **web** build. It's as easy as `copy/paste`.
184184
</script>
185185
```
186186

187+
## CAPTURING ERRORS FOR DEBUGGING
188+
189+
Sometimes an error will occur and you may wish to log it.
190+
Note that the PubNub JavaScript SDK auto-recovers connections
191+
upon error so it is not necessary to act upon errors
192+
when **receiving messages**.
193+
194+
```html
195+
<div id=pubnub pub-key=demo sub-key=demo></div>
196+
<script src=http://cdn.pubnub.com/pubnub-3.5.1.min.js ></script>
197+
<script>(function(){
198+
PUBNUB.subscribe({
199+
channel : "hello_world", // CONNECT TO THIS CHANNEL.
200+
message : function( message, env, channel ) {}, // RECEIVED A MESSAGE.
201+
error : function(data) { console.log(data) } // CONNECTION BACK ONLINE!
202+
})
203+
})();
204+
</script>
205+
```
206+
207+
> **Note:** the `error` callback is being used.
208+
209+
187210
## FULL MULTIPLEXING (Single TCP Socket)
188211

189212
>Multiplexing enhances mobile performance and battery savings.
@@ -276,8 +299,8 @@ are open source, you’re welcome to see how we did it).
276299
To use AES encryption in PubNub, simply do the following:
277300

278301
```html
279-
<script src=https://pubnub.a.ssl.fastly.net/pubnub-3.5.0.min.js></script>
280-
<script src=https://pubnub.a.ssl.fastly.net/pubnub-crypto-3.5.0.min.js></script>
302+
<script src=https://pubnub.a.ssl.fastly.net/pubnub-3.5.1.min.js></script>
303+
<script src=https://pubnub.a.ssl.fastly.net/pubnub-crypto-3.5.1.min.js></script>
281304
<script>(function(){
282305
var secure_pubnub = PUBNUB.secure({
283306
publish_key : 'demo',
@@ -342,7 +365,7 @@ To use AES encryption in PubNub, simply do the following:
342365
## SSL MODE
343366
```html
344367
<div id=pubnub ssl=on></div>
345-
<script src=https://pubnub.a.ssl.fastly.net/pubnub-3.5.0.min.js></script>
368+
<script src=https://pubnub.a.ssl.fastly.net/pubnub-3.5.1.min.js></script>
346369
<script>(function(){
347370
348371
var pubnub = PUBNUB.init({
@@ -366,7 +389,7 @@ To use AES encryption in PubNub, simply do the following:
366389
## HISTORY
367390
```html
368391
<div id=pubnub></div>
369-
<script src=http://pubnub.a.ssl.fastly.net/pubnub-3.5.0.min.js></script>
392+
<script src=http://pubnub.a.ssl.fastly.net/pubnub-3.5.1.min.js></script>
370393
<script>(function(){
371394
372395
var pubnub = PUBNUB.init({
@@ -395,7 +418,7 @@ the timeline as they occured.
395418
396419
```html
397420
<div id=pubnub></div>
398-
<script src=http://pubnub.a.ssl.fastly.net/pubnub-3.5.0.min.js></script>
421+
<script src=http://pubnub.a.ssl.fastly.net/pubnub-3.5.1.min.js></script>
399422
<script>(function(){
400423
401424
/* GENERATE CHANNEL */
@@ -432,7 +455,7 @@ and get back an answer with list of users and the occupancy count.
432455

433456
```html
434457
<div id=pubnub pub-key=demo sub-key=demo></div>
435-
<script src=http://cdn.pubnub.com/pubnub-3.5.0.min.js ></script>
458+
<script src=http://cdn.pubnub.com/pubnub-3.5.1.min.js ></script>
436459
<script>(function(){
437460
PUBNUB.subscribe({
438461
channel : "hello_world", // CONNECT TO THIS CHANNEL.
@@ -474,7 +497,7 @@ the `pubnub.subscribe` call below.
474497

475498
```html
476499
<div id=pubnub></div>
477-
<script src=http://pubnub.a.ssl.fastly.net/pubnub-3.5.0.min.js></script>
500+
<script src=http://pubnub.a.ssl.fastly.net/pubnub-3.5.1.min.js></script>
478501
<script>(function(){
479502
480503
var pubnub = PUBNUB.init({
@@ -524,7 +547,7 @@ The following example opens a `new WebSocket` in
524547

525548
```html
526549
<!-- Import PubNub Core Lib -->
527-
<script src="https://pubnub.a.ssl.fastly.net/pubnub-3.5.0.min.js"></script>
550+
<script src="https://pubnub.a.ssl.fastly.net/pubnub-3.5.1.min.js"></script>
528551

529552
<!-- Use WebSocket Constructor for a New Socket Connection -->
530553
<script>(function() {
@@ -572,7 +595,7 @@ The following example opens a `new WebSocket` in
572595

573596
```html
574597
<!-- NON-SSL Import PubNub Core Lib -->
575-
<script src="http://pubnub.a.ssl.fastly.net/pubnub-3.5.0.min.js"></script>
598+
<script src="http://pubnub.a.ssl.fastly.net/pubnub-3.5.1.min.js"></script>
576599

577600
<!-- NON-SSL Use WebSocket Constructor for a New Socket Connection -->
578601
<script>(function() {
@@ -589,7 +612,7 @@ How to create a new instance of the PubNub Object directly in JavaScript.
589612
To do this, simply follow this `init` example:
590613

591614
```html
592-
<script src=http://cdn.pubnub.com/pubnub-3.5.0.min.js ></script>
615+
<script src=http://cdn.pubnub.com/pubnub-3.5.1.min.js ></script>
593616
<script>(function(){
594617
595618
// INIT PubNub

VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.5.0
1+
3.5.1

core/pubnub-common.js

+13-7
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ var NOW = 1
55
, DEF_WINDOWING = 10 // MILLISECONDS.
66
, DEF_TIMEOUT = 10000 // MILLISECONDS.
77
, DEF_SUB_TIMEOUT = 310 // SECONDS.
8-
, DEF_KEEPALIVE = 3600 // SECONDS.
8+
, DEF_KEEPALIVE = 60 // SECONDS.
99
, SECOND = 1000 // A THOUSAND MILLISECONDS.
1010
, URLBIT = '/'
1111
, PARAMSBIT = '&'
@@ -460,6 +460,7 @@ function PN_API(setup) {
460460
, connect = args['connect'] || function(){}
461461
, reconnect = args['reconnect'] || function(){}
462462
, disconnect = args['disconnect'] || function(){}
463+
, errcb = args['error'] || function(){}
463464
, presence = args['presence'] || 0
464465
, noheresync = args['noheresync'] || 0
465466
, backfill = args['backfill'] || 0
@@ -582,7 +583,12 @@ function PN_API(setup) {
582583
],
583584
success : function(messages) {
584585
SUB_RECEIVER = null;
585-
if (!messages) return timeout( CONNECT, windowing );
586+
587+
// Check for Errors
588+
if (!messages || ('error' in messages && !messages['error'])) {
589+
errcb(messages);
590+
return timeout( CONNECT, windowing );
591+
}
586592

587593
// Restore Previous Connection Point if Needed
588594
TIMETOKEN = !TIMETOKEN &&
@@ -684,27 +690,27 @@ function PN_API(setup) {
684690
'each' : each,
685691
'each-channel' : each_channel,
686692
'grep' : grep,
687-
'offline' : _reset_offline,
693+
'offline' : function(){_reset_offline(1)},
688694
'supplant' : supplant,
689695
'now' : rnow,
690696
'unique' : unique,
691697
'updater' : updater
692698
};
693699

694700
function _poll_online() {
695-
_is_online() || _reset_offline();
701+
_is_online() || _reset_offline(1);
696702
timeout( _poll_online, SECOND );
697703
}
698704

699705
function _poll_online2() {
700706
SELF['time'](function(success){
701-
success || _reset_offline();
707+
success || _reset_offline(1);
702708
timeout( _poll_online2, KEEPALIVE );
703709
})
704710
}
705711

706-
function _reset_offline() {
707-
SUB_RECEIVER && SUB_RECEIVER();
712+
function _reset_offline(err) {
713+
SUB_RECEIVER && SUB_RECEIVER(err);
708714
SUB_RECEIVER = null;
709715
}
710716

modern/pubnub.js

+15-9
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
// Version: 3.5.0
1+
// Version: 3.5.1
22
var NOW = 1
33
, READY = false
44
, READY_BUFFER = []
55
, PRESENCE_SUFFIX = '-pnpres'
66
, DEF_WINDOWING = 10 // MILLISECONDS.
77
, DEF_TIMEOUT = 10000 // MILLISECONDS.
88
, DEF_SUB_TIMEOUT = 310 // SECONDS.
9-
, DEF_KEEPALIVE = 3600 // SECONDS.
9+
, DEF_KEEPALIVE = 60 // SECONDS.
1010
, SECOND = 1000 // A THOUSAND MILLISECONDS.
1111
, URLBIT = '/'
1212
, PARAMSBIT = '&'
@@ -461,6 +461,7 @@ function PN_API(setup) {
461461
, connect = args['connect'] || function(){}
462462
, reconnect = args['reconnect'] || function(){}
463463
, disconnect = args['disconnect'] || function(){}
464+
, errcb = args['error'] || function(){}
464465
, presence = args['presence'] || 0
465466
, noheresync = args['noheresync'] || 0
466467
, backfill = args['backfill'] || 0
@@ -583,7 +584,12 @@ function PN_API(setup) {
583584
],
584585
success : function(messages) {
585586
SUB_RECEIVER = null;
586-
if (!messages) return timeout( CONNECT, windowing );
587+
588+
// Check for Errors
589+
if (!messages || ('error' in messages && !messages['error'])) {
590+
errcb(messages);
591+
return timeout( CONNECT, windowing );
592+
}
587593

588594
// Restore Previous Connection Point if Needed
589595
TIMETOKEN = !TIMETOKEN &&
@@ -685,27 +691,27 @@ function PN_API(setup) {
685691
'each' : each,
686692
'each-channel' : each_channel,
687693
'grep' : grep,
688-
'offline' : _reset_offline,
694+
'offline' : function(){_reset_offline(1)},
689695
'supplant' : supplant,
690696
'now' : rnow,
691697
'unique' : unique,
692698
'updater' : updater
693699
};
694700

695701
function _poll_online() {
696-
_is_online() || _reset_offline();
702+
_is_online() || _reset_offline(1);
697703
timeout( _poll_online, SECOND );
698704
}
699705

700706
function _poll_online2() {
701707
SELF['time'](function(success){
702-
success || _reset_offline();
708+
success || _reset_offline(1);
703709
timeout( _poll_online2, KEEPALIVE );
704710
})
705711
}
706712

707-
function _reset_offline() {
708-
SUB_RECEIVER && SUB_RECEIVER();
713+
function _reset_offline(err) {
714+
SUB_RECEIVER && SUB_RECEIVER(err);
709715
SUB_RECEIVER = null;
710716
}
711717

@@ -754,7 +760,7 @@ THE SOFTWARE.
754760
* UTIL LOCALS
755761
*/
756762
var NOW = 1
757-
, PNSDK = 'PubNub-JS-' + 'Modern' + '/' + '3.5.0'
763+
, PNSDK = 'PubNub-JS-' + 'Modern' + '/' + '3.5.1'
758764
, XHRTME = 310000;
759765

760766

0 commit comments

Comments
 (0)