Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a ruby web server #3

Open
orta opened this issue Aug 9, 2016 · 0 comments
Open

Create a ruby web server #3

orta opened this issue Aug 9, 2016 · 0 comments

Comments

@orta
Copy link
Owner

orta commented Aug 9, 2016

The web socket connection needs to connect from both sides, so from the ruby side you'll need something that can pass message around.

The types of messages I expect it to send to the native client:

  • Starting a compilation of files x, y, z
  • New NSBundle for tests available in the app's sandbox
  • Server is shutting down

The types of messages I expect to receive from the client

  • This is my current working directory
  • Test run has started
  • Test run has passed/failed metadata
  • I'm closing down

When building out my proof of concept, this is the code I used to set up my socket.

require 'faye/websocket'
Faye::WebSocket.load_adapter('thin')

App = lambda do |env|
  if Faye::WebSocket.websocket?(env)
    ws = Faye::WebSocket.new(env)

    ws.on :message do |event|
      ws.send(event.data)
    end

    ws.on :close do |event|
      p [:close, event.code, event.reason]
      ws = nil
    end

    # Return async Rack response
    ws.rack_response

  else
    # Normal HTTP request
    [200, {'Content-Type' => 'text/plain'}, ['Hello']]
  end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant