Skip to content

Commit 820550e

Browse files
author
Devendra
committed
adding ZD 3056 fix for titanium resume, and changing API's to pass on only payload and error respectively to callbacks, changed tests accordingly
1 parent 30d569f commit 820550e

22 files changed

Lines changed: 1249 additions & 1213 deletions

File tree

core/pubnub-common.js

Lines changed: 47 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ function PN_API(setup) {
212212
, SUB_RESTORE = 0
213213
, SUB_BUFF_WAIT = 0
214214
, TIMETOKEN = 0
215+
, RESUMED = false
215216
, CHANNELS = {}
216217
, PRESENCE_HB_TIMEOUT = null
217218
, PRESENCE_HB_INTERVAL = validate_presence_heartbeat(setup['pnexpires'] || 0, setup['error'])
@@ -237,7 +238,7 @@ function PN_API(setup) {
237238
if (typeof pnexpires === 'number') {
238239
if (pnexpires > PRESENCE_HB_THRESHOLD || pnexpires == 0)
239240
err = false;
240-
else
241+
else
241242
err = true;
242243
} else {
243244
err = true;
@@ -314,6 +315,19 @@ function PN_API(setup) {
314315

315316
return count;
316317
}
318+
function _invoke_callback(response, callback, err) {
319+
if (typeof response == 'object') {
320+
if (response['error']) {
321+
err(response['error']);
322+
return;
323+
}
324+
if (response['payload']) {
325+
callback(response['payload']);
326+
return;
327+
}
328+
}
329+
callback(response)
330+
}
317331

318332
// Announce Leave Event
319333
var SELF = {
@@ -340,11 +354,7 @@ function PN_API(setup) {
340354
callback : jsonp,
341355
data : data,
342356
success : function(response) {
343-
if (typeof response == 'object' && response['error']) {
344-
err(response);
345-
return;
346-
}
347-
callback(response)
357+
_invoke_callback(response, callback, err);
348358
},
349359
fail : err,
350360
url : [
@@ -354,6 +364,9 @@ function PN_API(setup) {
354364
});
355365
return true;
356366
},
367+
'set_resumed' : function(resumed) {
368+
RESUMED = resumed;
369+
},
357370
'get_cipher_key' : function() {
358371
return CIPHER_KEY;
359372
},
@@ -415,7 +428,7 @@ function PN_API(setup) {
415428
data : params,
416429
success : function(response) {
417430
if (typeof response == 'object' && response['error']) {
418-
err(response);
431+
err(response['error']);
419432
return;
420433
}
421434
var messages = response[0];
@@ -485,11 +498,7 @@ function PN_API(setup) {
485498
xdr({
486499
callback : jsonp,
487500
success : function(response) {
488-
if (typeof response == 'object' && response['error']) {
489-
err(response);
490-
return;
491-
}
492-
callback(response)
501+
_invoke_callback(response, callback, err);
493502
},
494503
fail : function() { callback([ 0, 'Disconnected' ]) },
495504
url : url,
@@ -563,11 +572,7 @@ function PN_API(setup) {
563572
data : { 'uuid' : UUID, 'auth' : auth_key },
564573
fail : function(response){err(response);publish(1)},
565574
success : function(response) {
566-
if (typeof response == 'object' && response['error'])
567-
err(response);
568-
else
569-
callback(response)
570-
575+
_invoke_callback(response, callback, err);
571576
publish(1);
572577
}
573578
});
@@ -766,7 +771,7 @@ function PN_API(setup) {
766771
'error' in messages &&
767772
messages['error']
768773
)) {
769-
errcb(messages);
774+
errcb(messages['error']);
770775
return timeout( CONNECT, SECOND );
771776
}
772777

@@ -785,6 +790,15 @@ function PN_API(setup) {
785790
channel.connect(channel.name);
786791
});
787792

793+
if (RESUMED && !SUB_RESTORE) {
794+
TIMETOKEN = 0;
795+
RESUMED = false;
796+
// Update Saved Timetoken
797+
db['set']( SUBSCRIBE_KEY, 0 );
798+
timeout( _connect, windowing );
799+
return;
800+
}
801+
788802
// Invoke Memory Catchup and Receive Up to 100
789803
// Previous Messages from the Queue.
790804
if (backfill) {
@@ -876,11 +890,7 @@ function PN_API(setup) {
876890
callback : jsonp,
877891
data : data,
878892
success : function(response) {
879-
if (typeof response == 'object' && response['error']) {
880-
err(response);
881-
return;
882-
}
883-
callback(response)
893+
_invoke_callback(response, callback, err);
884894
},
885895
fail : err,
886896
url : url
@@ -908,11 +918,7 @@ function PN_API(setup) {
908918
callback : jsonp,
909919
data : data,
910920
success : function(response) {
911-
if (typeof response == 'object' && response['error']) {
912-
err(response);
913-
return;
914-
}
915-
callback(response)
921+
_invoke_callback(response, callback, err);
916922
},
917923
fail : err,
918924
url : [
@@ -949,11 +955,7 @@ function PN_API(setup) {
949955
callback : jsonp,
950956
data : data,
951957
success : function(response) {
952-
if (typeof response == 'object' && response['error']) {
953-
err(response);
954-
return;
955-
}
956-
callback(response)
958+
_invoke_callback(response, callback, err);
957959
},
958960
fail : err,
959961
url : [
@@ -986,11 +988,7 @@ function PN_API(setup) {
986988
callback : jsonp,
987989
data : data,
988990
success : function(response) {
989-
if (typeof response == 'object' && response['error']) {
990-
err(response);
991-
return;
992-
}
993-
callback(response)
991+
_invoke_callback(response, callback, err);
994992
},
995993
fail : err,
996994
url : [
@@ -1068,7 +1066,9 @@ function PN_API(setup) {
10681066
xdr({
10691067
callback : jsonp,
10701068
data : data,
1071-
success : function(response) { callback(response) },
1069+
success : function(response) {
1070+
_invoke_callback(response, callback, err);
1071+
},
10721072
fail : err,
10731073
url : [
10741074
STD_ORIGIN, 'v1', 'auth', 'grant' ,
@@ -1125,7 +1125,9 @@ function PN_API(setup) {
11251125
xdr({
11261126
callback : jsonp,
11271127
data : data,
1128-
success : function(response) { callback(response) },
1128+
success : function(response) {
1129+
_invoke_callback(response, callback, err);
1130+
},
11291131
fail : err,
11301132
url : [
11311133
STD_ORIGIN, 'v1', 'auth', 'audit' ,
@@ -1156,7 +1158,7 @@ function PN_API(setup) {
11561158
},
11571159
'presence_heartbeat' : function(args) {
11581160
var callback = args['callback'] || function() {}
1159-
var error = args['error'] || function() {}
1161+
var err = args['error'] || function() {}
11601162
var jsonp = jsonp_cb();
11611163
xdr({
11621164
callback : jsonp,
@@ -1168,8 +1170,10 @@ function PN_API(setup) {
11681170
'channel' , encode(generate_channel_list(CHANNELS).join(',')),
11691171
'heartbeat'
11701172
],
1171-
success : function(response) { callback(response[0]) },
1172-
fail : function(e) { error(e); }
1173+
success : function(response) {
1174+
_invoke_callback(response, callback, err);
1175+
},
1176+
fail : function(e) { err(e); }
11731177
});
11741178
},
11751179

0 commit comments

Comments
 (0)