Class: SockJS::Session::Consumer

Inherits:
Object
  • Object
show all
Defined in:
lib/sockjs/session.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response, transport) ⇒ Consumer

Returns a new instance of Consumer.



9
10
11
12
13
# File 'lib/sockjs/session.rb', line 9

def initialize(response, transport)
  @response = response
  @transport = transport
  @total_sent_length = 0
end

Instance Attribute Details

#responseObject (readonly)

Returns the value of attribute response.



14
15
16
# File 'lib/sockjs/session.rb', line 14

def response
  @response
end

#total_sent_lengthObject (readonly)

Returns the value of attribute total_sent_length.



14
15
16
# File 'lib/sockjs/session.rb', line 14

def total_sent_length
  @total_sent_length
end

#transportObject (readonly)

Returns the value of attribute transport.



14
15
16
# File 'lib/sockjs/session.rb', line 14

def transport
  @transport
end

Instance Method Details

#check_aliveObject

XXX Still not sure what this is FOR



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/sockjs/session.rb', line 42

def check_alive
  if !@response.body.closed?
    if @response.due_for_alive_check
      SockJS.debug "Checking if still alive"
      @response.write(@transport.empty_string)
    else
      puts "~ [TODO] Not checking if still alive, why?"
      puts "Status: #{@status} (response.body.closed: #{@response.body.closed?})\nSession class: #{self.class}\nTransport class: #{@transport.class}\nResponse: #{@response.to_s}\n\n"
    end
  end
end

#closing(status, message) ⇒ Object



37
38
39
# File 'lib/sockjs/session.rb', line 37

def closing(status, message)
  transport.closing_frame(response, status, message)
end

#disconnectObject

Close the response not the session



17
18
19
20
21
22
23
24
25
# File 'lib/sockjs/session.rb', line 17

def disconnect
  #WEBSOCKET shouldn't have limit of data - faye will send closing frame
  #after 1GB
  if @transport.kind_of?(SockJS::Transports::WebSocket)
    @total_sent_length = 0
    return
  end
  @response.finish if @response.respond_to?(:finish)
end

#heartbeatObject



27
28
29
# File 'lib/sockjs/session.rb', line 27

def heartbeat
  transport.heartbeat_frame(response)
end

#messages(items) ⇒ Object



31
32
33
34
35
# File 'lib/sockjs/session.rb', line 31

def messages(items)
  unless items.empty?
    @total_sent_length += transport.messages_frame(response, items)
  end
end