faye-websocket 0.9.2 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of faye-websocket might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e55b90e0392792e40296464c5bfb0419042dac2a
4
- data.tar.gz: 6d7a46c812d1c98cf23b5fe4f5b7c82149ae2144
3
+ metadata.gz: be0df4257b3a1f898577eb787b6f1fc8f5c0fae4
4
+ data.tar.gz: 75def6662b64d516ee753ccd78003a445c9dca11
5
5
  SHA512:
6
- metadata.gz: 807a1837ccc7d7817f611c21aeeb05d7d8e64795e10b83aaf6bb93145044e956626b27feeef228dca7ea21b7930c544caf11f6d37f95d5b6c463d3d300b6e2b4
7
- data.tar.gz: eefb00619befa06948f8d2752b6c670d16ed2ae1da71809780b7c3b0400b799118fd241758afd9c6565b8916a8b17af3f222afd3480e2c185776b7de1779beca
6
+ metadata.gz: 9054661c65b66682fea05e779d785b142f7005f323228ffdbd3429570ba4df9055b2c7b6516a6c7f046c929387133574ffa39a142121b1871bdcfe99e52ff828
7
+ data.tar.gz: 7eb1cb4a544824ffa191270c665ed70c87d5a131e54f597f090d71a23802691bdce18e9cc46f62c39d3283e031af42c27bec6bae552519c2c7e4a4630fde64cf
@@ -1,76 +1,66 @@
1
+ ### 0.10.0 / 2015-07-08
2
+
3
+ * Add the standard `code` and `reason` parameters to the `close` method
4
+
1
5
  ### 0.9.2 / 2014-12-21
2
6
 
3
7
  * Only emit `error` once, and don't emit it after `close`
4
8
 
5
-
6
9
  ### 0.9.1 / 2014-12-18
7
10
 
8
11
  * Check that all options to the WebSocket constructor are recognized
9
12
 
10
-
11
13
  ### 0.9.0 / 2014-12-13
12
14
 
13
15
  * Allow protocol extensions to be passed into websocket-extensions
14
16
 
15
-
16
17
  ### 0.8.0 / 2014-11-08
17
18
 
18
19
  * Support connections via HTTP proxies
19
20
 
20
-
21
21
  ### 0.7.5 / 2014-10-04
22
22
 
23
23
  * Allow sockets to be closed when they are in any state other than `CLOSED`
24
24
 
25
-
26
25
  ### 0.7.4 / 2014-07-06
27
26
 
28
27
  * Stop using `define_method` to implement `Event` properties, since it blows the method cache
29
28
  * Stop setup errors masking URI errors in `Client#initialize`
30
29
  * Make the Goliath adapter compatible with goliath-1.0.4.
31
30
 
32
-
33
31
  ### 0.7.3 / 2014-04-24
34
32
 
35
33
  * Remove an unneeded method override in the `WebSocket` class
36
34
 
37
-
38
35
  ### 0.7.2 / 2013-12-29
39
36
 
40
37
  * Fix WebSocket detection in cases where the web server does not produce an `env`
41
38
 
42
-
43
39
  ### 0.7.1 / 2013-12-03
44
40
 
45
41
  * Support the `max_length` websocket-driver option
46
42
  * Expose a `message` property on `error` events
47
43
 
48
-
49
44
  ### 0.7.0 / 2013-09-09
50
45
 
51
46
  * Allow the server to send custom headers with EventSource responses
52
47
 
53
-
54
48
  ### 0.6.3 / 2013-08-04
55
49
 
56
50
  * Stop implicitly depending on Rack 1.4
57
51
 
58
-
59
52
  ### 0.6.2 / 2013-07-05
60
53
 
61
54
  * Catch errors thrown by EventMachine and emit `error` and `close` events
62
55
 
63
-
64
56
  ### 0.6.1 / 2013-05-12
65
57
 
66
58
  * Release a gem without log and pid files in it
67
59
 
68
-
69
60
  ### 0.6.0 / 2013-05-12
70
61
 
71
62
  * Add support for custom headers
72
63
 
73
-
74
64
  ### 0.5.0 / 2013-05-05
75
65
 
76
66
  * Extract the protocol handlers into the `websocket-driver` library
@@ -78,58 +68,48 @@
78
68
  * Add support for Rainbows 4.5 and Puma
79
69
  * Officially support JRuby and Rubinius
80
70
 
