faye-websocket 0.9.1 → 0.9.2

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: 533cb535f3f41818edec87a9b712fd0c2ba24765
4
- data.tar.gz: ce5b4afbd01902a09b3cd18329d0d8cd430cec71
3
+ metadata.gz: e55b90e0392792e40296464c5bfb0419042dac2a
4
+ data.tar.gz: 6d7a46c812d1c98cf23b5fe4f5b7c82149ae2144
5
5
  SHA512:
6
- metadata.gz: 7171c36500ce120c2c629ba343f61d7a76b71e83a6306c7f3c16c0f92916344f28ff7b7aa61d8cf9f1bddec8d7ba2f5c16f1ae33d09103af9bc4afef8d4e0445
7
- data.tar.gz: 897610520dbabadc000077d7b585de835ace6e7222cca7a7c207861d7533b221fd492d24e8a726c289a60776d0e64bc57cb9e77d88ef07219d4b592f8b032c53
6
+ metadata.gz: 807a1837ccc7d7817f611c21aeeb05d7d8e64795e10b83aaf6bb93145044e956626b27feeef228dca7ea21b7930c544caf11f6d37f95d5b6c463d3d300b6e2b4
7
+ data.tar.gz: eefb00619befa06948f8d2752b6c670d16ed2ae1da71809780b7c3b0400b799118fd241758afd9c6565b8916a8b17af3f222afd3480e2c185776b7de1779beca
@@ -1,3 +1,8 @@
1
+ ### 0.9.2 / 2014-12-21
2
+
3
+ * Only emit `error` once, and don't emit it after `close`
4
+
5
+
1
6
  ### 0.9.1 / 2014-12-18
2
7
 
3
8
  * Check that all options to the WebSocket constructor are recognized
@@ -83,7 +83,7 @@ module Faye
83
83
 
84
84
  class Stream < RackStream
85
85
  def fail
86
- @socket_object.__send__(:finalize, '', 1006)
86
+ @socket_object.__send__(:finalize_close)
87
87
  end
88
88
 
89
89
  def receive(data)
@@ -36,12 +36,10 @@ module Faye
36
36
 
37
37
  @driver.on(:open) { |e| open }
38
38
  @driver.on(:message) { |e| receive_message(e.data) }
39
- @driver.on(:close) { |e| finalize(e.reason, e.code) }
39
+ @driver.on(:close) { |e| begin_close(e.reason, e.code) }
40
40
 
41
41
  @driver.on(:error) do |error|
42
- event = Event.create('error', :message => error.message)
43
- event.init_event('error', false, false)
44
- dispatch_event(event)
42
+ emit_error(error.message)
45
43
  end
46
44
 
47
45
  if @ping
@@ -52,6 +50,34 @@ module Faye
52
50
  end
53
51
  end
54
52
 
53
+ def write(data)
54
+ @stream.write(data)
55
+ end
56
+
57
+ def send(message)
58
+ return false if @ready_state > OPEN
59
+ case message
60
+ when Numeric then @driver.text(message.to_s)
61
+ when String then @driver.text(message)
62
+ when Array then @driver.binary(message)
63
+ else false
64
+ end
65
+ end
66
+
67
+ def ping(message = '', &callback)
68
+ return false if @ready_state > OPEN
69
+ @driver.ping(message, &callback)
70
+ end
71
+
72
+ def close
73
+ @ready_state = CLOSING unless @ready_state == CLOSED
74
+ @driver.close
75
+ end
76
+
77
+ def protocol
78
+ @driver.protocol || ''
79
+ end
80
+
55
81
  private
56
82
 
57
83
  def open
@@ -69,49 +95,43 @@ module Faye
69
95
  dispatch_event(event)
70
96
  end
71
97
 
72
- def finalize(reason = nil, code = nil)
73
- return if @ready_state == CLOSED
74
- @ready_state = CLOSED
75
- EventMachine.cancel_timer(@ping_timer) if @ping_timer
76
- @stream.close_connection_after_writing if @stream
77
- event = Event.create('close', :code => code || 1000, :reason => reason || '')
78
- event.init_event('close', false, false)
79
- dispatch_event(event)
80
- end
98
+ def emit_error(message)
99
+ return if @ready_state >= CLOSING
81
100
 
82
- def parse(data)
83
- worker = @proxy || @driver
84
- worker.parse(data)
101
+ event = Event.create('error', :message => message)
102
+ event.init_event('error', false, false)
103
+ dispatch_event(event)
85
104
  end
86
105
 
87
- public
88
-
89
- def write(data)
90
- @stream.write(data)
91
- end
106
+ def begin_close(reason, code)
107
+ return if @ready_state == CLOSED
108
+ @ready_state = CLOSING
92
109
 
93
- def send(message)
94
- return false if @ready_state > OPEN
95
- case message
96
- when Numeric then @driver.text(message.to_s)
97
- when String then @driver.text(message)
98
- when Array then @driver.binary(message)
99
- else false
110
+ if @stream
111
+ @stream.close_connection_after_writing
112
+ else
113
+ finalize_close
100
114
  end
115
+ @close_params = [reason, code]
101
116
  end
102
117
 
103
- def ping(message = '', &callback)
104
- return false if @ready_state > OPEN
105
- @driver.ping(message, &callback)
106
- end
118
+ def finalize_close
119
+ return if @ready_state == CLOSED
120
+ @ready_state = CLOSED
107
121
 
108
- def close
109
- @ready_state = CLOSING unless @ready_state == CLOSED
110
- @driver.close
122
+ EventMachine.cancel_timer(@ping_timer) if @ping_timer
123
+
124
+ reason = @close_params ? @close_params[0] : ''
125
+ code = @close_params ? @close_params[1] : 1006
126
+
127
+ event = Event.create('close', :code => code, :reason => reason)
128
+ event.init_event('close', false, false)
129
+ dispatch_event(event)
111
130
  end
112
131
 
113
- def protocol
114
- @driver.protocol || ''
132
+ def parse(data)
133
+ worker = @proxy || @driver
134
+ worker.parse(data)
115
135
  end
116
136
  end
117
137
 
@@ -50,19 +50,17 @@ module Faye
50
50
  end
51
51
 
52
52
  EventMachine.connect(endpoint.host, port, Connection) do |conn|
53
- @stream = conn
54
53
  conn.parent = self
55
54
  end
56
55
  rescue => error
57
- event = Event.create('error', :message => "Network error: #{url}: #{error.message}")
58
- event.init_event('error', false, false)
59
- dispatch_event(event)
60
- finalize('', 1006)
56
+ emit_error("Network error: #{url}: #{error.message}")
57
+ finalize_close
61
58
  end
62
59
 
63
60
  private
64
61
 
65
- def on_connect()
62
+ def on_connect(stream)
63
+ @stream = stream
66
64
  @stream.start_tls(@socket_tls) if @secure
67
65
  worker = @proxy || @driver
68
66
  worker.start
@@ -72,7 +70,7 @@ module Faye
72
70
  attr_accessor :parent
73
71
 
74
72
  def connection_completed
75
- parent.__send__(:on_connect)
73
+ parent.__send__(:on_connect, self)
76
74
  end
77
75
 
78
76
  def receive_data(data)
@@ -80,7 +78,7 @@ module Faye
80
78
  end
81
79
 
82
80
  def unbind
83
- parent.__send__(:finalize, '', 1006)
81
+ parent.__send__(:finalize_close)
84
82
  end
85
83
 
86
84
  def write(data)
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.1
4
+ version: 0.9.2
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-18 00:00:00.000000000 Z
11
+ date: 2014-12-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: eventmachine