Skip to content
/ weso Public

Ruby Websocket Client with the idea of simplicity and efficiency.

License

Notifications You must be signed in to change notification settings

overchind/weso

Repository files navigation

weso

Ruby WEbSOcket Client.

Installation

Add this line to your application's Gemfile:

gem 'weso'

And then execute:

bundle install

Or install it yourself as:

gem install weso

Usage

You can create an instance of the Weso::Base::Client class and configure required events with a public connect method on the Weso::Base module. Note, that this method creates a new instance every time. The functionality with valid client reconnection now in progress.

client = Weso::Base.connect 'wss://test.com' do |c|
  c.on :open do
    puts("I've opened a new websocket connection!")
  end
  
  c.on :close do
    puts("I'll miss you! Connection is closed now.")
  end
  
  c.on :error do |error|
    puts("I'm sorry, but something went wrong. Lets check the error:")
    puts(error)
  end
end

If you need to configure encryption settings other than defaults, I advise you to review Weso::Base::SocketCreator class. In order to perform useful work with the client, you need to configure the :message event and not be shy to write first with send_data method:

client.on :message do |message|
  puts(message.data)
end

client.send_data("Hello! How you doing?")

In case if you want to check the client connection status - open?, closed? and handshaked? are your best friends. And do not forget to close the connection when you finished your work:

client.close

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/overchind/weso. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.

License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the weso project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.

About

Ruby Websocket Client with the idea of simplicity and efficiency.

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published