Class: Mongrel2::WebSocket::Response

Inherits:
Response
  • Object
show all
Extended by:
Forwardable
Includes:
FrameMethods
Defined in:
lib/mongrel2/websocket.rb

Overview

WebSocket response – this is the container for Frames sent to a client.

Constant Summary

Constants inherited from Response

Response::DEFAULT_CHUNKSIZE

Instance Attribute Summary

Attributes inherited from Response

#body, #chunksize, #conn_id, #extended_reply_data, #extended_reply_filter, #request, #sender_id

Class Method Summary collapse

Instance Method Summary collapse

Methods included from FrameMethods

#<<, #inspect_details

Methods inherited from Response

#<<, #each_chunk, #extend_reply_with, #extended_reply?, #inspect, #puts, #socket_id, #to_s

Constructor Details

#initialize(sender_id, conn_id, body = '') ⇒ Response

Init a few instance variables unique to websocket requests/responses.



402
403
404
405
# File 'lib/mongrel2/websocket.rb', line 402

def initialize( sender_id, conn_id, body='' )
  @frame = Mongrel2::WebSocket::Frame.new( body )
  super( sender_id, conn_id, @frame.payload )
end

Class Method Details

.from_request(request) ⇒ Object

Return a response to the specified request, inferring appropriate flags if appropriate.



386
387
388
389
390
391
392
393
394
395
396
397
398
# File 'lib/mongrel2/websocket.rb', line 386

def self::from_request( request )
  response = super

  if request.opcode == :ping
    response.opcode = :pong
    IO.copy_stream( request.payload, response.payload, 4096 )
  else
    # Numeric in case it's a custom (reserved) value
    response.opcode = request.numeric_opcode
  end

  return response
end

Instance Method Details

#frameObject

Delegate some methods to the contained frame



410
411
# File 'lib/mongrel2/websocket.rb', line 410

def_instance_delegators :frame,
:puts, :to_s, :each_chunk, :<<, :make_close_frame, :set_status