提交 6f661d9b authored 作者: Mitch Capper's avatar Mitch Capper

Added EventSocket config generation so you can control the event socket port…

Added EventSocket config generation so you can control the event socket port from within FSClient.  Generalized some standard config generation items. Ensure the freeswitch.xml file exists or else core will crash. Warn is trying to reload portaudio settings during a call.
上级 1a03d507
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading; using System.Threading;
using System.Windows; using System.Windows;
...@@ -12,8 +12,8 @@ using Timer = System.Timers.Timer; ...@@ -12,8 +12,8 @@ using Timer = System.Timers.Timer;
namespace FSClient { namespace FSClient {
class Broker : IDisposable { class Broker : IDisposable {
private Broker() { private Broker() {
_instance = this; _instance = this;
upgrade_settings(); upgrade_settings();
Utils.PluginLog("", "");//clear file Utils.PluginLog("", "");//clear file
headset_plugin_manager = new HeadsetPluginManager(); headset_plugin_manager = new HeadsetPluginManager();
...@@ -27,27 +27,31 @@ namespace FSClient { ...@@ -27,27 +27,31 @@ namespace FSClient {
init_us(); init_us();
} }
public bool fully_loaded; public bool fully_loaded;
private void upgrade_settings(){ private void upgrade_settings(){
try { try {
if (Properties.Settings.Default.SettingsUpgrade) { if (Properties.Settings.Default.SettingsUpgrade) {
Properties.Settings.Default.Upgrade(); Properties.Settings.Default.Upgrade();
Properties.Settings.Default.SettingsUpgrade = false; Properties.Settings.Default.SettingsUpgrade = false;
Properties.Settings.Default.Save(); Properties.Settings.Default.Save();
} }
} }
catch { catch {
Properties.Settings.Default.SettingsUpgrade = false; Properties.Settings.Default.SettingsUpgrade = false;
Properties.Settings.Default.Save(); Properties.Settings.Default.Save();
} }
} }
private void init_us() { private void init_us() {
if (is_inited) if (is_inited)
return; return;
is_inited = true; is_inited = true;
try { try {
if (! System.IO.File.Exists("conf/freeswitch.xml")){
MessageBox.Show("conf/freeswitch.xml is not found, without it we must quit.", "Missing Base Configuration File", MessageBoxButton.OK, MessageBoxImage.Error);
Environment.Exit(-1);
}
if (System.IO.File.Exists("log/freeswitch.log")) { if (System.IO.File.Exists("log/freeswitch.log")) {
try { try {
System.IO.File.WriteAllText("log/freeswitch.log", ""); System.IO.File.WriteAllText("log/freeswitch.log", "");
...@@ -69,7 +73,12 @@ namespace FSClient { ...@@ -69,7 +73,12 @@ namespace FSClient {
if (Properties.Settings.Default.Sofia != null) if (Properties.Settings.Default.Sofia != null)
sofia = Properties.Settings.Default.Sofia.GetSofia(); sofia = Properties.Settings.Default.Sofia.GetSofia();
else else
sofia = new Sofia(); sofia = new Sofia();
if (Properties.Settings.Default.EventSocket != null)
event_socket = Properties.Settings.Default.EventSocket.GetEventSocket();
else
event_socket = new EventSocket();
} catch (Exception e) { } catch (Exception e) {
MessageBoxResult res = MessageBox.Show( MessageBoxResult res = MessageBox.Show(
...@@ -228,6 +237,10 @@ namespace FSClient { ...@@ -228,6 +237,10 @@ namespace FSClient {
} }
public void reload_audio_devices(bool and_settings, bool no_save) { public void reload_audio_devices(bool and_settings, bool no_save) {
if(active_calls > 0){
MessageBox.Show("Unable to reload audio devices while calls are active");
return;
}
if (and_settings && !no_save) if (and_settings && !no_save)
SaveAudioSettings(); SaveAudioSettings();
audio_devices = PortAudio.get_devices(true); audio_devices = PortAudio.get_devices(true);
...@@ -326,7 +339,8 @@ namespace FSClient { ...@@ -326,7 +339,8 @@ namespace FSClient {
Properties.Settings.Default.ClearDTMFS = ClearDTMFS; Properties.Settings.Default.ClearDTMFS = ClearDTMFS;
Properties.Settings.Default.UseNumberOnlyInput = UseNumberOnlyInput; Properties.Settings.Default.UseNumberOnlyInput = UseNumberOnlyInput;
Properties.Settings.Default.Sofia = new SettingsSofia(sofia); Properties.Settings.Default.Sofia = new SettingsSofia(sofia);
Properties.Settings.Default.EventSocket = new SettingsEventSocket(event_socket);
Properties.Settings.Default.Save(); Properties.Settings.Default.Save();
} catch (Exception e) {//if there is an error doing saving lets skip saving any settings to avoid overriding something else } catch (Exception e) {//if there is an error doing saving lets skip saving any settings to avoid overriding something else
MessageBox.Show("Error saving settings out: " + e.Message + "\n" + e.StackTrace); MessageBox.Show("Error saving settings out: " + e.Message + "\n" + e.StackTrace);
...@@ -564,13 +578,17 @@ namespace FSClient { ...@@ -564,13 +578,17 @@ namespace FSClient {
private static Broker _instance; private static Broker _instance;
public static Broker get_instance() { public static Broker get_instance() {
return _instance ?? (_instance = new Broker()); return _instance ?? (_instance = new Broker());
} }
ContactPluginManager contact_plugin_manager; private ContactPluginManager contact_plugin_manager;
HeadsetPluginManager headset_plugin_manager; private HeadsetPluginManager headset_plugin_manager;
Sofia sofia; private Sofia sofia;
private EventSocket event_socket;
public void edit_sofia() { public void edit_sofia() {
sofia.edit(); sofia.edit();
}
public void edit_event_socket() {
event_socket.edit();
} }
public void reload_sofia(Sofia.RELOAD_CONFIG_MODE mode) { public void reload_sofia(Sofia.RELOAD_CONFIG_MODE mode) {
sofia.reload_config(mode); sofia.reload_config(mode);
...@@ -597,25 +615,36 @@ namespace FSClient { ...@@ -597,25 +615,36 @@ namespace FSClient {
NewEvent(this, evt); NewEvent(this, evt);
} }
#region Config Generation #region Config Generation
XmlDocument sofia_doc;
private string get_sofia_xml() { private delegate void config_gen_del(XmlNode parent);
sofia_doc = new XmlDocument(); private string generate_xml_config(String name, String desc, config_gen_del func){
XmlNode doc = sofia_doc.CreateElement("document"); XmlDocument root_doc = new XmlDocument();
sofia_doc.AppendChild(doc); XmlNode doc = root_doc.CreateElement("document");
XmlUtils.AddNodeAttrib(doc, "type", "freeswitch/xml"); root_doc.AppendChild(doc);
XmlNode sect = XmlUtils.AddNodeNode(doc, "section"); XmlUtils.AddNodeAttrib(doc, "type", "freeswitch/xml");
XmlUtils.AddNodeAttrib(sect, "name", "configuration"); XmlNode sect = XmlUtils.AddNodeNode(doc, "section");
sofia.gen_config(sect); XmlUtils.AddNodeAttrib(sect, "name", "configuration");
//sofia_doc.Save(@"c:\temp\out.xml");
return sofia_doc.OuterXml; XmlNode config_node = XmlUtils.AddNodeNode(sect, "configuration");
} XmlUtils.AddNodeAttrib(config_node, "name", name);
private string xml_search(FreeSWITCH.SwitchXmlSearchBinding.XmlBindingArgs args) { XmlUtils.AddNodeAttrib(config_node, "description", desc);
if (args.KeyName == "name" && args.KeyValue == "sofia.conf" && args.Section == "configuration" && args.TagName == "configuration") { func(config_node);
return get_sofia_xml(); root_doc.Save(@"c:\temp\fs_" + name);
} return root_doc.OuterXml;
return null; }
private string xml_search(FreeSWITCH.SwitchXmlSearchBinding.XmlBindingArgs args) {
if (args.KeyName != "name" || args.Section != "configuration" || args.TagName != "configuration")
return null;
switch (args.KeyValue){
case "sofia.conf":
return generate_xml_config(args.KeyValue, "Sofia Endpoint", sofia.gen_config);
case "event_socket.conf":
return generate_xml_config(args.KeyValue, "Socket Client", event_socket.gen_config);
}
return null;
} }
private static IDisposable search_bind; private static IDisposable search_bind;
#endregion #endregion
......
...@@ -96,15 +96,6 @@ ...@@ -96,15 +96,6 @@
</settings> </settings>
</configuration> </configuration>
<configuration name="event_socket.conf" description="Socket Client">
<settings>
<param name="nat-map" value="false"/>
<param name="listen-ip" value="127.0.0.1"/>
<param name="listen-port" value="8022"/>
<param name="password" value="ClueCon"/>
</settings>
</configuration>
<configuration name="post_load_modules.conf" description="Modules"> <configuration name="post_load_modules.conf" description="Modules">
<modules> <modules>
</modules> </modules>
......
...@@ -101,6 +101,7 @@ ...@@ -101,6 +101,7 @@
</Compile> </Compile>
<Compile Include="Converters.cs" /> <Compile Include="Converters.cs" />
<Compile Include="DelayedFunction.cs" /> <Compile Include="DelayedFunction.cs" />
<Compile Include="EventSocket.cs" />
<Compile Include="Field.cs" /> <Compile Include="Field.cs" />
<Compile Include="FSEvent.cs" /> <Compile Include="FSEvent.cs" />
<Compile Include="GenericEditor.xaml.cs"> <Compile Include="GenericEditor.xaml.cs">
......
...@@ -54,6 +54,7 @@ ...@@ -54,6 +54,7 @@
<StackPanel Orientation="Horizontal" Grid.Column="0" Grid.ColumnSpan="2" HorizontalAlignment="Center" > <StackPanel Orientation="Horizontal" Grid.Column="0" Grid.ColumnSpan="2" HorizontalAlignment="Center" >
<Button Content="Reload Devices" Height="23" Name="btnReloadDevices" Width="100" Click="btnReloadDevices_Click" /> <Button Content="Reload Devices" Height="23" Name="btnReloadDevices" Width="100" Click="btnReloadDevices_Click" />
<Button Content="Sofia Settings" Height="23" Name="btnSofiaSettings" Width="100" Margin="10,0,0,0" Click="btnSofiaSettings_Click" /> <Button Content="Sofia Settings" Height="23" Name="btnSofiaSettings" Width="100" Margin="10,0,0,0" Click="btnSofiaSettings_Click" />
<Button Content="Event Socket Settings" Height="23" Name="btnEventSocketSettings" Width="125" Margin="10,0,0,0" Click="btnEventSocketSettings_Click" />
</StackPanel> </StackPanel>
</Grid> </Grid>
......
using System.Linq; using System.Linq;
using System.Windows; using System.Windows;
namespace FSClient { namespace FSClient {
/// <summary> /// <summary>
/// Interaction logic for Options.xaml /// Interaction logic for Options.xaml
/// </summary> /// </summary>
public partial class Options : Window { public partial class Options : Window {
public Options() { public Options() {
InitializeComponent(); InitializeComponent();
} }
private Broker broker = Broker.get_instance(); private Broker broker = Broker.get_instance();
private void Window_Loaded(object sender, RoutedEventArgs e) { private void Window_Loaded(object sender, RoutedEventArgs e) {
load_devices(true); load_devices(true);
} }
private void load_devices(bool from_settings) { private void load_devices(bool from_settings) {
PortAudio.AudioDevice[] devices = broker.audio_devices; PortAudio.AudioDevice[] devices = broker.audio_devices;
comboSpeakerInput.ItemsSource = comboHeadsetInput.ItemsSource = from d in devices where d.inputs > 0 select d; comboSpeakerInput.ItemsSource = comboHeadsetInput.ItemsSource = from d in devices where d.inputs > 0 select d;
comboRingDevice.ItemsSource = comboSpeakerOutput.ItemsSource = comboHeadsetOutput.ItemsSource = from d in devices where d.outputs > 0 select d; comboRingDevice.ItemsSource = comboSpeakerOutput.ItemsSource = comboHeadsetOutput.ItemsSource = from d in devices where d.outputs > 0 select d;
string old_selected_item = comboHeadsetDevice.SelectedItem as string; string old_selected_item = comboHeadsetDevice.SelectedItem as string;
comboHeadsetDevice.Items.Clear(); comboHeadsetDevice.Items.Clear();
comboHeadsetDevice.Items.Add("None"); comboHeadsetDevice.Items.Add("None");
foreach (string headset in broker.AvailableHeadsets()) foreach (string headset in broker.AvailableHeadsets())
comboHeadsetDevice.Items.Add(headset); comboHeadsetDevice.Items.Add(headset);
comboHeadsetDevice.SelectedItem = old_selected_item; comboHeadsetDevice.SelectedItem = old_selected_item;
if (from_settings) { if (from_settings) {
comboHeadsetInput.SelectedItem = broker.HeadsetInDev; comboHeadsetInput.SelectedItem = broker.HeadsetInDev;
comboHeadsetOutput.SelectedItem = broker.HeadsetOutDev; comboHeadsetOutput.SelectedItem = broker.HeadsetOutDev;
comboSpeakerInput.SelectedItem = broker.SpeakerInDev; comboSpeakerInput.SelectedItem = broker.SpeakerInDev;
comboSpeakerOutput.SelectedItem = broker.SpeakerOutDev; comboSpeakerOutput.SelectedItem = broker.SpeakerOutDev;
comboRingDevice.SelectedItem = broker.RingDev; comboRingDevice.SelectedItem = broker.RingDev;
chkIncomingBalloons.IsChecked = broker.IncomingBalloons; chkIncomingBalloons.IsChecked = broker.IncomingBalloons;
chkIncomingFront.IsChecked = broker.IncomingTopMost; chkIncomingFront.IsChecked = broker.IncomingTopMost;
chkClearDTMFS.IsChecked = broker.ClearDTMFS; chkClearDTMFS.IsChecked = broker.ClearDTMFS;
chkUseNumbers.IsChecked = broker.UseNumberOnlyInput; chkUseNumbers.IsChecked = broker.UseNumberOnlyInput;
comboHeadsetDevice.SelectedItem = broker.ActiveHeadset(); comboHeadsetDevice.SelectedItem = broker.ActiveHeadset();
if (comboHeadsetDevice.SelectedIndex == -1) if (comboHeadsetDevice.SelectedIndex == -1)
comboHeadsetDevice.SelectedIndex = 0; comboHeadsetDevice.SelectedIndex = 0;
} }
} }
private void SaveSettings() { private void SaveSettings() {
PortAudio.AudioDevice indev = comboHeadsetInput.SelectedItem as PortAudio.AudioDevice; PortAudio.AudioDevice indev = comboHeadsetInput.SelectedItem as PortAudio.AudioDevice;
PortAudio.AudioDevice outdev = comboHeadsetOutput.SelectedItem as PortAudio.AudioDevice; PortAudio.AudioDevice outdev = comboHeadsetOutput.SelectedItem as PortAudio.AudioDevice;
broker.SetHeadsetDevs(indev == null ? "" : indev.name, outdev == null ? "" : outdev.name); broker.SetHeadsetDevs(indev == null ? "" : indev.name, outdev == null ? "" : outdev.name);
indev = comboSpeakerInput.SelectedItem as PortAudio.AudioDevice; indev = comboSpeakerInput.SelectedItem as PortAudio.AudioDevice;
outdev = comboSpeakerOutput.SelectedItem as PortAudio.AudioDevice; outdev = comboSpeakerOutput.SelectedItem as PortAudio.AudioDevice;
broker.SetSpeakerDevs(indev == null ? "" : indev.name, outdev == null ? "" : outdev.name); broker.SetSpeakerDevs(indev == null ? "" : indev.name, outdev == null ? "" : outdev.name);
outdev = comboRingDevice.SelectedItem as PortAudio.AudioDevice; outdev = comboRingDevice.SelectedItem as PortAudio.AudioDevice;
broker.SetRingDev(outdev == null ? "" : outdev.name); broker.SetRingDev(outdev == null ? "" : outdev.name);
broker.IncomingBalloons = chkIncomingBalloons.IsChecked == true; broker.IncomingBalloons = chkIncomingBalloons.IsChecked == true;
broker.IncomingTopMost = chkIncomingFront.IsChecked == true; broker.IncomingTopMost = chkIncomingFront.IsChecked == true;
broker.ClearDTMFS = chkClearDTMFS.IsChecked == true; broker.ClearDTMFS = chkClearDTMFS.IsChecked == true;
broker.UseNumberOnlyInput = chkUseNumbers.IsChecked == true; broker.UseNumberOnlyInput = chkUseNumbers.IsChecked == true;
broker.SetActiveHeadset(comboHeadsetDevice.SelectedItem as string); broker.SetActiveHeadset(comboHeadsetDevice.SelectedItem as string);
broker.SaveSettings(); broker.SaveSettings();
} }
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) { private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) {
} }
private void btnSave_Click(object sender, RoutedEventArgs e) { private void btnSave_Click(object sender, RoutedEventArgs e) {
SaveSettings(); SaveSettings();
DialogResult = true; DialogResult = true;
Close(); Close();
} }
private void btnCancel_Click(object sender, RoutedEventArgs e) { private void btnCancel_Click(object sender, RoutedEventArgs e) {
DialogResult = false; DialogResult = false;
Close(); Close();
} }
private void btnReloadDevices_Click(object sender, RoutedEventArgs e) { private void btnReloadDevices_Click(object sender, RoutedEventArgs e) {
broker.reload_audio_devices(false, false); broker.reload_audio_devices(false, false);
load_devices(false); load_devices(false);
} }
private void btnSofiaSettings_Click(object sender, RoutedEventArgs e) { private void btnSofiaSettings_Click(object sender, RoutedEventArgs e) {
broker.edit_sofia(); broker.edit_sofia();
} }
}
} private void btnEventSocketSettings_Click(object sender, RoutedEventArgs e){
broker.edit_event_socket();
}
}
}
...@@ -176,5 +176,16 @@ namespace FSClient.Properties { ...@@ -176,5 +176,16 @@ namespace FSClient.Properties {
this["SettingsUpgrade"] = value; this["SettingsUpgrade"] = value;
} }
} }
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
public global::FSClient.SettingsEventSocket EventSocket {
get {
return ((global::FSClient.SettingsEventSocket)(this["EventSocket"]));
}
set {
this["EventSocket"] = value;
}
}
} }
} }
\ No newline at end of file
...@@ -41,5 +41,8 @@ ...@@ -41,5 +41,8 @@
<Setting Name="SettingsUpgrade" Type="System.Boolean" Scope="User"> <Setting Name="SettingsUpgrade" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">True</Value> <Value Profile="(Default)">True</Value>
</Setting> </Setting>
<Setting Name="EventSocket" Type="FSClient.SettingsEventSocket" Scope="User">
<Value Profile="(Default)" />
</Setting>
</Settings> </Settings>
</SettingsFile> </SettingsFile>
\ No newline at end of file
...@@ -71,12 +71,8 @@ namespace FSClient { ...@@ -71,12 +71,8 @@ namespace FSClient {
}; };
public FieldValue[] values = FieldValue.FieldValues(fields); public FieldValue[] values = FieldValue.FieldValues(fields);
public void gen_config(XmlNode parent) { public void gen_config(XmlNode config_node) {
XmlNode config_node = XmlUtils.AddNodeNode(parent, "configuration");
XmlUtils.AddNodeAttrib(config_node, "name", "sofia.conf");
XmlUtils.AddNodeAttrib(config_node, "description", "Sofia Endpoint");
XmlNode global_settings = XmlUtils.AddNodeNode(config_node, "global_settings"); XmlNode global_settings = XmlUtils.AddNodeNode(config_node, "global_settings");
Utils.add_xml_param(global_settings, "auto-restart", "true"); Utils.add_xml_param(global_settings, "auto-restart", "true");
Utils.add_xml_param(global_settings, "debug-presence", "0"); Utils.add_xml_param(global_settings, "debug-presence", "0");
...@@ -115,8 +111,7 @@ namespace FSClient { ...@@ -115,8 +111,7 @@ namespace FSClient {
DelayedFunction.DelayedCall("SofiaProfileCheck", sofia_profile_check, 100); DelayedFunction.DelayedCall("SofiaProfileCheck", sofia_profile_check, 100);
break; break;
case RELOAD_CONFIG_MODE.MODULE: case RELOAD_CONFIG_MODE.MODULE:
Utils.api_exec("unload", "mod_sofia"); Utils.api_exec("reload", "mod_sofia");
Utils.api_exec("load", "mod_sofia");
DelayedFunction.DelayedCall("SofiaProfileCheck", sofia_profile_check, 500); DelayedFunction.DelayedCall("SofiaProfileCheck", sofia_profile_check, 500);
break; break;
} }
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论