我正在從ActionController:Live
切換到websocket-rails
,我只是想知道如何在用戶關閉瀏覽器窗口後關閉服務器端的連接?websocket-rails如何關閉套接字連接?
隨着ActionController的:活着,我曾經有過:
def stream
response.headers['Content-Type'] = 'text/event-stream'
@redis_sub = RedisStream.new_redis_client
# Subscribing to user's stream by session token
@redis_sub.subscribe([ token ]) do |on|
on.message do |channel, msg|
## Did stuff
response.stream.write(msg)
end
end
rescue IOError
"\n\nIOError in controller"
rescue ClientDisconnected
puts "\n\nClient has disconnected\n\n"
ensure
@redis_sub.quit
response.stream.close
end
這工作得很好,我現在試圖做同樣的事情,這一點,但使用的WebSockets,我想知道如何關閉連接並退出我的redis訂閱。
任何想法如何在websocket控制器之外做到這一點? – blnc 2015-07-10 14:41:37