提交 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.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Windows;
......@@ -12,8 +12,8 @@ using Timer = System.Timers.Timer;
namespace FSClient {
class Broker : IDisposable {
private Broker() {
_instance = this;
upgrade_settings();
_instance = this;
upgrade_settings();
Utils.PluginLog("", "");//clear file
headset_plugin_manager = new HeadsetPluginManager();
......@@ -27,27 +27,31 @@ namespace FSClient {
init_us();
}
public bool fully_loaded;
private void upgrade_settings(){
try {
if (Properties.Settings.Default.SettingsUpgrade) {
Properties.Settings.Default.Upgrade();
Properties.Settings.Default.SettingsUpgrade = false;
Properties.Settings.Default.Save();
}
}
catch {
Properties.Settings.Default.SettingsUpgrade = false;
Properties.Settings.Default.Save();
}
public bool fully_loaded;
private void upgrade_settings(){
try {
if (Properties.Settings.Default.SettingsUpgrade) {
Properties.Settings.Default.Upgrade();
Properties.Settings.Default.SettingsUpgrade = false;
Properties.Settings.Default.Save();
}
}
catch {
Properties.Settings.Default.SettingsUpgrade = false;
Properties.Settings.Default.Save();
}
}
private void init_us() {
if (is_inited)
return;
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")) {
try {
System.IO.File.WriteAllText("log/freeswitch.log", "");
......@@ -69,7 +73,12 @@ namespace FSClient {
if (Properties.Settings.Default.Sofia != null)
sofia = Properties.Settings.Default.Sofia.GetSofia();
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) {
MessageBoxResult res = MessageBox.Show(
......@@ -228,6 +237,10 @@ namespace FSClient {
}
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)
SaveAudioSettings();
audio_devices = PortAudio.get_devices(true);
......@@ -326,7 +339,8 @@ namespace FSClient {
Properties.Settings.Default.ClearDTMFS = ClearDTMFS;
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();
} 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);
......@@ -564,13 +578,17 @@ namespace FSClient {
private static Broker _instance;
public static Broker get_instance() {
return _instance ?? (_instance = new Broker());
}
ContactPluginManager contact_plugin_manager;
HeadsetPluginManager headset_plugin_manager;
Sofia sofia;
}
private ContactPluginManager contact_plugin_manager;
private HeadsetPluginManager headset_plugin_manager;
private Sofia sofia;
private EventSocket event_socket;
public void edit_sofia() {
sofia.edit();
}
public void edit_event_socket() {
event_socket.edit();
}
public void reload_sofia(Sofia.RELOAD_CONFIG_MODE mode) {
sofia.reload_config(mode);
......@@ -597,25 +615,36 @@ namespace FSClient {
NewEvent(this, evt);
}
#region Config Generation
XmlDocument sofia_doc;
private string get_sofia_xml() {
sofia_doc = new XmlDocument();
XmlNode doc = sofia_doc.CreateElement("document");
sofia_doc.AppendChild(doc);
XmlUtils.AddNodeAttrib(doc, "type", "freeswitch/xml");
XmlNode sect = XmlUtils.AddNodeNode(doc, "section");
XmlUtils.AddNodeAttrib(sect, "name", "configuration");
sofia.gen_config(sect);
//sofia_doc.Save(@"c:\temp\out.xml");
return sofia_doc.OuterXml;
}
private string xml_search(FreeSWITCH.SwitchXmlSearchBinding.XmlBindingArgs args) {
if (args.KeyName == "name" && args.KeyValue == "sofia.conf" && args.Section == "configuration" && args.TagName == "configuration") {
return get_sofia_xml();
}
return null;
#region Config Generation
private delegate void config_gen_del(XmlNode parent);
private string generate_xml_config(String name, String desc, config_gen_del func){
XmlDocument root_doc = new XmlDocument();
XmlNode doc = root_doc.CreateElement("document");
root_doc.AppendChild(doc);
XmlUtils.AddNodeAttrib(doc, "type", "freeswitch/xml");
XmlNode sect = XmlUtils.AddNodeNode(doc, "section");
XmlUtils.AddNodeAttrib(sect, "name", "configuration");
XmlNode config_node = XmlUtils.AddNodeNode(sect, "configuration");
XmlUtils.AddNodeAttrib(config_node, "name", name);
XmlUtils.AddNodeAttrib(config_node, "description", desc);
func(config_node);
root_doc.Save(@"c:\temp\fs_" + name);
return root_doc.OuterXml;
}
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;
#endregion
......
......@@ -96,15 +96,6 @@
</settings>
</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">
<modules>
</modules>
......
......@@ -101,6 +101,7 @@
</Compile>
<Compile Include="Converters.cs" />
<Compile Include="DelayedFunction.cs" />
<Compile Include="EventSocket.cs" />
<Compile Include="Field.cs" />
<Compile Include="FSEvent.cs" />
<Compile Include="GenericEditor.xaml.cs">
......
......@@ -54,6 +54,7 @@
<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="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>
</Grid>
......
using System.Linq;
using System.Windows;
namespace FSClient {
/// <summary>
/// Interaction logic for Options.xaml
/// </summary>
public partial class Options : Window {
public Options() {
InitializeComponent();
}
private Broker broker = Broker.get_instance();
private void Window_Loaded(object sender, RoutedEventArgs e) {
load_devices(true);
}
private void load_devices(bool from_settings) {
PortAudio.AudioDevice[] devices = broker.audio_devices;
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;
string old_selected_item = comboHeadsetDevice.SelectedItem as string;
comboHeadsetDevice.Items.Clear();
comboHeadsetDevice.Items.Add("None");
foreach (string headset in broker.AvailableHeadsets())
comboHeadsetDevice.Items.Add(headset);
comboHeadsetDevice.SelectedItem = old_selected_item;
if (from_settings) {
comboHeadsetInput.SelectedItem = broker.HeadsetInDev;
comboHeadsetOutput.SelectedItem = broker.HeadsetOutDev;
comboSpeakerInput.SelectedItem = broker.SpeakerInDev;
comboSpeakerOutput.SelectedItem = broker.SpeakerOutDev;
comboRingDevice.SelectedItem = broker.RingDev;
chkIncomingBalloons.IsChecked = broker.IncomingBalloons;
chkIncomingFront.IsChecked = broker.IncomingTopMost;
chkClearDTMFS.IsChecked = broker.ClearDTMFS;
chkUseNumbers.IsChecked = broker.UseNumberOnlyInput;
comboHeadsetDevice.SelectedItem = broker.ActiveHeadset();
if (comboHeadsetDevice.SelectedIndex == -1)
comboHeadsetDevice.SelectedIndex = 0;
}
}
private void SaveSettings() {
PortAudio.AudioDevice indev = comboHeadsetInput.SelectedItem as PortAudio.AudioDevice;
PortAudio.AudioDevice outdev = comboHeadsetOutput.SelectedItem as PortAudio.AudioDevice;
broker.SetHeadsetDevs(indev == null ? "" : indev.name, outdev == null ? "" : outdev.name);
indev = comboSpeakerInput.SelectedItem as PortAudio.AudioDevice;
outdev = comboSpeakerOutput.SelectedItem as PortAudio.AudioDevice;
broker.SetSpeakerDevs(indev == null ? "" : indev.name, outdev == null ? "" : outdev.name);
outdev = comboRingDevice.SelectedItem as PortAudio.AudioDevice;
broker.SetRingDev(outdev == null ? "" : outdev.name);
broker.IncomingBalloons = chkIncomingBalloons.IsChecked == true;
broker.IncomingTopMost = chkIncomingFront.IsChecked == true;
broker.ClearDTMFS = chkClearDTMFS.IsChecked == true;
broker.UseNumberOnlyInput = chkUseNumbers.IsChecked == true;
broker.SetActiveHeadset(comboHeadsetDevice.SelectedItem as string);
broker.SaveSettings();
}
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) {
}
private void btnSave_Click(object sender, RoutedEventArgs e) {
SaveSettings();
DialogResult = true;
Close();
}
private void btnCancel_Click(object sender, RoutedEventArgs e) {
DialogResult = false;
Close();
}
private void btnReloadDevices_Click(object sender, RoutedEventArgs e) {
broker.reload_audio_devices(false, false);
load_devices(false);
}
private void btnSofiaSettings_Click(object sender, RoutedEventArgs e) {
broker.edit_sofia();
}
}
}
using System.Linq;
using System.Windows;
namespace FSClient {
/// <summary>
/// Interaction logic for Options.xaml
/// </summary>
public partial class Options : Window {
public Options() {
InitializeComponent();
}
private Broker broker = Broker.get_instance();
private void Window_Loaded(object sender, RoutedEventArgs e) {
load_devices(true);
}
private void load_devices(bool from_settings) {
PortAudio.AudioDevice[] devices = broker.audio_devices;
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;
string old_selected_item = comboHeadsetDevice.SelectedItem as string;
comboHeadsetDevice.Items.Clear();
comboHeadsetDevice.Items.Add("None");
foreach (string headset in broker.AvailableHeadsets())
comboHeadsetDevice.Items.Add(headset);
comboHeadsetDevice.SelectedItem = old_selected_item;
if (from_settings) {
comboHeadsetInput.SelectedItem = broker.HeadsetInDev;
comboHeadsetOutput.SelectedItem = broker.HeadsetOutDev;
comboSpeakerInput.SelectedItem = broker.SpeakerInDev;
comboSpeakerOutput.SelectedItem = broker.SpeakerOutDev;
comboRingDevice.SelectedItem = broker.RingDev;
chkIncomingBalloons.IsChecked = broker.IncomingBalloons;
chkIncomingFront.IsChecked = broker.IncomingTopMost;
chkClearDTMFS.IsChecked = broker.ClearDTMFS;
chkUseNumbers.IsChecked = broker.UseNumberOnlyInput;
comboHeadsetDevice.SelectedItem = broker.ActiveHeadset();
if (comboHeadsetDevice.SelectedIndex == -1)
comboHeadsetDevice.SelectedIndex = 0;
}
}
private void SaveSettings() {
PortAudio.AudioDevice indev = comboHeadsetInput.SelectedItem as PortAudio.AudioDevice;
PortAudio.AudioDevice outdev = comboHeadsetOutput.SelectedItem as PortAudio.AudioDevice;
broker.SetHeadsetDevs(indev == null ? "" : indev.name, outdev == null ? "" : outdev.name);
indev = comboSpeakerInput.SelectedItem as PortAudio.AudioDevice;
outdev = comboSpeakerOutput.SelectedItem as PortAudio.AudioDevice;
broker.SetSpeakerDevs(indev == null ? "" : indev.name, outdev == null ? "" : outdev.name);
outdev = comboRingDevice.SelectedItem as PortAudio.AudioDevice;
broker.SetRingDev(outdev == null ? "" : outdev.name);
broker.IncomingBalloons = chkIncomingBalloons.IsChecked == true;
broker.IncomingTopMost = chkIncomingFront.IsChecked == true;
broker.ClearDTMFS = chkClearDTMFS.IsChecked == true;
broker.UseNumberOnlyInput = chkUseNumbers.IsChecked == true;
broker.SetActiveHeadset(comboHeadsetDevice.SelectedItem as string);
broker.SaveSettings();
}
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) {
}
private void btnSave_Click(object sender, RoutedEventArgs e) {
SaveSettings();
DialogResult = true;
Close();
}
private void btnCancel_Click(object sender, RoutedEventArgs e) {
DialogResult = false;
Close();
}
private void btnReloadDevices_Click(object sender, RoutedEventArgs e) {
broker.reload_audio_devices(false, false);
load_devices(false);
}
private void btnSofiaSettings_Click(object sender, RoutedEventArgs e) {
broker.edit_sofia();
}
private void btnEventSocketSettings_Click(object sender, RoutedEventArgs e){
broker.edit_event_socket();
}
}
}
......@@ -176,5 +176,16 @@ namespace FSClient.Properties {
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 @@
<Setting Name="SettingsUpgrade" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">True</Value>
</Setting>
<Setting Name="EventSocket" Type="FSClient.SettingsEventSocket" Scope="User">
<Value Profile="(Default)" />
</Setting>
</Settings>
</SettingsFile>
\ No newline at end of file
......@@ -71,12 +71,8 @@ namespace FSClient {
};
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");
Utils.add_xml_param(global_settings, "auto-restart", "true");
Utils.add_xml_param(global_settings, "debug-presence", "0");
......@@ -115,8 +111,7 @@ namespace FSClient {
DelayedFunction.DelayedCall("SofiaProfileCheck", sofia_profile_check, 100);
break;
case RELOAD_CONFIG_MODE.MODULE:
Utils.api_exec("unload", "mod_sofia");
Utils.api_exec("load", "mod_sofia");
Utils.api_exec("reload", "mod_sofia");
DelayedFunction.DelayedCall("SofiaProfileCheck", sofia_profile_check, 500);
break;
}
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论