     @channels[instanceChannel].emit eventName, body
 
 
-  getTimeDiffWithServer: ->
-    @pubnub.time (serverTime) =>
-
-      return  unless serverTime
-
-      diff = new Date() * 10000 - serverTime
-      # when time difference between pubnub server and client is less than 500ms
-      # ignore the difference
-      @timeDiff = if Math.abs(diff) < 5000000 then 0 else diff
-
   handleError: (err) ->
     {message, payload} = err
+
+    if @isDisconnected err
+      @lastSeenOnline = @serverTimestamp
 
     return warn err  unless payload?.channels
 

        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) ->

        uuid          : KD.whoami()._id
        ssl           : if KD.config.environment is 'dev' then window.location.protocol is 'https:' else ssl

      realtimeToken = Cookies.get("realtimeToken")

      @fetchServerTime()
      setInterval =>
        @fetchServerTime()
      , 10000

      if realtimeToken?
        @pubnub.auth realtimeToken
