2015-02-10 88 views
0

我正在從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訂閱。

回答

0

深化@TheNastyOne回答一點,你可以關閉套接字從dispatcher在客戶端這樣的連接:

// Open connection. 
var dispatcher = new WebSocketRails('localhost:3000/websocket'); 

// Close connection. 
dispatcher.disconnect(); 

Here生活描述兩種方法的問題。