class WebSocket::Driver::Server - websocket-driver-0.6.5 Documentation

# class WebSocket::Driver::Server

### Constants

EVENTS

### Public Class Methods

new(socket, options = {}) click to toggle source
Calls superclass method WebSocket::Driver.new

    # File lib/websocket/driver/server.rb, line 7
    def initialize(socket, options = {})
      super
      @http = HTTP::Request.new
      @delegate = nil
    end

### Public Instance Methods

env() click to toggle source

    # File lib/websocket/driver/server.rb, line 13
    def env
      @http.complete? ? @http.env : nil
    end

parse(chunk) click to toggle source

    # File lib/websocket/driver/server.rb, line 43
    def parse(chunk)
      return @delegate.parse(chunk) if @delegate

      @http.parse(chunk)
      return fail_request('Invalid HTTP request') if @http.error?
      return unless @http.complete?

      @delegate = Driver.rack(self, @options)
      open

      EVENTS.each do |event|
        @delegate.on(event) { |e| emit(event, e) }
      end

      emit(:connect, ConnectEvent.new)
    end

url() click to toggle source

    # File lib/websocket/driver/server.rb, line 17
    def url
      return nil unless e = env

      url  = "ws://#{e['HTTP_HOST']}"
      url << e['PATH_INFO']
      url << "?#{e['QUERY_STRING']}" unless e['QUERY_STRING'] == ''
      url
    end

write(buffer) click to toggle source

    # File lib/websocket/driver/server.rb, line 60
    def write(buffer)
      @socket.write(buffer)
    end

### Private Instance Methods

fail_request(message) click to toggle source

    # File lib/websocket/driver/server.rb, line 66
    def fail_request(message)
      emit(:error, ProtocolError.new(message))
      emit(:close, CloseEvent.new(Hybi::ERRORS[:protocol_error], message))
    end

open() click to toggle source

    # File lib/websocket/driver/server.rb, line 71
    def open
      @queue.each do |method, args, block|
        @delegate.__send__(method, *args, &block)
      end
      @queue = []
    end