Class: CoRE::CoAP::Observer

Inherits:
Object
  • Object
show all
Defined in:
lib/core/coap/observer.rb

Constant Summary collapse

MAX_OBSERVE_OPTION_VALUE =
8_388_608

Instance Method Summary collapse

Constructor Details

#initializeObserver

Returns a new instance of Observer


6
7
8
# File 'lib/core/coap/observer.rb', line 6

def initialize
  @logger = CoAP.logger
end

Instance Method Details

#observe(message, callback, socket) ⇒ Object


10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/core/coap/observer.rb', line 10

def observe(message, callback, socket)
  n = message.options[:observe]

  callback.call(socket, message)

  # This does not seem to be able to cope with concurrency.
  loop do
    answer = socket.receive(timeout: 0)

    next unless answer.options[:observe]

    if update?(n, answer.options[:observe])
      callback.call(socket, answer)
    end
  end
end