81
-
82
71
  ### 0.4.7 / 2013-02-14
83
72
 
84
73
  * Emit the `close` event if TCP is closed before CLOSE frame is acked
85
74
  * Treat the `Upgrade: websocket` header case-insensitively because of IE10
86
75
  * Do not suppress headers in the Thin and Rainbows adapters unless the status is `101`
87
76
 
88
-
89
77
  ### 0.4.6 / 2012-07-09
90
78
 
91
79
  * Add `Connection: close` to EventSource response
92
80
 
93
-
94
81
  ### 0.4.5 / 2012-04-06
95
82
 
96
83
  * Add WebSocket error code `1011`.
97
84
  * Handle URLs with no path correctly by sending `GET /`
98
85
 
99
-
100
86
  ### 0.4.4 / 2012-03-16
101
87
 
102
88
  * Fix installation on JRuby with a platform-specific gem
103
89
 
104
-
105
90
  ### 0.4.3 / 2012-03-12
106
91
 
107
92
  * Make `extconf.rb` a no-op on JRuby
108
93
 
109
-
110
94
  ### 0.4.2 / 2012-03-09
111
95
 
112
96
  * Port masking-function C extension to Java for JRuby
113
97
 
114
-
115
98
  ### 0.4.1 / 2012-02-26
116
99
 
117
100
  * Treat anything other than an `Array` as a string when calling `send()`
118
101
  * Fix error loading UTF-8 validation code on Ruby 1.9 with `-Ku` flag
119
102
 
120
-
121
103
  ### 0.4.0 / 2012-02-13
122
104
 
123
105
  * Add `ping()` method to server-side `WebSocket` and `EventSource`
124
106
  * Buffer `send()` calls until the draft-76 handshake is complete
125
107
 
126
-
127
108
  ### 0.3.0 / 2012-01-13
128
109
 
129
110
  * Add support for `EventSource` connections
130
111
  * Support the Thin, Rainbows and Goliath web servers
131
112
 
132
-
133
113
  ### 0.2.0 / 2011-12-21
134
114
 
135
115
  * Add support for `Sec-WebSocket-Protocol` negotiation
@@ -137,17 +117,14 @@
137
117
  * Improve performance of HyBi parsing/framing functions
138
118
  * Write masking function in C
139
119
 
140
-
141
120
  ### 0.1.2 / 2011-12-05
142
121
 
143
122
  * Make `hixie-76` sockets work through HAProxy
144
123
 
145
-
146
124
  ### 0.1.1 / 2011-11-30
147
125
 
148
126
  * Fix `add_event_listener()` interface methods
149
127
 
150
-
151
128
  ### 0.1.0 / 2011-11-27
152
129
 
153
130
  * Initial release, based on WebSocket components from Faye
