Class: Phone::BroadcastCallStatus

Inherits:
BaseService
  • Object
show all
Defined in:
app/services/phone/broadcast_call_status.rb

Overview

Class responsible for sending current calls

Defined Under Namespace

Classes: Result

Instance Method Summary collapse

Instance Method Details

#call_status_broadcast_hashObject



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/services/phone/broadcast_call_status.rb', line 16

def call_status_broadcast_hash
  current_calls = current_calls_grouped_by_employee_id
  broadcast = {}
  EmployeePhoneStatus.extension_to_employee_id_hash.each do |_extension, employee_id|
    current_call = current_calls[employee_id] || {}
    broadcast[employee_id] = {
      current_call_status: current_call[:state] || "",
      current_call: current_call,
      timestamp: Time.current.to_i
    }
  end
  broadcast
end

#current_calls_grouped_by_employee_idObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/services/phone/broadcast_call_status.rb', line 30

def current_calls_grouped_by_employee_id
  hsh = {}
  extension_map = EmployeePhoneStatus.extension_to_employee_id_hash
  current_calls = Phone::Pbx.instance.current_calls
  current_calls.each do |call|
    from_number = call[:from_caller_id_number]
    to_number = call[:to_caller_id_number]
    if (employee_id = extension_map[from_number])
      hsh[employee_id] = call.merge(direction: :out)
    elsif (employee_id = extension_map[to_number])
      hsh[employee_id] = call.merge(direction: :in)
    end
  end
  hsh
end

#perform(_options = {}) ⇒ Object



9
10
11
12
13
14
# File 'app/services/phone/broadcast_call_status.rb', line 9

def perform(_options = {})
  broadcast = call_status_broadcast_hash
  # TODO: REPLACE WITH SSE
  # ActionCable.server.broadcast('agent_statuses', broadcast)
  Result.new(broadcast: broadcast)
end