How do I get a Faye client given a client ID?

依然范特西╮ 提交于 2019-12-12 21:57:22

问题


Faye allows you to monitor various events, such as handshake or subscribe. These callback blocks are only supplied the client_id value rather than the client itself. For example:

server = Faye::RackAdapter.new(mount: '/faye', timeout: 45)

server.bind(:handshake) do |client_id|
  puts "Received handshake from #{client_id}"
end

How can I access the client given the client_id? Or how can I access more information in the handshake, such as cookies provided in the request header (if that info is even available)?


回答1:


I think my original question is based upon a lack of understanding on how Faye works in two regards. Instead of deleting my question, I'm going to answer it for anyone else who comes across this with a similar question. (If my answer is wrong in any way, please comment or edit!)

First, at no point is access to the connected client available due to the way Faye is implemented with regards to the Bayeux protocol. All communications are carried out via channel broadcasting, meaning all connections listening to a channel will receive the message being sent.

Second, the code I pasted in the question deals with monitoring. What I'm really looking for is an extension.

In order to achieve authentication given my original question, I need to pass whatever authentication value is needed (whether it's a cookie value, auth token, etc.) as part of the message['ext'] value (per the example on the extensions page). Then, on the server side, I need to listen for messages on the /meta/handshake channel, setting message['error'] to some value in the case of value.



来源:https://stackoverflow.com/questions/12480122/how-do-i-get-a-faye-client-given-a-client-id

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!