Class: Switest::Session

Inherits:
Librevox::Listener::Inbound
  • Object
show all
Defined in:
lib/switest/session.rb

Overview

Inbound ESL session built on librevox.

A single connection to FreeSWITCH that handles both commands and events (filtered by UUID). Events are dispatched to Call objects via the call_registry. Unknown CHANNEL_PARK events trigger the offer_handler for inbound call detection.

Class-level state (call_registry, offer_handler, connection_promise) is used because librevox instantiates Session internally — we cannot inject dependencies via the constructor. Client sets these before starting the connection and clears them on stop.

Class Attribute Summary collapse

Instance Method Summary collapse

Class Attribute Details

.call_registryObject

{ uuid => Call }



20
21
22
# File 'lib/switest/session.rb', line 20

def call_registry
  @call_registry
end

.connection_promiseObject

Async::Promise resolved when connected



22
23
24
# File 'lib/switest/session.rb', line 22

def connection_promise
  @connection_promise
end

.offer_handlerObject

Proc for inbound call offers



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

def offer_handler
  @offer_handler
end

Instance Method Details

#bgapi(cmd) ⇒ Object



45
46
47
# File 'lib/switest/session.rb', line 45

def bgapi(cmd)
  send_message("bgapi #{cmd}")
end

#connection_completedObject



25
26
27
# File 'lib/switest/session.rb', line 25

def connection_completed
  self.class.connection_promise&.resolve(self)
end

#on_event(event) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/switest/session.rb', line 29

def on_event(event)
  uuid = event.content[:unique_id]
  call = self.class.call_registry&.[](uuid)

  case event.event
  when "CHANNEL_CALLSTATE", "CHANNEL_HANGUP_COMPLETE", "DTMF"
    call&.handle_event(event)
  when "CHANNEL_PARK"
    if call
      call.handle_event(event)
    else
      self.class.offer_handler&.call(event)
    end
  end
end