我正在从ActionController:Live
切换到websocket-rails
,我只是想知道一旦用户关闭浏览器窗口,如何关闭服务器端的连接?
使用ActionController:Live我曾经拥有:
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
"nnIOError in controller"
rescue ClientDisconnected
puts "nnClient has disconnectednn"
ensure
@redis_sub.quit
response.stream.close
end
这很好,现在我正在尝试做同样的事情,但使用websocket,我想知道如何关闭连接并退出我的redis订阅。
connection.close!
。
https://github.com/websocket-rails/websocket-rails/issues/219
要在@TheNastyOne中加深一点答案,您可以关闭客户端dispatcher
的套接字连接,如下所示:
// Open connection.
var dispatcher = new WebSocketRails('localhost:3000/websocket');
// Close connection.
dispatcher.disconnect();
这就是描述这两种方法的问题。