Class: WebSocket::Frame::Outgoing

Inherits:
Base
  • Object
show all
Defined in:
lib/websocket/frame/outgoing.rb,
lib/websocket/frame/outgoing/client.rb,
lib/websocket/frame/outgoing/server.rb

Overview

Note:

You should NEVER use this class directly - use Client or Server subclasses instead, as they contain additional frame options(i.e. Client-side masking in draft 04)

Construct or parse incoming WebSocket Frame.

Examples:

frame = WebSocket::Frame::Outgoing::Server.new(:version => @handshake.version, :data => "Hello", :type => :text)
frame.to_s # "\x81\x05\x48\x65\x6c\x6c\x6f"

Direct Known Subclasses

Client, Server

Defined Under Namespace

Classes: Client, Server

Instance Attribute Summary

Attributes inherited from Base

#data, #error, #type, #version

Instance Method Summary collapse

Methods inherited from Base

#error?, #initialize, #inspect, #support_type?, #supported_frames

Constructor Details

This class inherits a constructor from WebSocket::Frame::Base

Instance Method Details

#require_sending?Boolean

Should current frame be sent? Exclude empty frames etc.

Returns:

  • (Boolean)

    true if frame should be sent



22
23
24
# File 'lib/websocket/frame/outgoing.rb', line 22

def require_sending?
  !error?
end

#supported?Boolean

Is selected type supported by current draft version?

Returns:

  • (Boolean)

    true if frame type is supported



16
17
18
# File 'lib/websocket/frame/outgoing.rb', line 16

def supported?
  support_type?
end

#to_sObject

Return raw frame formatted for sending.



27
28
29
30
# File 'lib/websocket/frame/outgoing.rb', line 27

def to_s
  set_error(:unknown_frame_type) and return unless supported?
  encode_frame
end