Module: Tina4::DevReload
- Defined in:
- lib/tina4/websocket.rb
Overview
Shared, process-wide manager for the dev-reload channel (/__dev_reload).
Every browser that loads a page in debug mode opens a WebSocket here and keeps it open. POST /__dev/api/reload (issued by the tina4 Rust CLI on a file change) calls Tina4::DevReload.broadcast(…) to push an instant file, mtime message to every connected client — no respawn, no poll. Mirrors Python’s single ‘_ws_manager` holding /__dev_reload connections by path; in Ruby each route upgrade otherwise spins its own isolated WebSocket engine, so a dedicated shared manager is what makes a broadcast reach all clients.
Class Method Summary collapse
-
.add(connection) ⇒ Object
Register an open connection so a later broadcast reaches it.
-
.broadcast(message) ⇒ Object
Push a text frame to every connected dev-reload client.
-
.count ⇒ Object
Number of live dev-reload clients (used by tests / introspection).
-
.manager ⇒ Object
The shared WebSocket manager that holds every /__dev_reload connection.
-
.remove(connection) ⇒ Object
Drop a connection on close.
Class Method Details
.add(connection) ⇒ Object
Register an open connection so a later broadcast reaches it.
369 370 371 |
# File 'lib/tina4/websocket.rb', line 369 def add(connection) manager.connections[connection.id] = connection end |
.broadcast(message) ⇒ Object
Push a text frame to every connected dev-reload client. Best-effort: a dead socket or zero clients must never raise into the caller (the /__dev/api/reload endpoint), so failures are swallowed per-connection.
386 387 388 389 390 391 392 |
# File 'lib/tina4/websocket.rb', line 386 def broadcast() manager.connections.values.each do |conn| conn.send_text() rescue StandardError next end end |
.count ⇒ Object
Number of live dev-reload clients (used by tests / introspection).
379 380 381 |
# File 'lib/tina4/websocket.rb', line 379 def count manager.connections.size end |
.manager ⇒ Object
The shared WebSocket manager that holds every /__dev_reload connection.
364 365 366 |
# File 'lib/tina4/websocket.rb', line 364 def manager @mutex.synchronize { @manager ||= Tina4::WebSocket.new } end |
.remove(connection) ⇒ Object
Drop a connection on close.
374 375 376 |
# File 'lib/tina4/websocket.rb', line 374 def remove(connection) manager.connections.delete(connection.id) end |