 
     @userRef.child("status").onDisconnect().set "offline"
 
+    @requestPingRef.on "value", (snapshot) =>
+      return unless @amIHost()
+      @userRef.child("timestamp").set Date.now()
+
+    @usersRef.child(@getHost()).child("timestamp").on "value", (snapshot) =>
+      return if @amIHost() or @connected or snapshot.val() is null
+      @syncWorkspace()
+      @connected = yes
+
+  requestPingFromHost: ->
+    @requestPingRef.set Date.now()
+
   fetchUsers: ->
     @workspaceRef.once "value", (snapshot) =>
       val = snapshot.val()


      # TODO: Each time we are fetching user data that we already have. Needs to be fixed.
      KD.remote.api.JAccount.some { "profile.nickname": { "$in": usernames } }, {}, (err, jAccounts) =>
        @users[user.profile.nickname] = user for user in jAccounts
        @emit "WorkspaceUsersFetched"

  createPanel: (callback = noop) ->


    new KDNotificationView options

  setPresenceHandler: ->
    if @amIHost()
      @presenceInterval = @utils.repeat 10000, =>
        @userRef.child("timestamp").set Date.now(), (err) =>
          return  unless err
          @utils.killRepeat @presenceInterval
    else
      @presenceInterval = @utils.repeat 10000, @bound "pingHost"

    @once "KDObjectWillBeDestroyed", =>
      @killPresenceTimer()

  checkHost: (snapshot, callback) ->
    host = snapshot.val()
    return @showNotActiveView()  unless host

    diff = Date.now() - host.timestamp

    if diff <= 15000
      @hideNotification()
      @hostStatus = "online"
    else if diff >= 30000
      @hideNotification()
      @showNotActiveView()
      @hostStatus = "offline"
    else if diff >= 15000
      @showNotification "Host is experiencing connectivity issues"
      @hostStatus = "unknown"

