Class: Kameleoon::RealTime::SseClient

Inherits:
Object
  • Object
show all
Defined in:
lib/kameleoon/real_time/sse_client.rb

Overview

SseClient is used to interpret SSE event stream.

Instance Method Summary collapse

Constructor Details

#initialize(sse_request, message_handler) ⇒ SseClient

Parametrized initializer.

is synchronously called for received SSE messages.

Parameters:



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/kameleoon/real_time/sse_client.rb', line 18

def initialize(sse_request, message_handler)
  @sse_request = sse_request
  @message_handler = message_handler

  @cr_prev = nil
  @buffer = nil
  @data_buffer = nil
  @event = nil
  @id = nil
  @reconnection_time = nil

  @sse_request.resp_char_handler = method(:process_char)
end

Instance Method Details

#call_close_handlerObject

Calls @sse_request@close_handler if it is not nil.



45
46
47
# File 'lib/kameleoon/real_time/sse_client.rb', line 45

def call_close_handler
  @sse_request.call_close_handler
end

#startObject

Starts SSE connection and stay in the loop until close.



34
35
36
37
38
39
40
41
# File 'lib/kameleoon/real_time/sse_client.rb', line 34

def start
  @cr_prev = false
  @data_buffer = []
  @event = nil
  @id = nil
  @buffer = []
  @sse_request.start
end