New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

eventflit-client

Package Overview
Dependencies
Maintainers
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eventflit-client

  • 0.1.0
  • Rubygems
  • Socket score

Version published
Maintainers
2
Created
Source

eventflit-client: Ruby WebSocket client for Eventflit Channels

eventflit-client is a Ruby gem for consuming WebSockets from Eventflit service.

Installation

gem install eventflit-client

This gem is compatible with jruby

Single-Threaded Usage

The application will pause at eventflit.connect and handle events from Eventflit Channels as they happen.

require 'eventflit-client'
cluster = 'cus1'  # take this from your app's config in the dashboard
eventflit = EventflitClient::Socket.new(YOUR_APPLICATION_KEY, {
  secure: true,
  ws_host: "ws-#{cluster}.eventflit.com"
})

# Subscribe to two channels
eventflit.subscribe('channel1')
eventflit.subscribe('channel2')

# Subscribe to presence channel
eventflit.subscribe('presence-channel3', USER_ID)

# Subscribe to private channel
eventflit.subscribe('private-channel4', USER_ID)

# Subscribe to presence channel with custom data (user_id is mandatory)
eventflit.subscribe('presence-channel5', :user_id => USER_ID, :user_name => 'john')

# Bind to a global event (can occur on either channel1 or channel2)
eventflit.bind('globalevent') do |data|
  puts data
end

# Bind to a channel event (can only occur on channel1)
eventflit['channel1'].bind('channelevent') do |data|
  puts data
end

eventflit.connect

Asynchronous Usage

With eventflit.connect(true), the connection to Eventflit Channels will be maintained in its own thread. The connection will remain open in the background as long as your main application thread is running, and you can continue to subscribe/unsubscribe to channels and bind new events.

require 'eventflit-client'
eventflit = EventflitClient::Socket.new(YOUR_APPLICATION_KEY)
eventflit.connect(true) # Connect asynchronously

# Subscribe to two channels
eventflit.subscribe('channel1')
eventflit.subscribe('channel2')

# Bind to a global event (can occur on either channel1 or channel2)
eventflit.bind('globalevent') do |data|
  puts data
end

# Bind to a channel event (can only occur on channel1)
eventflit['channel1'].bind('channelevent') do |data|
  puts data
end

loop do
  sleep(1) # Keep your main thread running
end

Using native WebSocket implementation

This gem depends on the websocket gem which is a pure Ruby implementation of websockets.

However it can optionally use a native C or Java implementation for a 25% speed increase by including the websocket-native gem in your Gemfile.

See LICENSE.txt.

FAQs

Package last updated on 04 May 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc