See also https://github.com/rails/rails/pull/29390 about using proper close codes for WebSockets.
On Thu, Oct 4, 2018 at 1:45 PM, Artis Abolts <artis.abo...@gmail.com> wrote: > WebSocket.close() method accept two optional parameters: > > > 1. code - A numeric value indicating the status code explaining why > the connection is being closed. > 2. reason - A human-readable string explaining why the connection is > closing. > > More info: https://developer.mozilla.org/en-US/docs/Web/API/WebSocket/ > close > > > > > Real live example where and how my proposed changes would work in Rails > > > > For example by terminating subscription from server if User session expired > > > ActionCable.server > .remote_connections > .where(current_user: warden_proxy.user) > .disconnect(4001, "Unauthorized") > > > On JavaScript side possibility to receive WebSocket close code and reason. > For example if WebSocket closed because User session expired then we > redirect to root path > > > disconnected: (data) -> > # Called when the subscription has been terminated by the server > > # If Unauthorized (Session Terminated or Expired) > if data.statusCode == 4001 > window.location = "/" > > > > In Rails ActionCable there is needed only couple changes to support > WebSocket close code and reason. > > Please check my implementation in my Fork: https://github.com/aboltart/ > rails/commit/be168f16118f5848d0d3a9165afeafb6717a71f8 > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Core" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to rubyonrails-core+unsubscr...@googlegroups.com. > To post to this group, send email to rubyonrails-core@googlegroups.com. > Visit this group at https://groups.google.com/group/rubyonrails-core. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-core+unsubscr...@googlegroups.com. To post to this group, send email to rubyonrails-core@googlegroups.com. Visit this group at https://groups.google.com/group/rubyonrails-core. For more options, visit https://groups.google.com/d/optout.