data/README.md CHANGED
@@ -6,12 +6,11 @@
6
6
  [client](http://faye.jcoglan.com/autobahn/clients/)
7
7
 
8
8
  This is a general-purpose WebSocket implementation extracted from the
9
- [Faye](http://faye.jcoglan.com) project. It provides classes for easily
10
- building WebSocket servers and clients in Ruby. It does not provide a server
11
- itself, but rather makes it easy to handle WebSocket connections within an
12
- existing [Rack](http://rack.github.io/) application. It does not provide
13
- any abstraction other than the standard [WebSocket
14
- API](http://dev.w3.org/html5/websockets/).
9
+ [Faye](http://faye.jcoglan.com) project. It provides classes for easily building
10
+ WebSocket servers and clients in Ruby. It does not provide a server itself, but
11
+ rather makes it easy to handle WebSocket connections within an existing
12
+ [Rack](http://rack.github.io/) application. It does not provide any abstraction
13
+ other than the standard [WebSocket API](http://dev.w3.org/html5/websockets/).
15
14
 
16
15
  It also provides an abstraction for handling
17
16
  [EventSource](http://dev.w3.org/html5/eventsource/) connections, which are
@@ -38,10 +37,10 @@ $ gem install faye-websocket
38
37
 
39
38
  ## Handling WebSocket connections in Rack
40
39
 
41
- You can handle WebSockets on the server side by listening for requests using
42
- the `Faye::WebSocket.websocket?` method, and creating a new socket for the
43
- request. This socket object exposes the usual WebSocket methods for receiving
44
- and sending messages. For example this is how you'd implement an echo server:
40
+ You can handle WebSockets on the server side by listening for requests using the
41
+ `Faye::WebSocket.websocket?` method, and creating a new socket for the request.
42
+ This socket object exposes the usual WebSocket methods for receiving and sending
43
+ messages. For example this is how you'd implement an echo server:
45
44
 
46
45
  ```ruby
47
46
  # app.rb
@@ -82,8 +81,8 @@ If you need to detect when the WebSocket handshake is complete, you can use the
82
81
 
83
82
  If the connection's protocol version supports it, you can call `ws.ping()` to
84
83
  send a ping message and wait for the client's response. This method takes a
85
- message string, and an optional callback that fires when a matching pong
86
- message is received. It returns `true` iff a ping message was sent. If the
84
+ message string, and an optional callback that fires when a matching pong message
85
+ is received. It returns `true` if and only if a ping message was sent. If the
87
86
  client does not support ping/pong, this method sends no data and returns
88
87
  `false`.
89
88
 
@@ -130,7 +129,7 @@ To connect via a proxy, set the `proxy` option to the HTTP origin of the proxy,
130
129
  including any authorization information and custom headers you require:
131
130
 
132
131
  ```rb
133
- ws = Faye::WebSocket::Client.new('ws://www.example.com/', nil, {
132
+ ws = Faye::WebSocket::Client.new('ws://www.example.com/', [], {
134
133
  :proxy => {
135
134
  :origin => 'http://username:password@proxy.example.com',
136
135
  :headers => {'User-Agent' => 'ruby'}
@@ -173,7 +172,7 @@ array of extensions to the `:extensions` option. For example, to add
173
172
  ```rb
174
173
  require 'permessage_deflate'
175
174
 
176
- ws = Faye::WebSocket.new(env, nil, :extensions => [PermessageDeflate])
175
+ ws = Faye::WebSocket.new(env, [], :extensions => [PermessageDeflate])
177
176
  ```
178
177
 
179
178
 
@@ -193,8 +192,8 @@ is an optional hash containing any of these keys:
193
192
  * `:extensions` - an array of
194
193
  [websocket-extensions](https://github.com/faye/websocket-extensions-ruby)
195
194
  compatible extensions, as described above
196
- * `:headers` - a hash containing key-value pairs representing HTTP headers to
197
- be sent during the handshake process
195
+ * `:headers` - a hash containing key-value pairs representing HTTP headers to be
196
+ sent during the handshake process
198
197
  * `:max_length` - the maximum allowed size of incoming message frames, in bytes.
199
198
  The default value is `2^26 - 1`, or 1 byte short of 64 MiB.
200
199
  * `:ping` - an integer that sets how often the WebSocket should send ping
@@ -215,18 +214,19 @@ Both the server- and client-side `WebSocket` objects support the following API:
215
214
  not need to implement error recovery.
216
215
  * <b>`on(:close) { |event| }`</b> fires when either the client or the server
217
216
  closes the connection. Event has two optional attributes, <b>`code`</b> and
218
- <b>`reason`</b>, that expose the status code and message sent by the peer
219
- that closed the connection.
217
+ <b>`reason`</b>, that expose the status code and message sent by the peer that
218
+ closed the connection.
220
219
  * <b>`send(message)`</b> accepts either a `String` or an `Array` of byte-sized
221
220
  integers and sends a text or binary message over the connection to the other
222
221
  peer; binary data must be encoded as an `Array`.
223
- * <b>`ping(message = '', &callback)`</b> sends a ping frame with an optional
224
- message and fires the callback when a matching pong is received.
225
- * <b>`close`</b> closes the connection.
222
+ * <b>`ping(message, &callback)`</b> sends a ping frame with an optional message
223
+ and fires the callback when a matching pong is received.
224
+ * <b>`close(code, reason)`</b> closes the connection, sending the given status
225
+ code and reason text, both of which are optional.
226
226
  * <b>`version`</b> is a string containing the version of the `WebSocket`
227
227
  protocol the connection is using.
228
- * <b>`protocol`</b> is a string (which may be empty) identifying the
229
- subprotocol the socket is using.
228
+ * <b>`protocol`</b> is a string (which may be empty) identifying the subprotocol
229
+ the socket is using.
230
230
 
231
231
 
232
232
  ## Handling EventSource connections in Rack
@@ -263,9 +263,9 @@ App = lambda do |env|
263
263
  end
264
264
  ```
265
265
 
266
- The `send` method takes two optional parameters, `:event` and `:id`. The
267
- default event-type is `'message'` with no ID. For example, to send a
268
- `notification` event with ID `99`:
266
+ The `send` method takes two optional parameters, `:event` and `:id`. The default
267
+ event-type is `'message'` with no ID. For example, to send a `notification`
268
+ event with ID `99`:
269
269
 
270
270
  ```ruby
271
271
  es.send('Breaking News!', :event => 'notification', :id => '99')
@@ -302,8 +302,8 @@ es = Faye::EventSource.new(es,
302
302
  ```
303
303
 
304
304
  You can send a ping message at any time by calling `es.ping`. Unlike WebSocket
305
- the client does not send a response to this; it is merely to send some data
306
- over the wire to keep the connection alive.
305
+ the client does not send a response to this; it is merely to send some data over
306
+ the wire to keep the connection alive.
307
307
 
308
308
 
309
309
  ## Running your socket application
@@ -321,8 +321,8 @@ loading `faye/websocket`:
321
321
  Faye::WebSocket.load_adapter('thin')
322
322
  ```
323
323
 
324
- Thin can be started via the command line if you've set up a `config.ru` file
325
- for your application:
324
+ Thin can be started via the command line if you've set up a `config.ru` file for
325
+ your application:
326
326
 
327
327
  ```
328
328
  $ thin start -R config.ru -p 9292
@@ -362,9 +362,20 @@ end
362
362
  ### Running the app with Passenger
363
363
 
364
364
  faye-websocket requires either Passenger for Nginx or Passenger Standalone.
365
- Apache doesn't work well with WebSockets at this time. You do not need any
366
- special configuration to make faye-websocket work, it should work out of the
367
- box on Passenger provided you use at least Passenger 4.0.
365
+ [Apache doesn't work well with WebSockets at this time](https://github.com/phusion/passenger/issues/1202).
366
+ You do not need any special configuration to make faye-websocket work, it
367
+ should work out of the box on Passenger provided you use at least Passenger
368
+ 4.0.
369
+
370
+ However, you do need to insert the following code in `config.ru` for optimal
371
+ WebSocket performance in Passenger. This is
372
+ [documented in the Passenger manual](https://www.phusionpassenger.com/documentation/Users%20guide%20Nginx.html#tuning_sse_websockets).
373
+
374
+ ```ruby
375
+ if defined?(PhusionPasseneger)
376
+ PhusionPassenger.advertised_concurrency_level = 0
377
+ end
378
+ ```
368
379
 
369
380
  Run your app on Passenger for Nginx by creating a virtual host entry which
370
381
  points to your app's "public" directory:
@@ -479,22 +490,21 @@ end
479
490
 
480
491
  (The MIT License)
481
492
 
482
- Copyright (c) 2010-2014 James Coglan
493
+ Copyright (c) 2010-2015 James Coglan
483
494
 
484
495
  Permission is hereby granted, free of charge, to any person obtaining a copy of
485
496
  this software and associated documentation files (the 'Software'), to deal in
486
497
  the Software without restriction, including without limitation the rights to
487
- use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
488
- of the Software, and to permit persons to whom the Software is furnished to do
489
- so, subject to the following conditions:
498
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
499
+ the Software, and to permit persons to whom the Software is furnished to do so,
500
+ subject to the following conditions:
490
501
 
491
502
  The above copyright notice and this permission notice shall be included in all
492
503
  copies or substantial portions of the Software.
493
504
 
494
505
  THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
495
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
496
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
497
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
498
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
499
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
500
- SOFTWARE.
506
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
507
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
508
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
509
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
510
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -30,7 +30,7 @@ EM.run {
30
30
  end
31
31
 
32
32
  url = "#{host}/runCase?case=#{n}&agent=#{agent}"
33
- socket = Faye::WebSocket::Client.new(url, nil, options)
33
+ socket = Faye::WebSocket::Client.new(url, [], options)
34
34
 
35
35
  socket.onmessage = lambda do |event|
36
36
  socket.send(event.data)
@@ -2,12 +2,17 @@ require 'rubygems'
2
2
  require 'bundler/setup'
3
3
  require 'faye/websocket'
4
4
  require 'eventmachine'
5
+ require 'permessage_deflate'
5
6
 
6
7
  EM.run {
7
- url = ARGV[0]
8
- headers = {'Origin' => 'http://faye.jcoglan.com'}
9
- proxy = {:origin => ARGV[1], :headers => {'User-Agent' => 'Echo'}}
10
- ws = Faye::WebSocket::Client.new(url, nil, :headers => headers, :proxy => proxy)
8
+ url = ARGV[0]
9
+ proxy = ARGV[1]
10
+
11
+ ws = Faye::WebSocket::Client.new(url, [],
12
+ :proxy => {:origin => proxy, :headers => {'User-Agent' => 'Echo'}},
13
+ :headers => {'Origin' => 'http://faye.jcoglan.com'},
14
+ :extensions => [PermessageDeflate]
15
+ )
11
16
 
12
17
  ws.onopen = lambda do |event|
13
18
  p [:open, ws.headers]
@@ -69,9 +69,18 @@ module Faye
69
69
  @driver.ping(message, &callback)
70
70
  end
71
71
 
72
- def close
72
+ def close(code = nil, reason = nil)
73
+ code ||= 1000
74
+ reason ||= ''
75
+
76
+ unless code == 1000 or (code >= 3000 and code <= 4999)
77
+ raise ArgumentError, "Failed to execute 'close' on WebSocket: " +
78
+ "The code must be either 1000, or between 3000 and 4999. " +
79
+ "#{code} is neither."
80
+ end
81
+
73
82
  @ready_state = CLOSING unless @ready_state == CLOSED
74
- @driver.close
83
+ @driver.close(reason, code)
75
84
  end
76
85
 
77
86
  def protocol
@@ -106,13 +115,13 @@ module Faye
106
115
  def begin_close(reason, code)
107
116
  return if @ready_state == CLOSED
108
117
  @ready_state = CLOSING
118
+ @close_params = [reason, code]
109
119
 
110
120
  if @stream
111
121
  @stream.close_connection_after_writing
112
122
  else
113
123
  finalize_close
114
124
  end
115
- @close_params = [reason, code]
116
125
  end
117
126
 
118
127
  def finalize_close
@@ -7,7 +7,7 @@ module Faye::WebSocket::API
7
7
  events.each do |event_type|
8
8
  define_method "on#{event_type}=" do |handler|
9
9
  EventMachine.next_tick do
10
- flush(event_type, &handler)
10
+ flush(event_type, handler)
11
11
  instance_variable_set("@on#{event_type}", handler)
12
12
  end
13
13
  end
@@ -17,9 +17,10 @@ module Faye::WebSocket::API
17
17
  add_listener(event_type, &listener)
18
18
  end
19
19
 
20
- def add_listener(event_type, &listener)
20
+ def add_listener(event_type, callable = nil, &block)
21
+ listener = callable || block
21
22
  EventMachine.next_tick do
22
- flush(event_type, &listener)
23
+ flush(event_type, listener)
23
24
  super(event_type, &listener)
24
25
  end
25
26
  end
@@ -32,23 +33,23 @@ module Faye::WebSocket::API
32
33
  event.target = event.current_target = self
33
34
  event.event_phase = Event::AT_TARGET
34
35
 
35
- callback = instance_variable_get("@on#{ event.type }")
36
+ listener = instance_variable_get("@on#{ event.type }")
36
37
  count = listener_count(event.type)
37
38
 
38
- unless callback or count > 0
39
+ unless listener or count > 0
39
40
  @buffers ||= Hash.new { |k,v| k[v] = [] }
40
41
  @buffers[event.type].push(event)
41
42
  end
42
43
 
43
- callback.call(event) if callback
44
+ listener.call(event) if listener
44
45
  emit(event.type, event)
45
46
  end
46
47
 
47
48
  private
48
49
 
49
- def flush(event_type, &callback)
50
+ def flush(event_type, listener)
50
51
  if buffer = @buffers && @buffers.delete(event_type.to_s)
51
- buffer.each { |event| callback.call(event) }
52
+ buffer.each { |event| listener.call(event) }
52
53
  end
53
54
  end
54
55
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: faye-websocket
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.2
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Coglan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-21 00:00:00.000000000 Z
11
+ date: 2015-07-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: eventmachine
@@ -233,7 +233,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
233
233
  version: '0'
234
234
  requirements: []
235
235
  rubyforge_project:
236
- rubygems_version: 2.2.2
236
+ rubygems_version: 2.4.5
237
237
  signing_key:
238
238
  specification_version: 4
239
239
  summary: Standards-compliant WebSocket server and client