Dashing is a Sinatra based framework that lets you build beautiful dashboards. It looks especially great on TVs.
[New EventEngines and websocket support] (https://github.com/kneradovsky/dashing/tree/websockets)
The calling job files code was moved from the gem level to the project level (config.ru). To make you existent jobs and lib files to be called from application one need to add the following lines of code:
{}.to_json # Forces your json codec to initialize (in the event that it is lazily loaded). Does this before job threads start.
job_path = ENV["JOB_PATH"] || 'jobs'
require_glob(File.join('lib', '**', '*.rb'))
require_glob(File.join(job_path, '**', '*.rb'))
to the end of the project's config.ru file
Dashing provides two engines for processing events to and from clients. ServerSentEvents and WebSockets. The ServerSentEvents engine provides one way comunication from the dashing server to a client. WebSockets engine provides two way communication and supports subscriptions to reduce traffic between the server and the client. A dashboard automatically subscribes to receive message only for widgets it contains.
Dashing is using eventsengine setting as engine instance reference. One can select the engine type during the configuration of the application:
config.ru:
configure do
set :auth_token, 'YOUR_AUTH_TOKEN'
set :eventsengine, EventsEngine.create(EventsEngineTypes::WS)
end
The above selects websocket engine.
Currently supported engines are:
- ServerSideEvents - EventsEngineTypes::SSE
- WebSockets - EventsEngineTypes::WS
To add an engine, you need to provide a route for accepting request and subclass EventsEngine class. Optionally you could add a constant to the EventsEngineType module to improve code readability. You also need to add engine on the client side.
1. add constant
module EventsEngineTypes
WEBSOCKET2="WS2" #new web socket implementation
end
2. route:
get '/events', provides: 'text/event-stream' do
protected!
response.headers['X-Accel-Buffering'] = 'no' # Disable buffering for nginx
stream :keep_open do |out|
settings.eventsengine.openConnection(out)
end
end
3. subclass EventsEngine: You need to subclass EventsEngine class, register your new engine and implement send_event and stop methods
class NewCoolWebSockets < EventsEngine
register_engine EventsEngineTypes::WEBSOCKET2
def stop
end
def send_event(body, target=nil)
end
end
4. add engine on the client side
$(document).ready ->
if Configuration.EventEngine=="WS2"
Dashing.source= ->
.... create your own engine...
Please note that client side uses the value of the EventsEngineType's constant, not its name
Distributed under the MIT license