Class: WebSocket::Frame::Base Abstract

Inherits:
Object
  • Object
show all
Includes:
ExceptionHandler, NiceInspect
Defined in:
lib/websocket/frame/base.rb

Overview

This class is abstract.

Subclass and override to implement custom frames

Direct Known Subclasses

Incoming, Outgoing

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from NiceInspect

#inspect

Methods included from ExceptionHandler

included

Constructor Details

#initialize(args = {}) ⇒ Base

Initialize frame

Parameters:

  • args (Hash) (defaults to: {})

    Arguments for frame

Options Hash (args):

  • :data (String)

    default data for frame

  • :type (String)

    Type of frame - available types are “text”, “binary”, “ping”, “pong” and “close”(support depends on draft version)

  • :code (Integer)

    Code for close frame. Supported by drafts > 05.

  • :version (Integer)

    Version of draft. Currently supported version are 75, 76 and 00-13.



19
20
21
22
23
24
25
26
# File 'lib/websocket/frame/base.rb', line 19

def initialize(args = {})
  @type = args[:type].to_sym if args[:type]
  @code = args[:code]
  @data = Data.new(args[:data].to_s)
  @version = args[:version] || DEFAULT_VERSION
  @handler = nil
  include_version
end

Instance Attribute Details

#codeObject

Returns the value of attribute code.



11
12
13
# File 'lib/websocket/frame/base.rb', line 11

def code
  @code
end

#dataObject

Returns the value of attribute data.



11
12
13
# File 'lib/websocket/frame/base.rb', line 11

def data
  @data
end

#errorObject (readonly)

Returns the value of attribute error.



10
11
12
# File 'lib/websocket/frame/base.rb', line 10

def error
  @error
end

#typeObject (readonly)

Returns the value of attribute type.



10
11
12
# File 'lib/websocket/frame/base.rb', line 10

def type
  @type
end

#versionObject (readonly)

Returns the value of attribute version.



10
11
12
# File 'lib/websocket/frame/base.rb', line 10

def version
  @version
end

Instance Method Details

#error?Boolean

Check if some errors occured

Returns:

  • (Boolean)

    True if error is set



31
32
33
# File 'lib/websocket/frame/base.rb', line 31

def error?
  !@error.nil?
end

#support_type?Boolean

Is selected type supported for selected handler?

Returns:

  • (Boolean)


36
37
38
# File 'lib/websocket/frame/base.rb', line 36

def support_type?
  @handler.supported_frames.include?(@type)
end

#supported_framesObject

Implement in submodules

Raises:

  • (NotImplementedError)


41
42
43
# File 'lib/websocket/frame/base.rb', line 41

def supported_frames
  raise NotImplementedError
end