Module: Pbx::Status
- Defined in:
- lib/pbx/status.rb
Constant Summary collapse
- STATUS_COLORS =
{ "registered" => "#22c55e", "reachable" => "#22c55e", "lagged" => "#f59e0b", "unreachable" => "#ef4444", "unregistered" => "#6b7280", "unmonitored" => "#6b7280", "unknown" => "#6b7280" }.freeze
- STATUS_LABELS =
{ "registered" => "Registered", "reachable" => "Reachable", "lagged" => "Lagged", "unreachable" => "Unreachable", "unregistered" => "Unregistered", "unmonitored" => "Unmonitored", "unknown" => "Unknown" }.freeze
- QUEUE_MEMBER_STATES =
{ "1" => "not_in_use", "2" => "in_use", "3" => "busy", "5" => "unavailable", "6" => "ringing", "8" => "on_hold" }.freeze
Class Method Summary collapse
- .color(status) ⇒ Object
- .describe(status) ⇒ Object
-
.from_pjsip_device_state(raw) ⇒ Object
Maps PJSIP DeviceState strings ("Not in use", "In use", "Unavailable"…) to the same internal keys used by describe/color.
-
.from_sip(raw) ⇒ Object
Normalises the raw AMI Status string from SIPpeers/PeerStatus into a lowercase key used by describe/color.
- .queue_member_state(code) ⇒ Object
-
.rtt_from_sip(raw) ⇒ Object
Extracts the RTT in milliseconds from strings like "OK (5 ms)".
Class Method Details
.color(status) ⇒ Object
29 30 31 |
# File 'lib/pbx/status.rb', line 29 def self.color(status) STATUS_COLORS[status.to_s.downcase] || "#6b7280" end |
.describe(status) ⇒ Object
25 26 27 |
# File 'lib/pbx/status.rb', line 25 def self.describe(status) STATUS_LABELS[status.to_s.downcase] || status.to_s.capitalize end |
.from_pjsip_device_state(raw) ⇒ Object
Maps PJSIP DeviceState strings ("Not in use", "In use", "Unavailable"…) to the same internal keys used by describe/color. Any reachable state (in use, ringing, on hold…) maps to "registered" so the peers table shows the endpoint as up.
66 67 68 69 70 71 72 73 74 |
# File 'lib/pbx/status.rb', line 66 def self.from_pjsip_device_state(raw) return "unknown" unless raw s = raw.to_s.downcase return "unknown" if s.empty? return "unreachable" if s.include?("unavailable") || s.include?("invalid") "registered" end |
.from_sip(raw) ⇒ Object
Normalises the raw AMI Status string from SIPpeers/PeerStatus into a lowercase key used by describe/color.
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/pbx/status.rb', line 35 def self.from_sip(raw) return "unknown" unless raw s = raw.to_s.downcase return "registered" if s.start_with?("ok") return "unreachable" if s.include?("unreachable") return "lagged" if s.include?("lagged") return "unregistered" if s.include?("unregistered") return "unmonitored" if s.include?("unmonitored") return "registered" if s.include?("registered") || s.include?("reachable") "unknown" end |
.queue_member_state(code) ⇒ Object
58 59 60 |
# File 'lib/pbx/status.rb', line 58 def self.queue_member_state(code) QUEUE_MEMBER_STATES[code.to_s] || "unknown" end |
.rtt_from_sip(raw) ⇒ Object
Extracts the RTT in milliseconds from strings like "OK (5 ms)".
77 78 79 80 81 82 |
# File 'lib/pbx/status.rb', line 77 def self.rtt_from_sip(raw) return nil unless raw match = raw.match(/\((\d+)\s*ms\)/i) match ? match[1].to_i : nil end |