Class: RailsConsole::ConsoleChannel
- Inherits:
-
ActionCable::Channel::Base
- Object
- ActionCable::Channel::Base
- RailsConsole::ConsoleChannel
- Defined in:
- app/channels/rails_console/console_channel.rb
Instance Method Summary collapse
-
#receive(data) ⇒ Object
Keystrokes from the browser: decode and forward them to the broker.
-
#subscribed ⇒ Object
Connects an authorized user to the broker and starts streaming its output back.
-
#unsubscribed ⇒ Object
Closes the broker connection when the browser leaves.
Instance Method Details
#receive(data) ⇒ Object
Keystrokes from the browser: decode and forward them to the broker.
9 10 11 12 13 14 15 |
# File 'app/channels/rails_console/console_channel.rb', line 9 def receive(data) bytes = Base64.strict_decode64(data.fetch('bytes')) @socket&.write(bytes) rescue ArgumentError, Errno::EPIPE, IOError nil end |
#subscribed ⇒ Object
Connects an authorized user to the broker and starts streaming its output back.
18 19 20 21 22 23 24 25 26 27 |
# File 'app/channels/rails_console/console_channel.rb', line 18 def subscribed return reject if !RailsConsole.(connection) return reject_unavailable if !RailsConsole::Broker.boot @socket = connect_to_broker @reader_thread = Thread.new { relay_broker_output } rescue Errno::ECONNREFUSED, Errno::ENOENT reject_unavailable end |
#unsubscribed ⇒ Object
Closes the broker connection when the browser leaves.
30 31 32 33 34 35 |
# File 'app/channels/rails_console/console_channel.rb', line 30 def unsubscribed @reader_thread&.kill @socket&.close rescue IOError nil end |