Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

sock-drawer

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sock-drawer

  • 0.1.1
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

Sock::Drawer

This gem allows message async message calls to subscribed listeners. Messages can be fired between ruby objects or to websocket connections.

Circle CI Code Climate Test Coverage

Installation

Add this line to your application's Gemfile:

gem 'sock-drawer'

And then execute:

$ bundle

Or install it yourself as:

$ gem install sock-drawer

Usage

Initialize a instance of the sock-drawer client

sock = Sock::Client.new(logger: Rails.logger, redis: redis)

Publishing

Publish an event on a channel,

sock.pub("my message", channel: "my-channel")

or publish to all channels,

sock.pub("my message")

Receiving in Javascript

To capture the event in Javascript use something like,

var webSocket = new WebSocket("ws://" + location.hostname + ":8081/" + "my-channel");

webSocket.onmessage = function(event) {
  console.log(event.data);
}

Subscribing

Create a class to handle redis events like,

class MyListener
  include Sock::Subscriber

  on 'echo' do |msg|
    msg
  end
end

Then register your listener with the server

Sock::Server.new(listener: MyListener)

Whenever an event is fired on the sock-hook/echo channel the block will be executed.

Configuration

you can configure your sock server to run as a rake task like,

namespace :sock do
  desc 'start the sock-drawer server to manage socket connections'
  task :server do
    Sock::Server.new.start!
  end
end

Then run it with rake sock:server Current supported configuration options:

keyword argdefault
name'sock-hook'
loggerLogger.new(STDOUT)
socket_params{ host: '0.0.0.0', port: 8020 }
mode'default'
listenerN/A

Wish List

  • Right now all configuration is passed into new, it would be nice to read from a config file
  • There isn't a way of having multiple event handlers. Should be easy to pass multiple in or intelligently find them (given some convention)

And you are good to go!

Contributing

  1. Fork it ( https://github.com/[my-github-username]/sock-drawer/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Running the tests

if you are going to contribute, I hope you run the tests at least once -- hopefully many times. to run the tests, you must have redis-server running in the background with default configuration.

FAQs

Package last updated on 15 Nov 2015

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