Skip to content

Commit 63eb63a

Browse files
committed
Support binary
1 parent 44ce03c commit 63eb63a

File tree

4 files changed

+10
-4
lines changed

4 files changed

+10
-4
lines changed

lib/em-websocket/connection.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,16 @@ def onopen(&blk); @onopen = blk; end
1010
def onclose(&blk); @onclose = blk; end
1111
def onerror(&blk); @onerror = blk; end
1212
def onmessage(&blk); @onmessage = blk; end
13+
def onbinary(&blk); @onbinary = blk; end
1314
def onping(&blk); @onping = blk; end
1415
def onpong(&blk); @onpong = blk; end
1516

1617
def trigger_on_message(msg)
1718
@onmessage.call(msg) if defined? @onmessage
1819
end
20+
def trigger_on_binary(msg)
21+
@onbinary.call(msg) if defined? @onbinary
22+
end
1923
def trigger_on_open(handshake)
2024
@onopen.call(handshake) if defined? @onopen
2125
end

lib/em-websocket/message_processor_03.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def message(message_type, extension_data, application_data)
3434
end
3535
@connection.trigger_on_message(application_data)
3636
when :binary
37-
@connection.trigger_on_message(application_data)
37+
@connection.trigger_on_binary(application_data)
3838
end
3939
end
4040

lib/em-websocket/message_processor_06.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def message(message_type, extension_data, application_data)
5151
end
5252
@connection.trigger_on_message(application_data)
5353
when :binary
54-
@connection.trigger_on_message(application_data)
54+
@connection.trigger_on_binary(application_data)
5555
end
5656
end
5757

spec/integration/draft03_spec.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ def start_client
114114
data = "a" * 256
115115

116116
start_server { |ws|
117-
ws.onmessage { |msg|
117+
ws.onbinary { |msg|
118+
msg.encoding.should == Encoding.find("BINARY") if defined?(Encoding)
118119
msg.should == data
119120
done
120121
}
@@ -134,7 +135,8 @@ def start_client
134135
data = "a" * 65536
135136

136137
start_server { |ws|
137-
ws.onmessage { |msg|
138+
ws.onbinary { |msg|
139+
msg.encoding.should == Encoding.find("BINARY") if defined?(Encoding)
138140
msg.should == data
139141
done
140142
}

0 commit comments

Comments
 (0)