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

EventSource vs WebSocket? #26

Open
speedmax opened this issue Aug 7, 2017 · 5 comments
Open

EventSource vs WebSocket? #26

speedmax opened this issue Aug 7, 2017 · 5 comments
Labels

Comments

@speedmax
Copy link

speedmax commented Aug 7, 2017

Hi Godfat,

It's good to see this project still going strong. The event source example looks pretty similar to a lot of the chat example they have with web sockets.

What is your thought on getting streaming response on the web these days? Some web API provides both WS and Rest API these days.

@godfat
Copy link
Owner

godfat commented Aug 8, 2017 via email

@godfat godfat added the help label Aug 8, 2017
@speedmax
Copy link
Author

speedmax commented Sep 25, 2017

This is a example of creating a middleware/wsclient that follows similar interface that adds multiple sockets onto the same HTTP client object. This makes this class a more generalised HTTP/Web client for a specific online provider (Facebook, Twitter)

YourClient = RC::Builder.client do
  use RC::DefaultSite , 'https://api.github.com/users/'
  use RC::JsonResponse, true
  use RC::CommonLogger, method(:puts)

  use RC::WebSocket, "wss://ws.gitter.im/" # default URI (can be specified in instance method)
end

client = YourClient.new

es = client.event_source('users/tom.json', {}, # this is query, none here
                          :headers => {'Accept' => 'text/event-stream'})

# Instance of websocket using default URI
ws = client.websocket

ws.onopen{|s| s.write(subscribe: "tom_uid")}

# Stalker logic to reply to all tom's message
ws.onmessage{|s| s.write(message: "Yo Tom, It's me again") }

# Specify a different path or URI
ws1 = client.websocket("/activities")

ws2 = client.websocket("ws://www.host.com/chat")

Step 1

Early version could use Faye::Websocket as client

lib/rest-core/client/websocket.rb
lib/rest-core/middleware/websocket.rb

Step2

Ideally, the logic that handles EventEmitter and concurrency share the same underlying rest-core libs like promisepool and timer.

Use a generalised Websocket::Driver and without the weight from Faye::Websocket, Extend event_source and create common abstraction Server Side Event (1 way) and Websocket (bidirectional)

  • Remove proxy support
  • Remove Rack/Server support
  • Remove EM specific logic

@godfat
Copy link
Owner

godfat commented Sep 26, 2017

Do you have a working copy so that I could play around it a bit?

I would like to understand the use case a bit more. Would it be something like this?

ws1 = client.websocket("/activities")
ws2 = client.websocket("ws://www.host.com/chat")

ws1.puts "some message"
ws2.puts "some other message"

response1 = ws1.gets
response2 = ws2.gets

@speedmax
Copy link
Author

@godfat No i don't have a working copy yet. I am messing with a lot of web and ws clients to learn more about these recent ruby projects and fundamental building blocks better. (concurrent-ruby, nio4r, websocket-driver).

@khoan and I will be doing dev around these areas, I will ping you when I have some working code.

@godfat
Copy link
Owner

godfat commented Sep 28, 2017

Cool, thanks! Looking forward to it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants