padrino-websockets 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 48a6c2dbc40407de9d89363244273ea101a333b9
4
- data.tar.gz: f55b458cb97d4931a9bb9178827961e5a3a24819
3
+ metadata.gz: 0fcb9330007638099edcb3fe7c5f86ae8147d1fe
4
+ data.tar.gz: e0f9a5887325488f3266cc1939803f9d80a80c61
5
5
  SHA512:
6
- metadata.gz: de5f1cc610fb4b047ca7beea1b5d735fab5eb5fb298085efb96578c45eed5fa7b4673ebf1b8fbb36be3b57b0b310a677960042e32c696d3877cd267c213d1def
7
- data.tar.gz: b1f972357d3054ebe90b4fa5c727acc90a16d8b59e40ed0500e83591a81e391e6a0f2def90f02279a8ecb15fe3d2ff43c43d77e3c1df35045f62ec7441af6e1e
6
+ metadata.gz: f0ffe8ae0cf071bbbea799d02643fcf8a13af81e5e9ff24a394c1fe0c6c7aaaedc46d2c7bff5a3957fec61e6088f04822d436ce4298ff87c87da5d98afe1fcf8
7
+ data.tar.gz: fba963a1fb0357ad92ee0a08939c8e83badc1a5f1aa1cb465b9ffd220d7b70ed9816f58a84bb8ccb5e54032ab0f0eb2bc28b0832955b5dd7e185d68a355df025
data/README.md CHANGED
@@ -1,30 +1,31 @@
1
1
  # Padrino Websockets
2
2
 
3
3
  A WebSockets abstraction for the Padrino Ruby Web Framework to manage
4
- channels, users and events regardless of the underlying WebSockets implementation.
4
+ channels, users and events regardless of the underlying WebSockets implementation.
5
5
 
6
6
  ## Current support
7
7
 
8
8
  * [SpiderGazelle](https://github.com/cotag/spider-gazelle) a LibUV application server.
9
9
  * [Puma](http://puma.io/) >= 2.0. (*)
10
- * [Thin](http://code.macournoyer.com/thin/) (*)
11
- * [Rainbows](http://rainbows.rubyforge.org/) (*) (**)
12
- * [Goliath](http://postrank-labs.github.com/goliath/) (*) (**)
13
- * [Phusion Passenger](https://www.phusionpassenger.com/) >= 4.0 with nginx >= 1.4 (*) (**)
10
+ * [Thin](http://code.macournoyer.com/thin/) (*)
11
+ * [Rainbows](http://rainbows.rubyforge.org/) (\*) (**)
12
+ * [Goliath](http://postrank-labs.github.com/goliath/) (\*) (**)
13
+ * [Phusion Passenger](https://www.phusionpassenger.com/) >= 4.0 with nginx >= 1.4 (\*) (**)
14
14
 
15
15
  (*) Supported through [faye-websocket-ruby](https://github.com/faye/faye-websocket-ruby).
16
+
16
17
  (**) Untested.
17
18
 
18
19
 
19
- UPDATE: See the [faye-support](https://github.com/dariocravero/padrino-websockets/tree/faye-support) branch for Thin support (more updats coming on this).
20
-
21
-
22
20
  ## Installation
23
21
 
24
22
  Add this line to your application's `Gemfile`:
25
23
 
26
24
  ```
27
25
  gem 'padrino-websockets'
26
+
27
+ # Uncomment the following line if you're using a Faye backend
28
+ # gem 'faye-websocket'
28
29
  ```
29
30
 
30
31
  And then execute:
@@ -52,7 +53,8 @@ Then in any controller or in the app itself, define a WebSocket channel:
52
53
  ```
53
54
  websocket :channel do
54
55
  on :ping do |message|
55
- send_message({pong: true, data: message})
56
+ send_message(:ping, session['websocket_user'], {pong: true, data: message})
57
+ broadcast(:ping, {pong: true, data: message, broadcast: true})
56
58
  end
57
59
  end
58
60
  ```
@@ -4,16 +4,19 @@ source 'https://rubygems.org'
4
4
  # gemspec
5
5
 
6
6
  # Server requirements
7
- # gem 'thin' # or mongrel
8
- # gem 'trinidad', :platform => 'jruby'
9
- gem 'spider-gazelle', github: 'cotag/spider-gazelle'
7
+ # For Puma
8
+ gem 'faye-websocket'
9
+ gem 'puma'
10
+
11
+ # For SpiderGazelle
12
+ # gem 'spider-gazelle', github: 'cotag/spider-gazelle'
13
+ # gem 'uv-rays', github: 'cotag/uv-rays'
10
14
 
11
15
  # Optional JSON codec (faster performance)
12
16
  gem 'oj'
13
17
 
14
18
  # Project requirements
15
19
  gem 'rake'
16
- gem 'uv-rays', github: 'cotag/uv-rays'
17
20
  gem 'padrino-websockets', path: '../..'
18
21
  # gem 'padrino-websockets', github: 'dariocravero/padrino-websockets'
19
22
 
@@ -10,9 +10,10 @@ module PadrinoWebsocketsDemo
10
10
  end
11
11
 
12
12
  websocket :channel do
13
- event :test do |context, message|
13
+ on :test do |message|
14
14
  "test on channel"
15
- send_message message
15
+ send_message :channel, session['websocket_user'], message
16
+ broadcast :channel, message.merge({'broadcast' => true})
16
17
  end
17
18
  end
18
19
  end
@@ -124,7 +124,7 @@ module Padrino
124
124
  #
125
125
  def on_shutdown
126
126
  logger.debug "Disconnecting user: #{@user} from channel: #{@channel}."
127
- @@connections[@channel].delete(@ws)
127
+ @@connections[@channel].delete(@user)
128
128
  end
129
129
 
130
130
  class << self
@@ -21,6 +21,7 @@ module Padrino
21
21
  #
22
22
  def on_shutdown(event)
23
23
  @pinger.cancel if @pinger
24
+ super
24
25
  end
25
26
 
26
27
  ##
@@ -17,7 +17,8 @@ module Padrino
17
17
 
18
18
  set_websocket_user
19
19
  ws = ::Faye::WebSocket.new(env, nil, {ping: 15})
20
- Padrino::WebSockets::Faye::EventManager.new(channel, session['websocket_user'],
20
+ Padrino::WebSockets::Faye::EventManager.new(params[:channel] || channel,
21
+ session['websocket_user'],
21
22
  ws, self, &block)
22
23
  ws.rack_response
23
24
  end
@@ -16,6 +16,7 @@ module Padrino
16
16
  throw :pass unless request.env['rack.hijack']
17
17
 
18
18
  event_context = self
19
+ ws_channel = params[:channel] || channel
19
20
 
20
21
  # It's a WebSocket. Get the libuv promise and manage its events
21
22
  request.env['rack.hijack'].call.then do |hijacked|
@@ -24,7 +25,7 @@ module Padrino
24
25
  set_websocket_user
25
26
 
26
27
  Padrino::WebSockets::SpiderGazelle::EventManager.new(
27
- channel, session['websocket_user'], ws, event_context, &block)
28
+ ws_channel, session['websocket_user'], ws, event_context, &block)
28
29
  ws.start
29
30
  end
30
31
  end
@@ -1,5 +1,5 @@
1
1
  module Padrino
2
2
  module Websockets
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: padrino-websockets
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Darío Javier Cravero
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-05 00:00:00.000000000 Z
11
+ date: 2015-04-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -95,9 +95,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
95
95
  version: '0'
96
96
  requirements: []
97
97
  rubyforge_project:
98
- rubygems_version: 2.2.0
98
+ rubygems_version: 2.4.5
99
99
  signing_key:
100
100
  specification_version: 4
101
101
  summary: A WebSockets abstraction for Padrino
102
102
  test_files: []
103
- has_rdoc: