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



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/sockjs/session.rb', line 36

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



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

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

#disconnectObject

Close the response not the session



17
18
19
# File 'lib/sockjs/session.rb', line 17

def disconnect
  @response.finish
end

#heartbeatObject



21
22
23
# File 'lib/sockjs/session.rb', line 21

def heartbeat
  transport.heartbeat_frame(response)
end

#messages(items) ⇒ Object



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

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