Skip to content

Commit 55fddc5

Browse files
committed
Add PingMessage along side TextMessage and BinaryMessage.
1 parent 62c8d1c commit 55fddc5

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

lib/protocol/websocket/message.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,5 +72,12 @@ def send(connection, **options)
7272
connection.send_binary(@buffer, **options)
7373
end
7474
end
75+
76+
# Represents a ping message that can be sent over a WebSocket connection.
77+
class PingMessage < Message
78+
def send(connection)
79+
connection.send_ping(@buffer)
80+
end
81+
end
7582
end
7683
end

test/protocol/websocket/connection.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,7 @@
336336
connection.write("Hello World!".b)
337337

338338
frame = client.read_frame
339+
expect(frame).to be_a(Protocol::WebSocket::BinaryFrame)
339340
expect(frame.unpack).to be == "Hello World!".b
340341
end
341342

@@ -344,6 +345,16 @@
344345
connection.write(message)
345346

346347
frame = client.read_frame
348+
expect(frame).to be_a(Protocol::WebSocket::TextFrame)
349+
expect(frame.unpack).to be == "Hello World!"
350+
end
351+
352+
it "can send ping mmessages" do
353+
message = Protocol::WebSocket::PingMessage.new("Hello World!")
354+
connection.write(message)
355+
356+
frame = client.read_frame
357+
expect(frame).to be_a(Protocol::WebSocket::PingFrame)
347358
expect(frame.unpack).to be == "Hello World!"
348359
end
349360
end

0 commit comments

Comments
 (0)