What I am doing is the following:
When a user starts a new faye client, he also publishes a message on
the channel /presence/connect.
Then I monitor that event with the following code
faye_server.bind(:publish) do |client_id, channel, data|
if channel == '/presence/connect'
FayeUtils.client_connected :user_id => data['user_id'], :client_id
=> client_id
FayeUtils.update_contacts_list
end
end
where FayeUtils.client_connected handles all the logic.
FayeUtils.update_contacts_list tries to publish a new message to all
faye clients.
The missing part is the update of the online contacts list inside the
browsers.
If I try to publish data via a server client inside
FayeUtils.update_contacts_list, faye hangs.
It doesn't look like an infinite loop caused by recursion, but more
like if something goes in timeout.
Any idea on how to inspect that or is there any better way to
implement that?
Thank you.
faye_server.bind(:publish) do |client_id, channel, data|
if channel == '/presence/connect'
FayeUtils.client_connected :user_id => data['user_id'], :client_id
=> client_id
FayeUtils.update_contacts_list
end
end
where FayeUtils.client_connected handles all the logic.
FayeUtils.update_contacts_list tries to publish a new message to all
faye clients.
On Dec 13, 8:37 am, James Coglan <jcog...@gmail.com> wrote:
> On 9 December 2011 00:17, slampis <stefanolam...@gmail.com> wrote:
>
> > faye_server.bind(:publish) do |client_id, channel, data|
>
> > if channel == '/presence/connect'
> > FayeUtils.client_connected :user_id => data['user_id'], :client_id
> > => client_id
> > FayeUtils.update_contacts_list
> > end
>
> > end
>
> > where FayeUtils.client_connected handles all the logic.
> > FayeUtils.update_contacts_list tries to publish a new message to all
> > faye clients.
>
> Can you publish all the code involved in this, or is that not possible?
> That would make it easier to debug. What I assume your code is doing is:
>
> * client_connected() adds the user_id to a set and probably maps the
> user_id to its current client_id
> * update_contacts_list() does something like, client.publish('/present',
> 'user_ids' => all_the_user_ids)
Your assumptions are right, if it helps I will post my code as I get
home.
For now, I can tell you that update_contacts_list does not use
client.publish but makes a direct HTTP POST to faye with restclient.
The restclient call is correct, I know because I use it in other
contexts.
>
> What type of client are you using to do this? Do you know how it's
> connected? Is it connected via WebSocket/HTTP or is the in-process
> faye_server.get_client connection?
By client you mean server client? If yes, any client: as I said I make
a simple HTTP request.
I don't understand the second question. How can I obtain that
information?
For now, I can tell you that update_contacts_list does not use
client.publish but makes a direct HTTP POST to faye with restclient.
The restclient call is correct, I know because I use it in other
contexts.
rackup faye.ru
which contains a line like
bayeux = Faye::RackAdapter.new(:mount => '/faye', :timeout => 25)
and then something like
run bayeux
As you can see my code is based on the basic example.
Can you confirm that this approach starts a single threaded server?
I've given a quick look to faye-websocket. I understand that it would
be easy to implement a simple server, but my question is?
Can I still use the faye javascript client?
If yes, do I lost compatibility with browsers which are not supporting
web sockets?
On Dec 13, 8:59 am, James Coglan <jcog...@gmail.com> wrote:
This sounds reasonable because I am starting faye with something like
rackup faye.ru
which contains a line like
bayeux = Faye::RackAdapter.new(:mount => '/faye', :timeout => 25)
and then something like
run bayeux
As you can see my code is based on the basic example.
Can you confirm that this approach starts a single threaded server?
I've given a quick look to faye-websocket. I understand that it would
be easy to implement a simple server, but my question is?
Can I still use the faye javascript client?
If yes, do I lost compatibility with browsers which are not supporting
web sockets?
rackup faye.ru -D -s thin -E production -p 9292
but still, it hangs under the conditions I have described.
If it helps, I am using ruby EE, so it's ruby 1.8.7
On Dec 13, 9:26 am, James Coglan <jcog...@gmail.com> wrote:
I've checked out my scripts and this is the exact command I use to
start faye
rackup faye.ru -D -s thin -E production -p 9292
but still, it hangs under the conditions I have described.
On Dec 14, 1:26 pm, James Coglan <jcog...@gmail.com> wrote:
> On 14 December 2011 10:23, Stefano Lampis <stefanolam...@gmail.com> wrote:
>
> > I've checked out my scripts and this is the exact command I use to
> > start faye
>
> > rackup faye.ru -D -s thin -E production -p 9292
>
> > but still, it hangs under the conditions I have described.
>
> I can confirm that making a blocking call blocks Thin: run this:
>
> require 'rack'
> require 'uri'
> require 'net/http'
>
> app = lambda do |env|
> body = case env['PATH_INFO']
> when '/hi'
> uri = URI.parse('http://localhost:8000/')
> Net::HTTP.get_response(uri).body
> else
> 'Hello!'
> end
>
> [200, {'Content-Type' => 'text/plain'}, [body]]
> end
>
> handler = Rack::Handler.get('thin')
> handler.run(app, :Port => 8000)
>
> If you requesthttp://localhost:8000/hi, the server hangs. This is because
Can you provide an example for use Faye client in server events?
I need to use a client in server subscribe event but I'm not sure of
the right way to achieve this.
Thank you
Can you provide an example for use Faye client in server events?
I need to use a client in server subscribe event but I'm not sure of
the right way to achieve this.
I try to use it in my server:
faye_server.bind(:subscribe) do |client_id, channel|
# USE CLIENT HERE
end
So can I do something like faye_server.get_client.publish here ?
Thanks
On Dec 19, 11:16 am, Stefano Lampis <stefanolam...@gmail.com> wrote:
> This is very simple, just use the self.get_client method to obtain the ruby
> client. Then you can publish whatever you want.
>
> self.get_client.publish '/channel/name', { ... }
>
> --
> Stefano Lampis
>
faye_server.bind(:subscribe) do |client_id, channel|
# USE CLIENT HERE
end
So can I do something like faye_server.get_client.publish here ?
Thank you very much for the answers.
Jerome
On Dec 19, 11:31 am, James Coglan <jcog...@gmail.com> wrote: