Class: TRMNLP::App
- Inherits:
-
Sinatra::Base
- Object
- Sinatra::Base
- TRMNLP::App
- Defined in:
- lib/trmnlp/app.rb
Constant Summary collapse
- HEARTBEAT_SECONDS =
Live reload uses rack.hijack so the Puma worker thread is released the instant we have the raw socket — broadcasting then runs on our own thread, never competing with HTTP request workers. Adapted from the Faye::EventSource pattern in faye-websocket (lib/faye/rack_stream.rb) but without the EventMachine dependency: where Faye uses EM.attach to get a reactor callback on socket close, we detect close synchronously via the IOError/EPIPE raised by the next heartbeat write.
5
Instance Method Summary collapse
-
#initialize(*args) ⇒ App
constructor
A new instance of App.
Constructor Details
#initialize(*args) ⇒ App
Returns a new instance of App.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/trmnlp/app.rb', line 38 def initialize(*args) super @context = settings.context @poller = @context.poller @renderer = @context.renderer @user_data_assembler = @context.user_data_assembler @transform_pipeline = @context.transform_pipeline @watcher = @context.watcher @screenshot = Screenshot.new(pool: settings.browser_pool) @poller.poll_data @watcher.start if @context.config.project.live_render? @live_reload_clients = [] @watcher.on_change do |view, user_data| payload = { 'type' => 'reload', 'view' => view, 'user_data' => user_data } = "data: #{payload.to_json}\n\n" @live_reload_clients.each { |queue| queue << } end end |