socketry / async-websocket

Asynchronous WebSocket client and server, supporting HTTP/1 and HTTP/2 for Ruby.
MIT License
167 stars 18 forks source link

Allow sending & receiving arbitrary data across socket #10

Closed WA9ACE closed 5 years ago

WA9ACE commented 5 years ago

Solves issue #9

coveralls commented 5 years ago

Pull Request Test Coverage Report for Build 54


Changes Missing Coverage Covered Lines Changed/Added Lines %
lib/async/websocket/connection.rb 1 2 50.0%
<!-- Total: 1 2 50.0% -->
Totals Coverage Status
Change from base Build 53: -0.1%
Covered Lines: 71
Relevant Lines: 78

💛 - Coveralls
ioquatix commented 5 years ago

While I agree with this change, it's going to break all existing use cases. For me "message" is structured data. The default is JSON for websockets, no? So if we want to send/receive raw data maybe we need different method, like read/write

ioquatix commented 5 years ago

Also, need specs.

ioquatix commented 5 years ago

Okay, I rebuilt this library and now you can do it however you want.

The way to do it is to make your own custom "Connection" object which handles everything above the framing layers.

You should do something like:

Async::WebSocket::Server::Rack.open(env, connection_klass: MyConnection) do |connection|
    # connection is an instance of MyConnection

MyConnection should derive from Async::WebSocket::Connection which implements the base functionality.

Does this suit your use case?

ioquatix commented 5 years ago

Please see the update to #9, and feel free to make a PR if you feel there is some way to improve it further.