jimsynz / faye-rails

Simple Rails glue for the Faye messaging protocol.
MIT License
435 stars 79 forks source link

User's online status #72

Closed przbadu closed 9 years ago

przbadu commented 9 years ago

Hi, I am using private_pub gem to configure faye in my applicaiton.

# private_pub.ru

# Run with: rackup private_pub.ru -s thin -E production
require "bundler/setup"
require "yaml"
require "faye"
require "private_pub"

# Only load rails environment if required
# we are calling sidekiq so it is required
require ::File.expand_path('../config/environment',  __FILE__)

Faye::WebSocket.load_adapter('thin')

PrivatePub.load_config(File.expand_path("../config/private_pub.yml", __FILE__), ENV["RAILS_ENV"] || "development")
# run PrivatePub.faye_app

# UPDATED CODE - 
# added functionality in gem
app = PrivatePub.faye_app

# subscribe - online
app.bind(:subscribe) do |client_id, channel|
  puts "Client subscribe: #{client_id}:#{channel}"

  if /\/user\/*/.match(channel)
    p "ok ****8"
    SubscribeClient.perform_async(client_id, channel)
  end
end

# unsubscribe - offline
app.bind(:unsubscribe) do |client_id, channel|
  puts "Client unsubscribe: #{client_id}:#{channel}"
  UnsubscribeClient.perform_async(client_id)
end

# disconnect - offline
app.bind(:disconnect) do |client_id|
  puts "Client disconnect: #{client_id}"
  UnsubscribeClient.perform_async(client_id)
end

run app

PROBLEM

Now, my problem is, when I close browser or browser tab where my app is running, the disconnect event fires up:

e.g:

    # console log
    Client disconnect: 7q30kyezc4d68kjnyuik9quw42tqk2u

1) But when did subscribe and unsubscribe events trigger? unsubscribe is not triggering when I close browser / tab. Only disconnect is triggered. 2) Also, when is subscribe triggered? When I reconnect to application again, it is not triggering.

What I want now is, When user disconnect from the app, I will update that user to offline mode and if he come back to application, I have to update him to online mode again.....How can I acheive this??

jimsynz commented 9 years ago

Hi @przbadu the https://github.com/ryanb/private_pub gem has nothing to do with this project. I suggest you raise this issue over there. Cheers. /cc @ryanb