websocket-eventmachine-base 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.0.1
4
+
5
+ - prevent sending messages after connection was closed
6
+ - prevent duplicated close frames
7
+
3
8
  ## 1.0.0
4
9
 
5
10
  - initial release
@@ -1,7 +1,7 @@
1
1
  module WebSocket
2
2
  module EventMachine
3
3
  class Base
4
- VERSION = '1.0.0'
4
+ VERSION = '1.0.1'
5
5
  end
6
6
  end
7
7
  end
@@ -48,6 +48,7 @@ module WebSocket
48
48
  # @return [Boolean] true if data was send, otherwise call on_error if needed
49
49
  def send(data, args = {})
50
50
  type = args[:type] || :text
51
+ return if @state == :closed || (@state == :closing && type != :close)
51
52
  unless type == :plain
52
53
  frame = outgoing_frame.new(:version => @handshake.version, :data => data, :type => type.to_s, :code => args[:code])
53
54
  if !frame.supported?
@@ -156,29 +157,35 @@ module WebSocket
156
157
  def handle_open(data)
157
158
  @frame << data
158
159
  while frame = @frame.next
159
- case frame.type
160
- when :close
161
- @state = :closing
162
- close
163
- trigger_onclose(frame.to_s)
164
- when :ping
165
- pong(frame.to_s)
166
- trigger_onping(frame.to_s)
167
- when :pong
168
- trigger_onpong(frame.to_s)
169
- when :text
170
- trigger_onmessage(frame.to_s, :text)
171
- when :binary
172
- trigger_onmessage(frame.to_s, :binary)
160
+ if @state == :open
161
+ case frame.type
162
+ when :close
163
+ @state = :closing
164
+ close
165
+ trigger_onclose(frame.to_s)
166
+ when :ping
167
+ pong(frame.to_s)
168
+ trigger_onping(frame.to_s)
169
+ when :pong
170
+ trigger_onpong(frame.to_s)
171
+ when :text
172
+ trigger_onmessage(frame.to_s, :text)
173
+ when :binary
174
+ trigger_onmessage(frame.to_s, :binary)
175
+ end
176
+ else
177
+ break
173
178
  end
174
179
  end
175
180
  unbind if @frame.error?
176
181
  end
177
182
 
178
183
  def handle_closing(data)
179
- @state = :closed
180
- close
181
- trigger_onclose
184
+ unless @state == :closed
185
+ @state = :closed
186
+ close
187
+ trigger_onclose('')
188
+ end
182
189
  end
183
190
 
184
191
  def debug(description, data)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: websocket-eventmachine-base
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: