Tambur.io provides a pain-free websocket experience.
Install this library preferably using bundler:
gem "ruby-tambur", :git => "git://github.com/tamburio/ruby-tambur.git", :branch => "master"
Please register on Tambur.io and create at least one app. This will give you the unique API_KEY, an APP_ID and a SECRET, which you need to initialize the client.
require 'ruby-tambur' tambur = Tambur::Connector.new(API_KEY, APP_ID, SECRET) tambur.publish('mystream', 'some message')
The example above publishes the given message to all subscribed clients. Clients can set different modes for streams they have subscribed. Currently the Tambur.io supports a 'auth', 'presence', and 'direct' mode. But you must grant permission by issueing a specific mode token. For generating such tokens you typically need the StreamName, the SubscriberId, and for direct- and presence-modes the UserId. The SubscriberId is the only parameter your clients must send you e.g. through some AJAX request which you can answer with the generated mode token.
If you issue an auth mode token, the client can authenticate himself for a particular stream. If you use the
auth: stream prefix you can control how we deliver your message.
tambur.publish('auth:mystream', 'some auth message')
The example above publishes the given message to all subscribed clients that have the auth mode enabled.
Issuing an auth mode token is straight forward:
If you issue a presence mode token, the client can switch on and off presence mode. If presence mode is switched on the client will receive join- and leave-events of all the other presence clients in that particular stream. Issuing a presence mode token needs an extra 'User-Id' parameter, which enables you to connect a tambur.io subscriber-id to a User-Id used in your application:
tambur.generate_presence_token('mystream', 'Alice', subscriber_id)
If you issue a direct mode token, the client can switch on and off direct mode. If direct mode is switched on the client can send and receive messages from other clients in that particular stream. Issuing a direct mode token needs an extra 'User-Id' parameter, which enables you to connect a tambur.io subscriber-id to a User-Id used in your application:
tambur.generate_direct_token('mystream', 'Alice', subscriber_id)
If you want to further limit your receivers to one specific subscriber you can do this using the 'private' stream.
tambur.publish('private:' + subscriber_id, 'some private message')
Copyright (c) <2012> <Tambur.io>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.