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 outgoing 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

#code, #data, #error, #type, #version

Attributes included from ExceptionHandler

#error

Instance Method Summary collapse

Methods inherited from Base

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

Methods included from NiceInspect

#inspect

Methods included from ExceptionHandler

included

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



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

def require_sending?
  !error?
end

#supported?Boolean

Is selected type supported by current draft version?

Returns:

  • (Boolean)

    true if frame type is supported



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

def supported?
  support_type?
end

#to_sObject

Return raw frame formatted for sending.



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

def to_s
  raise WebSocket::Error::Frame::UnknownFrameType unless supported?
  @handler.encode_frame
end