{"action":"created","issue":{"url":"https://api.github.com/repos/Shopify/dashing/issues/505","labels_url":"https://api.github.com/repos/Shopify/dashing/issues/505/labels{/name}","comments_url":"https://api.github.com/repos/Shopify/dashing/issues/505/comments","events_url":"https://api.github.com/repos/Shopify/dashing/issues/505/events","html_url":"https://github.com/Shopify/dashing/pull/505","id":54932565,"number":505,"title":"Websockets support","user":{"login":"kneradovsky","id":10231606,"avatar_url":"https://avatars.githubusercontent.com/u/10231606?v=3","gravatar_id":"","url":"https://api.github.com/users/kneradovsky","html_url":"https://github.com/kneradovsky","followers_url":"https://api.github.com/users/kneradovsky/followers","following_url":"https://api.github.com/users/kneradovsky/following{/other_user}","gists_url":"https://api.github.com/users/kneradovsky/gists{/gist_id}","starred_url":"https://api.github.com/users/kneradovsky/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kneradovsky/subscriptions","organizations_url":"https://api.github.com/users/kneradovsky/orgs","repos_url":"https://api.github.com/users/kneradovsky/repos","events_url":"https://api.github.com/users/kneradovsky/events{/privacy}","received_events_url":"https://api.github.com/users/kneradovsky/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-01-20T20:08:29Z","updated_at":"2015-01-23T06:30:09Z","closed_at":"2015-01-22T15:24:27Z","pull_request":{"url":"https://api.github.com/repos/Shopify/dashing/pulls/505","html_url":"https://github.com/Shopify/dashing/pull/505","diff_url":"https://github.com/Shopify/dashing/pull/505.diff","patch_url":"https://github.com/Shopify/dashing/pull/505.patch"},"body":"# Compatibility issue\r\nThe 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: \r\n```ruby\r\n{}.to_json # Forces your json codec to initialize (in the event that it is lazily loaded). Does this before job threads start.\r\njob_path = ENV[\"JOB_PATH\"] || 'jobs'\r\nrequire_glob(File.join('lib', '**', '*.rb'))\r\nrequire_glob(File.join(job_path, '**', '*.rb'))\r\n```\r\nto the end of the project's __config.ru__ file \r\n\r\n# Events Engines\r\nDashing 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.\r\n\r\n## Engine Selection\r\nDashing is using _eventsengine_ setting as engine instance reference. One can select the engine type during the configuration of the application: \r\n\r\n__config.ru:__\r\n```ruby\r\nconfigure do\r\n  set :auth_token, 'YOUR_AUTH_TOKEN'\r\n  set :eventsengine, EventsEngine.create(EventsEngineTypes::WS)\r\nend\r\n```\r\nThe above selects websocket engine.\r\n\r\nCurrently supported engines are:\r\n* ServerSideEvents - _EventsEngineTypes::SSE_\r\n* WebSockets - _EventsEngineTypes::WS_\r\n\r\n## Add your own engine\r\nTo 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. \r\n\r\n__1. add constant__\r\n```ruby\r\nmodule EventsEngineTypes\r\n\tWEBSOCKET2=\"WS2\" #new web socket implementation\r\nend\r\n```\r\n\r\n__2. route__: \r\n```ruby\r\nget '/events', provides: 'text/event-stream' do\r\n  protected!\r\n  response.headers['X-Accel-Buffering'] = 'no' # Disable buffering for nginx\r\n  stream :keep_open do |out|\r\n  \tsettings.eventsengine.openConnection(out)\r\n  end\r\nend\r\n```\r\n\r\n__3. subclass EventsEngine__:\r\nYou need to subclass EventsEngine class, register your new engine and implement _send_event_ and _stop_ methods\r\n```ruby\r\nclass NewCoolWebSockets < EventsEngine\r\n\tregister_engine EventsEngineTypes::WEBSOCKET2\r\n\tdef stop\r\n\tend\r\n\tdef send_event(body, target=nil)\r\n\tend\r\nend\r\n```\r\n\r\n__4. add engine on the client side__\r\n```coffee\r\n  $(document).ready -> \r\n  \tif Configuration.EventEngine==\"WS2\"\r\n  \t\tDashing.source= -> \r\n  \t\t\t.... create your own engine...\r\n```\r\n> Please note that client side uses the value of the EventsEngineType's constant, not its name\r\n"},"comment":{"url":"https://api.github.com/repos/Shopify/dashing/issues/comments/71153132","html_url":"https://github.com/Shopify/dashing/pull/505#issuecomment-71153132","issue_url":"https://api.github.com/repos/Shopify/dashing/issues/505","id":71153132,"user":{"login":"kneradovsky","id":10231606,"avatar_url":"https://avatars.githubusercontent.com/u/10231606?v=3","gravatar_id":"","url":"https://api.github.com/users/kneradovsky","html_url":"https://github.com/kneradovsky","followers_url":"https://api.github.com/users/kneradovsky/followers","following_url":"https://api.github.com/users/kneradovsky/following{/other_user}","gists_url":"https://api.github.com/users/kneradovsky/gists{/gist_id}","starred_url":"https://api.github.com/users/kneradovsky/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kneradovsky/subscriptions","organizations_url":"https://api.github.com/users/kneradovsky/orgs","repos_url":"https://api.github.com/users/kneradovsky/repos","events_url":"https://api.github.com/users/kneradovsky/events{/privacy}","received_events_url":"https://api.github.com/users/kneradovsky/received_events","type":"User","site_admin":false},"created_at":"2015-01-23T06:30:09Z","updated_at":"2015-01-23T06:30:09Z","body":"@mahoekst : \r\n> Using websockets instead of sse's will that make it work on IE?\r\n\r\nYes, it will work in IE, starting from IE10\r\n\r\n@pushmatrix \r\n> I want to keep the base installation minimalistic.. \r\n\r\nI use dashing in my project and I have to have websockets support in it. It would be very convinient for me to have that websocket support in the gem. Do you mind if I start a new gem based on dashing which will have that additional functionality \r\n"}}