Skip to content
This repository has been archived by the owner on Dec 7, 2018. It is now read-only.

Commit

Permalink
forward ping to @driver - with test
Browse files Browse the repository at this point in the history
  • Loading branch information
kenichi committed Feb 21, 2016
1 parent dbfaf49 commit de30b45
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/reel/websocket.rb
Expand Up @@ -10,6 +10,7 @@ class WebSocket

attr_reader :socket
def_delegators :@socket, :addr, :peeraddr
def_delegators :@driver, :ping

def initialize(info, connection)
driver_env = DriverEnvironment.new(info, connection.socket)
Expand Down
14 changes: 14 additions & 0 deletions spec/reel/websocket_spec.rb
Expand Up @@ -173,6 +173,20 @@ def initialize(websocket)
end
end

it "pings clients" do
with_websocket_pair do |client, websocket|
websocket.ping "<3"

pinger = double "pinger"
expect(pinger).to receive(:ping) { |msg| expect(msg).to eq("<3") }

parser = WebSocket::Parser.new
parser.on_ping { |msg| pinger.ping msg }

parser << client.readpartial(4096)
end
end

def with_websocket_pair
with_socket_pair do |client, peer|
connection = Reel::Connection.new(peer)
Expand Down

0 comments on commit de30b45

Please sign in to comment.