Class: Kibosh::Session::Stream

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

Direct Known Subclasses

XMPP::Session::Stream

Defined Under Namespace

Modules: Response

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object, request, response) ⇒ Stream

Returns a new instance of Stream.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/kibosh/session/stream.rb', line 15

def initialize object, request, response
  case object
  when Kibosh::Session::Stream
    other = object
    @session = other.session
    @to = other.to
    @route = other.route
    @driver = other.driver
    session.streams << self
  when Kibosh::Session
    session = object
    @session = session
    @to = request["to"]
    @route = request["route"]
    @driver = request.driver @session, @to, @route
    session.streams << self
    response.stream = self
    yield connect request, response.extend(Response)
  else
    raise "hell"
  end
end

Instance Attribute Details

#connectionObject (readonly)

Returns the value of attribute connection.



12
13
14
# File 'lib/kibosh/session/stream.rb', line 12

def connection
  @connection
end

#driverObject (readonly)

Returns the value of attribute driver.



12
13
14
# File 'lib/kibosh/session/stream.rb', line 12

def driver
  @driver
end

#fromObject

Returns the value of attribute from.



13
14
15
# File 'lib/kibosh/session/stream.rb', line 13

def from
  @from
end

#routeObject (readonly)

Returns the value of attribute route.



12
13
14
# File 'lib/kibosh/session/stream.rb', line 12

def route
  @route
end

#secureObject

Returns the value of attribute secure.



13
14
15
# File 'lib/kibosh/session/stream.rb', line 13

def secure
  @secure
end

#sessionObject (readonly)

Returns the value of attribute session.



12
13
14
# File 'lib/kibosh/session/stream.rb', line 12

def session
  @session
end

#toObject (readonly)

Returns the value of attribute to.



12
13
14
# File 'lib/kibosh/session/stream.rb', line 12

def to
  @to
end

Instance Method Details

#abortObject



108
109
110
# File 'lib/kibosh/session/stream.rb', line 108

def abort
  session.streams.delete self
end

#bodyObject



45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/kibosh/session/stream.rb', line 45

def body
  @body ||=
    begin
      document = Nokogiri::XML::Document.new
      body = document.create_element("body")
      # puts "new body #{body.object_id}"
      body["xmlns"] = 'http://jabber.org/protocol/httpbind'
      body["stream"] = id
      document.root = body
    end
  # puts "current body #{@body.object_id}"
  # raise "hell" if @body["sent"]
  @body
end

#body=(body) ⇒ Object



60
61
62
63
64
# File 'lib/kibosh/session/stream.rb', line 60

def body= body
  raise "hell" if @body || !body.nil?
  # puts "set body #{body.object_id}"
  @body = body
end

#closeObject



103
104
105
106
# File 'lib/kibosh/session/stream.rb', line 103

def close
  raise "implement"
  abort
end

#idObject



99
100
101
# File 'lib/kibosh/session/stream.rb', line 99

def id
  @id ||= ('%16.16f' % rand)[2..-1]
end

#lock(body) ⇒ Object



66
67
68
69
70
71
72
73
74
75
# File 'lib/kibosh/session/stream.rb', line 66

def lock body
  # puts "lock? #{body.object_id} #{@body.object_id} (#{body['sent']})"
  # raise "hell" if body['sent']
  if body.object_id == @body.object_id
    # puts "locking #{@body}"
    @body = nil
  else
    # puts "not locking #{@body}"
  end
end

#ready!Object



81
82
83
# File 'lib/kibosh/session/stream.rb', line 81

def ready!
  respond
end

#respondObject



77
78
79
# File 'lib/kibosh/session/stream.rb', line 77

def respond
  @body = @session.respond @body
end

#stopObject



38
39
40
41
42
43
# File 'lib/kibosh/session/stream.rb', line 38

def stop
  # FIX
  body["type"] = "terminate"
  body["condition"] = "system-shutdown"
  respond
end

#terminate(request, response) ⇒ Object



85
86
87
88
89
90
91
92
93
# File 'lib/kibosh/session/stream.rb', line 85

def terminate request, response
  document = Nokogiri::XML::Document.new
  body = document.create_element("body")
  body["xmlns"] = 'http://jabber.org/protocol/httpbind'
  # body["stream"] = id (?)
  response.body = document.root = body
  abort
  response
end

#terminate!Object



95
96
97
# File 'lib/kibosh/session/stream.rb', line 95

def terminate!
  abort
end