@@ -320,7 +320,7 @@ return /******/ (function(modules) { // webpackBootstrap
320320 this . _maxSubDomain = 20 ;
321321 this . _currentSubDomain = Math . floor ( Math . random ( ) * this . _maxSubDomain ) ;
322322
323- this . _providedFQDN = ( config . isSslEnabled ( ) ? 'https://' : 'http://' ) + config . getOrigin ( ) ;
323+ this . _providedFQDN = ( this . _config . secure ? 'https://' : 'http://' ) + this . _config . origin ;
324324 this . _coreParams = { } ;
325325
326326 this . shiftStandardOrigin ( false ) ;
@@ -368,31 +368,6 @@ return /******/ (function(modules) { // webpackBootstrap
368368
369369 return this . _subscribeOrigin ;
370370 }
371- } , {
372- key : 'performHeartbeat' ,
373- value : function performHeartbeat ( channels , incomingData , callback ) {
374- if ( ! this . _config . getSubscribeKey ( ) ) {
375- return callback ( this . _r . validationError ( 'Missing Subscribe Key' ) ) ;
376- }
377-
378- var data = this . prepareParams ( incomingData ) ;
379-
380- var url = [ this . getStandardOrigin ( ) , 'v2' , 'presence' , 'sub-key' , this . _config . getSubscribeKey ( ) , 'channel' , channels , 'heartbeat' ] ;
381-
382- if ( this . _config . getAuthKey ( ) ) {
383- data . auth = this . _config . getAuthKey ( ) ;
384- }
385-
386- if ( this . _config . getUUID ( ) ) {
387- data . uuid = this . _config . getUUID ( ) ;
388- }
389-
390- if ( this . _config . isRequestIdEnabled ( ) ) {
391- data . requestid = _utils2 . default . generateUUID ( ) ;
392- }
393-
394- this . _xdr ( { data : data , callback : callback , url : url } ) ;
395- }
396371 } , {
397372 key : 'fetchHereNow' ,
398373 value : function fetchHereNow ( channel , channelGroup , incomingData , callback ) {
@@ -4174,11 +4149,12 @@ return /******/ (function(modules) { // webpackBootstrap
41744149 this . baseParams = setup . params || { } ;
41754150 this . UUID = setup . uuid || _uuid2 . default . v4 ( ) ;
41764151
4152+ this . origin = setup . origin || 'pubsub.pubnub.com' ;
4153+ this . secure = setup . ssl || false ;
4154+
41774155 this . setRequestIdConfig ( setup . useRequestId || false ) ;
41784156 this . setSupressLeaveEvents ( setup . suppressLeaveEvents || false ) ;
41794157 this . setInstanceIdConfig ( setup . useInstanceId || false ) ;
4180- this . setSslConfig ( setup . ssl || false ) ;
4181- this . setOrigin ( setup . origin || 'pubsub.pubnub.com' ) ;
41824158
41834159 this . setTransactionTimeout ( setup . transactionalRequestTimeout || 15 * 1000 ) ;
41844160
@@ -4198,6 +4174,28 @@ return /******/ (function(modules) { // webpackBootstrap
41984174 value : function setCipherKey ( val ) {
41994175 this . cipherKey = val ; return this ;
42004176 }
4177+ } , {
4178+ key : 'getPresenceTimeout' ,
4179+ value : function getPresenceTimeout ( ) {
4180+ return this . _presenceTimeout ;
4181+ }
4182+ } , {
4183+ key : 'setPresenceTimeout' ,
4184+ value : function setPresenceTimeout ( val ) {
4185+ this . _presenceTimeout = val ;
4186+ this . _presenceAnnounceInterval = this . _presenceTimeout / 2 - 1 ;
4187+ return this ;
4188+ }
4189+ } , {
4190+ key : 'getPresenceAnnounceInterval' ,
4191+ value : function getPresenceAnnounceInterval ( ) {
4192+ return this . _presenceAnnounceInterval ;
4193+ }
4194+ } , {
4195+ key : 'setPresenceAnnounceInterval' ,
4196+ value : function setPresenceAnnounceInterval ( val ) {
4197+ this . _presenceAnnounceInterval = val ; return this ;
4198+ }
42014199 } , {
42024200 key : 'isInstanceIdEnabled' ,
42034201 value : function isInstanceIdEnabled ( ) {
@@ -4248,26 +4246,6 @@ return /******/ (function(modules) { // webpackBootstrap
42484246 value : function setSupressLeaveEvents ( val ) {
42494247 this . _suppressLeaveEvents = val ; return this ;
42504248 }
4251- } , {
4252- key : 'isSslEnabled' ,
4253- value : function isSslEnabled ( ) {
4254- return this . _sslEnabled ;
4255- }
4256- } , {
4257- key : 'setSslConfig' ,
4258- value : function setSslConfig ( val ) {
4259- this . _sslEnabled = val ; return this ;
4260- }
4261- } , {
4262- key : 'getOrigin' ,
4263- value : function getOrigin ( ) {
4264- return this . _customOrigin ;
4265- }
4266- } , {
4267- key : 'setOrigin' ,
4268- value : function setOrigin ( val ) {
4269- this . _customOrigin = val ; return this ;
4270- }
42714249 } , {
42724250 key : 'isSendBeaconEnabled' ,
42734251 value : function isSendBeaconEnabled ( ) {
@@ -4278,28 +4256,6 @@ return /******/ (function(modules) { // webpackBootstrap
42784256 value : function setSendBeaconConfig ( val ) {
42794257 this . _useSendBeacon = val ; return this ;
42804258 }
4281- } , {
4282- key : 'getPresenceTimeout' ,
4283- value : function getPresenceTimeout ( ) {
4284- return this . _presenceTimeout ;
4285- }
4286- } , {
4287- key : 'setPresenceTimeout' ,
4288- value : function setPresenceTimeout ( val ) {
4289- this . _presenceTimeout = val ;
4290- this . _presenceAnnounceInterval = this . _presenceTimeout / 2 - 1 ;
4291- return this ;
4292- }
4293- } , {
4294- key : 'getPresenceAnnounceInterval' ,
4295- value : function getPresenceAnnounceInterval ( ) {
4296- return this . _presenceAnnounceInterval ;
4297- }
4298- } , {
4299- key : 'setPresenceAnnounceInterval' ,
4300- value : function setPresenceAnnounceInterval ( val ) {
4301- this . _presenceAnnounceInterval = val ; return this ;
4302- }
43034259 } ] ) ;
43044260
43054261 return _class ;
@@ -5415,11 +5371,57 @@ return /******/ (function(modules) { // webpackBootstrap
54155371 key : 'reconnect' ,
54165372 value : function reconnect ( ) {
54175373 this . _startSubscribeLoop ( ) ;
5374+ this . _registerHeartbeatTimer ( ) ;
5375+ }
5376+ } , {
5377+ key : 'disconnect' ,
5378+ value : function disconnect ( ) {
5379+ this . _stopSubscribeLoop ( ) ;
5380+ }
5381+ } , {
5382+ key : '_registerHeartbeatTimer' ,
5383+ value : function _registerHeartbeatTimer ( ) {
5384+ this . _stopHeartbeatTimer ( ) ;
5385+ this . _heartbeatTimer = setInterval ( this . _performHeartbeatLoop . bind ( this ) , this . _config . getPresenceAnnounceInterval ( ) * 1000 ) ;
5386+ }
5387+ } , {
5388+ key : '_stopHeartbeatTimer' ,
5389+ value : function _stopHeartbeatTimer ( ) {
5390+ if ( this . _heartbeatTimer ) {
5391+ clearInterval ( this . _heartbeatTimer ) ;
5392+ this . _heartbeatTimer = null ;
5393+ }
5394+ }
5395+ } , {
5396+ key : '_performHeartbeatLoop' ,
5397+ value : function _performHeartbeatLoop ( ) {
5398+ var _this4 = this ;
5399+
5400+ var presenceChannels = Object . keys ( this . _channels ) ;
5401+ var presenceChannelGroups = Object . keys ( this . _channelGroups ) ;
5402+ var presenceState = { } ;
5403+
5404+ presenceChannels . forEach ( function ( channel ) {
5405+ var channelState = _this4 . _channels [ channel ] . state ;
5406+ if ( channelState ) presenceState [ channel ] = channelState ;
5407+ } ) ;
5408+
5409+ presenceChannelGroups . forEach ( function ( channelGroup ) {
5410+ var channelGroupState = _this4 . channelGroup [ channelGroup ] . state ;
5411+ if ( channelGroupState ) presenceState [ channelGroup ] = channelGroupState ;
5412+ } ) ;
5413+
5414+ this . _presenceEndpoints . heartbeat ( {
5415+ channels : presenceChannels ,
5416+ channelGroups : presenceChannelGroups ,
5417+ state : presenceState } , function ( status ) {
5418+ console . log ( status ) ;
5419+ } ) ;
54185420 }
54195421 } , {
54205422 key : '_startSubscribeLoop' ,
54215423 value : function _startSubscribeLoop ( ) {
5422- var _this4 = this ;
5424+ var _this5 = this ;
54235425
54245426 this . _stopSubscribeLoop ( ) ;
54255427 var channels = [ ] ;
@@ -5449,8 +5451,7 @@ return /******/ (function(modules) { // webpackBootstrap
54495451 region : this . _region
54505452 } , function ( status , payload ) {
54515453 if ( status . error ) {
5452- console . log ( "subscribe tanked" ) ;
5453- _this4 . _startSubscribeLoop ( ) ;
5454+ _this5 . _startSubscribeLoop ( ) ;
54545455 return ;
54555456 }
54565457
@@ -5472,26 +5473,26 @@ return /******/ (function(modules) { // webpackBootstrap
54725473 announce . occupancy = message . payload . occupancy ;
54735474 announce . uuid = message . payload . uuid ;
54745475 announce . timestamp = message . payload . timestamp ;
5475- _this4 . _announcePresence ( announce ) ;
5476+ _this5 . _announcePresence ( announce ) ;
54765477 } else {
54775478 var _announce = { } ;
54785479 _announce . actualChannel = subscriptionMatch != null ? channel : null ;
54795480 _announce . subscribedChannel = subscriptionMatch != null ? subscriptionMatch : channel ;
54805481 _announce . timetoken = publishMetaData . publishTimetoken ;
54815482
5482- if ( _this4 . _config . cipherKey ) {
5483- _announce . message = _this4 . _crypto . decrypt ( message . payload ) ;
5483+ if ( _this5 . _config . cipherKey ) {
5484+ _announce . message = _this5 . _crypto . decrypt ( message . payload ) ;
54845485 } else {
54855486 _announce . message = message . payload ;
54865487 }
54875488
5488- _this4 . _announceMessage ( _announce ) ;
5489+ _this5 . _announceMessage ( _announce ) ;
54895490 }
54905491 } ) ;
54915492
5492- _this4 . _region = payload . metadata . region ;
5493- _this4 . _timetoken = payload . metadata . timetoken ;
5494- _this4 . _startSubscribeLoop ( ) ;
5493+ _this5 . _region = payload . metadata . region ;
5494+ _this5 . _timetoken = payload . metadata . timetoken ;
5495+ _this5 . _startSubscribeLoop ( ) ;
54955496 } ) ;
54965497 }
54975498 } , {
@@ -6383,6 +6384,42 @@ return /******/ (function(modules) { // webpackBootstrap
63836384 callback ( status , response ) ;
63846385 } ) ;
63856386 }
6387+ } , {
6388+ key : 'heartbeat' ,
6389+ value : function heartbeat ( args , callback ) {
6390+ var _args$channels5 = args . channels ;
6391+ var channels = _args$channels5 === undefined ? [ ] : _args$channels5 ;
6392+ var _args$channelGroups5 = args . channelGroups ;
6393+ var channelGroups = _args$channelGroups5 === undefined ? [ ] : _args$channelGroups5 ;
6394+ var _args$state = args . state ;
6395+ var state = _args$state === undefined ? { } : _args$state ;
6396+
6397+ var stringifiedChannels = channels . length > 0 ? channels . join ( ',' ) : ',' ;
6398+ var endpointConfig = {
6399+ params : {
6400+ uuid : { required : false } ,
6401+ authKey : { required : false }
6402+ } ,
6403+ url : '/v2/presence/sub-key/' + this . config . subscribeKey + '/channel/' + encodeURIComponent ( stringifiedChannels ) + '/heartbeat'
6404+ } ;
6405+
6406+ if ( ! this . validateEndpointConfig ( endpointConfig ) ) {
6407+ return ;
6408+ }
6409+
6410+ var params = this . createBaseParams ( endpointConfig ) ;
6411+
6412+ if ( channelGroups . length > 0 ) {
6413+ params [ 'channel-group' ] = encodeURIComponent ( channelGroups . join ( ',' ) ) ;
6414+ }
6415+
6416+ params . state = encodeURIComponent ( JSON . stringify ( state ) ) ;
6417+ params . heartbeat = this . config . getPresenceTimeout ( ) ;
6418+
6419+ this . networking . GET ( params , endpointConfig , function ( status ) {
6420+ return callback ( status ) ;
6421+ } ) ;
6422+ }
63866423 } ] ) ;
63876424
63886425 return _class ;
0 commit comments