Module: Rapid::Server::Helpers::Streaming

Defined in:
lib/ury_rapid/server/helpers/streaming.rb

Overview

Sinatra helper for HTTP and WebSocket update streaming

This depends on the Sinatra::Streaming helper set.

Instance Method Summary collapse

Instance Method Details

#model_updates_streamObject

Sets up a connection to the model updates stream.


20
21
22
# File 'lib/ury_rapid/server/helpers/streaming.rb', line 20

def model_updates_stream
  send(request.websocket? ? :websocket_update : :stream_update)
end

#stream_updateObject


24
25
26
27
28
# File 'lib/ury_rapid/server/helpers/streaming.rb', line 24

def stream_update
  content_type 'application/json', charset: 'utf-8'
  privs = privilege_set
  stream(:keep_open) { |s| StreamUpdater.launch(@model, s, privs) }
end

#websocket_updateObject


30
31
32
33
34
35
36
37
# File 'lib/ury_rapid/server/helpers/streaming.rb', line 30

def websocket_update
  privs = privilege_set(true)
  request.websocket do |websocket|
    WebSocketUpdater.launch(
      @model, websocket, @authenticator.method(:authenticate), privs
    )
  end
end