         uuid          : KD.whoami()._id
         ssl           : if KD.config.environment is 'dev' then window.location.protocol is 'https:' else ssl
 
-      @getTimeDiffWithServer()
-
       realtimeToken = Cookies.get("realtimeToken")
+
+      @fetchServerTime()
+      setInterval =>
+        @fetchServerTime()
+      , 10000
 
       if realtimeToken?
         @pubnub.auth realtimeToken

        error   : (err) =>
          @handleError err
          callback err  unless callbackCalled
        reconnect: => @getTimeDiffWithServer()
        # with each channel subscription pubnub resubscribes to every channel
        # and some messages are dropped in this resubscription time interval
        # for this reason for every subscribe request, we are fetching all messages sent
        # in last 3 seconds
        # another issue is if user's computer time is ahead of server, it is not receiving the events.
        # this timeDiff is added because of this problem. https://www.pivotaltracker.com/story/show/87093608
        timetoken: (((new Date()).getTime() - 3000) * 10000) - @timeDiff
        restore : yes


  handleMessage: (message, channel) ->


        @authenticated = yes
        @emit 'authenticated'


  fetchServerTime: ->
    @pubnub.time (timestamp) =>
      return  unless timestamp

      @serverTimestamp = timestamp
      @emit 'Ping', timestamp


  # channel authentication is needed for notification channel and
