Class: Tidewave::BrowserControl::Channel
- Inherits:
-
ActionCable::Channel::Base
- Object
- ActionCable::Channel::Base
- Tidewave::BrowserControl::Channel
- Defined in:
- lib/tidewave/browser_control.rb
Overview
Handles a single control page connection.
Instance Method Summary collapse
-
#initialize(connection, identifier, params = {}) ⇒ Channel
constructor
A new instance of Channel.
- #receive(data) ⇒ Object
- #unsubscribed ⇒ Object
Constructor Details
#initialize(connection, identifier, params = {}) ⇒ Channel
Returns a new instance of Channel.
171 172 173 174 175 176 |
# File 'lib/tidewave/browser_control.rb', line 171 def initialize(connection, identifier, params = {}) super @mutex = Mutex.new @name = nil @pending_refs = {} end |
Instance Method Details
#receive(data) ⇒ Object
178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/tidewave/browser_control.rb', line 178 def receive(data) case data["type"] when "hello" hello(data["name"]) when "tool_reply" tool_reply(data) end # "ping" and unknown messages are ignored; the page pings to keep # the socket alive through proxies end |
#unsubscribed ⇒ Object
190 191 192 193 194 195 196 197 198 199 200 |
# File 'lib/tidewave/browser_control.rb', line 190 def unsubscribed server.client_registry.unregister(@name, self) if @name refs = @mutex.synchronize do @pending_refs.keys.tap { @pending_refs.clear } end refs.each do |ref| server.broadcast(BrowserControl.reply_stream(ref), { "type" => "disconnected" }) end end |