class WebSocket::Frame::Base
@abstract Subclass and override to implement custom frames
Attributes
Public Class Methods
Source
# 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
Initialize frame @param args [Hash] Arguments for frame @option args [String] :data default data for frame @option args [String] :type Type of frame - available types are “text”, “binary”, “ping”, “pong” and “close”(support depends on draft version) @option args [Integer] :code Code for close frame. Supported by drafts > 05. @option args [Integer] :version Version of draft. Currently supported version are 75, 76 and 00-13.
Public Instance Methods
Source
# File lib/websocket/frame/base.rb, line 31 def error? !@error.nil? end
Check if some errors occured @return [Boolean] True if error is set
Source
# File lib/websocket/frame/base.rb, line 36 def support_type? @handler.supported_frames.include?(@type) end
Is selected type supported for selected handler?
Source
# File lib/websocket/frame/base.rb, line 41 def supported_frames raise NotImplementedError end
Implement in submodules
Private Instance Methods
Source
# File lib/websocket/frame/base.rb, line 49 def include_version @handler = case @version when 75..76 then Handler::Handler75.new(self) when 0..2 then Handler::Handler75.new(self) when 3 then Handler::Handler03.new(self) when 4 then Handler::Handler04.new(self) when 5..6 then Handler::Handler05.new(self) when 7..13 then Handler::Handler07.new(self) else raise WebSocket::Error::Frame::UnknownVersion end end
Include set of methods for selected protocol version @return [Boolean] false if protocol number is unknown, otherwise true