cal_core/device/
plugin.rs

1use crate::{ConnectState, FlowState};
2use cal_jambonz::shared::shared::SIPStatus;
3use serde::{Deserialize, Serialize};
4use std::fmt::{Debug, Formatter};
5use crate::device::device::{Connector, EndpointDevice};
6use crate::device::shared::{AiOptions, CallControl, RecordOptions, TranscribeOptions};
7
8#[derive(Serialize, Deserialize, Clone)]
9#[serde(rename_all = "camelCase")]
10pub struct Plugin {
11    //todo MapBox info
12    pub plugin: String,
13    pub data: String,
14    #[serde(default = "crate::device::shared::build_present")]
15    pub present: String,
16    #[serde(default = "crate::device::shared::build_country_code")]
17    pub country_code: String,
18    #[serde(default = "crate::device::shared::build_ring_time")]
19    pub ring_time: u8,
20    #[serde(default = "crate::device::shared::build_call_time")]
21    pub max_call_time: u16,
22    #[serde(default = "crate::device::shared::build_connect_to")]
23    pub on_transfer: String,
24    #[serde(default = "crate::device::shared::build_connect_to")]
25    pub on_error: String,
26    #[serde(default = "crate::device::shared::build_connect_to")]
27    pub on_complete: String,
28    #[serde(default = "crate::device::shared::build_connect_to")]
29    pub on_busy: String,
30    #[serde(default = "crate::device::shared::build_connect_to")]
31    pub on_fail: String,
32    #[serde(default = "crate::device::shared::build_connect_to")]
33    pub on_no_answer: String,
34    #[serde(default)]
35    pub record_options: RecordOptions,
36    #[serde(default)]
37    pub transcribe_options: TranscribeOptions,
38    #[serde(default)]
39    pub ai_options: AiOptions,
40    #[serde(default)]
41    pub call_control: CallControl,
42}
43
44impl Connector for Plugin {
45    fn get_connect_to(&mut self, state: &mut FlowState) -> ConnectState {
46        match &state.get_dial_status() {
47            Some(status) => match status {
48                SIPStatus::Ok => ConnectState::complete(self.on_complete.as_str()),
49                SIPStatus::RequestTerminated => ConnectState::no_answer(self.on_no_answer.as_str()),
50                SIPStatus::BusyHere | SIPStatus::BusyEverywhere => {
51                    ConnectState::busy(self.on_busy.as_str())
52                }
53                _ => ConnectState::fail(self.on_fail.as_str()),
54            },
55            None => ConnectState::dialling(),
56        }
57    }
58}
59
60impl EndpointDevice for Plugin {
61    fn device_type_name(&self) -> &'static str {
62        "Plugin"
63    }
64
65    fn supports_routing(&self) -> bool {
66        true
67    }
68}
69
70impl Debug for Plugin {
71    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
72        f.debug_struct("Plugin")
73            .field("plugin", &self.plugin)
74            .field("data", &self.data)
75            .field("present", &self.present)
76            .field("country_code", &self.country_code)
77            .field("ring_time", &self.ring_time)
78            .field("max_call_time", &self.max_call_time)
79            .field("on_transfer", &self.on_transfer)
80            .field("on_error", &self.on_error)
81            .field("on_complete", &self.on_complete)
82            .field("on_busy", &self.on_busy)
83            .field("on_fail", &self.on_fail)
84            .field("on_no_answer", &self.on_no_answer)
85            .field("record_options", &self.record_options)
86            .field("transcribe_options", &self.transcribe_options)
87            .field("ai_options", &self.ai_options)
88            .field("call_control", &self.call_control)
89            .finish()
90    }
91}
92
93
94#[derive(Serialize, Deserialize, Clone)]
95#[serde(rename_all = "camelCase")]
96pub struct MapBox {
97    #[serde(default)]
98    pub bounds: MapBoxBoundary,
99    #[serde(default)]
100    pub features: Vec<MapBoxFeature>,
101}
102
103#[derive(Serialize, Deserialize, Clone)]
104#[serde(rename_all = "camelCase")]
105pub struct MapBoxBoundary {
106    pub xmin: f32,
107    pub ymin: f32,
108    pub xmax: f32,
109    pub ymax: f32,
110}
111
112impl Default for MapBoxBoundary {
113    fn default() -> Self {
114        Self {
115            xmin: 0.00,
116            ymin: 1.00,
117            xmax: 0.01,
118            ymax: 1.01,
119        }
120    }
121}
122
123#[derive(Serialize, Deserialize, Clone)]
124#[serde(rename_all = "camelCase")]
125pub struct MapBoxFeature {
126    pub id: String,
127    #[serde(rename = "type")]
128    pub feature_type: String,
129    pub geometry: MapBoxGeometry,
130}
131
132#[derive(Serialize, Deserialize, Clone)]
133#[serde(rename_all = "camelCase")]
134pub struct MapBoxGeometry {
135    #[serde(rename = "type")]
136    pub geometry_type: String,
137    pub coordinates: Vec<Vec<(f32, f32)>>,
138}
139
140