Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/minoritea/drunkmonkey
https://github.com/minoritea/drunkmonkey
Last synced: 1 day ago
JSON representation
- Host: GitHub
- URL: https://github.com/minoritea/drunkmonkey
- Owner: minoritea
- License: mit
- Created: 2013-10-20T03:59:58.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2013-12-27T04:58:38.000Z (about 11 years ago)
- Last Synced: 2024-12-12T17:19:44.484Z (about 1 month ago)
- Language: JavaScript
- Size: 182 KB
- Stars: 4
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# DrunkMonkey
[![Build Status](https://travis-ci.org/minoritea/drunkmonkey.png?branch=master)](https://travis-ci.org/minoritea/drunkmonkey)
DrunkMonkey is a rack middleware providing realtime two-way http communication with API for [Portal](https://github.com/flowersinthesand/portal/ "Portal").
## Supported servers
You should use servers which supports Rack hijacking API, such as follows:
- Puma## Installation
Add this line to your application's Gemfile:
gem 'drunkmonkey'
And then execute:
$ bundle
Or install it yourself as:
$ gem install drunkmonkey
## Usage
Add DrunkMonkey::Builder to Rack application by **use** method.
Plain Rack:
```ruby
app = Rack::Builder.new do
use DrunkMonkey::Middleware do
on :message do |socket, message|
socket.push "ECHO: #{message}"
end
end
endrun app
```Sinatra:
```ruby
require "sinatra"use DrunkMonkey::Middleware do
on :message do |socket, message|
socket.push "ECHO: #{message}"
end
end
```
Note: the passed block will be executed once when *use* is called at first.Then, include [Portal](https://github.com/flowersinthesand/portal/ "Portal") to HTML and initialize it as follows.
```html
/*
* Following option is a hack to switch protocols automatically
* when the connection cannot be established.
*/
var options = {
transports:["ws","longpollajax"],
reconnect:function(lastDelay,attempts){
if(options.transports.length > 1)
options.transports.shift();
return 2 * (lastDelay || 100);},
prepare:function(connect,disconnect,opts){
opts.transports = options.transports;connect();}
};//Add above options and drunkmonkey's path; default is "/drunkmonkey".
var socket = portal.open("/drunkmonkey",options).on("open",function(){
//Add you event.
socket.send("Hello!");
});```
Note: in current version, supported transports by Drunkmonkey are websocket and long-poll ajax only.
## Contributing
1. Fork it
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 new Pull Request