Support outbound call
This commit is contained in:
@@ -46,7 +46,7 @@ pub fn no_service(_did: Did) -> XMLElement {
|
||||
let no_service_path = format!("{}/no_service.wav", sound_path);
|
||||
let mut work = XMLElement::new("work");
|
||||
|
||||
add_playback(&mut work, &no_service_path);
|
||||
add_playback_element(&mut work, &no_service_path);
|
||||
|
||||
work
|
||||
}
|
||||
@@ -58,7 +58,7 @@ pub fn night_mode(_did: Did) -> XMLElement {
|
||||
|
||||
let mut work = XMLElement::new("work");
|
||||
|
||||
add_playback(&mut work, &night_mode_path);
|
||||
add_playback_element(&mut work, &night_mode_path);
|
||||
|
||||
work
|
||||
}
|
||||
@@ -68,7 +68,19 @@ pub fn custom_message(_did: Did) -> XMLElement {
|
||||
work
|
||||
}
|
||||
|
||||
pub fn add_playback(work: &mut XMLElement ,file_path: &str) {
|
||||
pub fn outbound(d: &str) -> XMLElement {
|
||||
let mut work = XMLElement::new("work");
|
||||
let mut bridge = XMLElement::new("execute");
|
||||
|
||||
bridge.add_attribute("application", "bridge");
|
||||
bridge.add_attribute("data", format!("sofia/gateway/powernet_1/{}", d).as_str());
|
||||
|
||||
work.add_child(bridge).unwrap();
|
||||
|
||||
work
|
||||
}
|
||||
|
||||
pub fn add_playback_element(work: &mut XMLElement ,file_path: &str) {
|
||||
let mut answer = XMLElement::new("execute");
|
||||
answer.add_attribute("application", "answer");
|
||||
work.add_child(answer).unwrap();
|
||||
@@ -78,9 +90,37 @@ pub fn add_playback(work: &mut XMLElement ,file_path: &str) {
|
||||
work.add_child(playback).unwrap();
|
||||
}
|
||||
|
||||
pub fn route_call(did: String) -> Vec<u8> {
|
||||
let d = db::get_did_by(&did).unwrap();
|
||||
let did_active = d.active;
|
||||
pub fn build_work_element(did: &str, caller_ipaddr: &str) -> XMLElement {
|
||||
if db::from_pbx(&caller_ipaddr).unwrap() == true {
|
||||
outbound(did)
|
||||
} else {
|
||||
let d = db::get_did_by(&did).unwrap();
|
||||
let work = match d.target_type {
|
||||
DidTargetType::Url => {
|
||||
url(d)
|
||||
},
|
||||
DidTargetType::Moh => {
|
||||
moh(d)
|
||||
},
|
||||
DidTargetType::ExternalNumber => {
|
||||
external_number(d)
|
||||
},
|
||||
DidTargetType::NoService => {
|
||||
no_service(d)
|
||||
},
|
||||
DidTargetType::NightMode => {
|
||||
night_mode(d)
|
||||
},
|
||||
DidTargetType::CustomMessage => {
|
||||
custom_message(d)
|
||||
}
|
||||
};
|
||||
|
||||
work
|
||||
}
|
||||
}
|
||||
|
||||
pub fn route_call(did: String, caller_ipaddr: String) -> Vec<u8> {
|
||||
let mut xml = XMLBuilder::new()
|
||||
.version(XMLVersion::XML1_1)
|
||||
.encoding("UTF-8".into())
|
||||
@@ -90,35 +130,24 @@ pub fn route_call(did: String) -> Vec<u8> {
|
||||
doc.add_attribute("type", "xml/freeswitch-httapi");
|
||||
|
||||
let params = XMLElement::new("params");
|
||||
|
||||
let mut work = match d.target_type {
|
||||
DidTargetType::Url => {
|
||||
url(d)
|
||||
},
|
||||
DidTargetType::Moh => {
|
||||
moh(d)
|
||||
},
|
||||
DidTargetType::ExternalNumber => {
|
||||
external_number(d)
|
||||
},
|
||||
DidTargetType::NoService => {
|
||||
no_service(d)
|
||||
},
|
||||
DidTargetType::NightMode => {
|
||||
night_mode(d)
|
||||
},
|
||||
DidTargetType::CustomMessage => {
|
||||
custom_message(d)
|
||||
}
|
||||
};
|
||||
let mut work = build_work_element(&did, &caller_ipaddr);
|
||||
|
||||
let mut hangup = XMLElement::new("execute");
|
||||
hangup.add_attribute("application", "hangup");
|
||||
work.add_child(hangup).unwrap();
|
||||
|
||||
doc.add_child(params).unwrap();
|
||||
if did_active == true {
|
||||
doc.add_child(work).unwrap();
|
||||
|
||||
let d = db::get_did_by(&did);
|
||||
match d {
|
||||
Ok(d) => {
|
||||
if d.active == true {
|
||||
doc.add_child(work).unwrap();
|
||||
}
|
||||
},
|
||||
Err(_) => {
|
||||
doc.add_child(work).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
xml.set_root_element(doc);
|
||||
|
||||
Reference in New Issue
Block a user