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.
705 706 707 |
# File 'lib/tina4/websocket.rb', line 705 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.
722 723 724 725 726 727 728 |
# File 'lib/tina4/websocket.rb', line 722 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).
715 716 717 |
# File 'lib/tina4/websocket.rb', line 715 def count manager.connections.size end |
.manager ⇒ Object
The shared WebSocket manager that holds every /__dev_reload connection.
700 701 702 |
# File 'lib/tina4/websocket.rb', line 700 def manager @mutex.synchronize { @manager ||= Tina4::WebSocket.new } end |
.remove(connection) ⇒ Object
Drop a connection on close.
710 711 712 |
# File 'lib/tina4/websocket.rb', line 710 def remove(connection) manager.connections.delete(connection.id) end |