Ozeki VoIP not receiving audio - c#

I have been working on a Softphone project in c# and have been using Ozeki VoIP SDK.
So far I have got the softphone successfully registering and making outbound calls. However, I can not hear the called party but they can hear me. (Me being the softphone and called party being a Cisco SPA504G Phone)
2-Way audio is fine when using other applications (Such as X-Lite)
The SIP Trace shows I am sending but not receiving any RTP packages, is this something I have done wrong in my code (See below) or an issue on the PBX side. (Thirdlane PBX)
void CreateCall()
{
string numberToDial = txtNum.Text;
logOutput("Call " + numberToDial);
txtLog.ScrollToCaret();
call = softphone.CreateCallObject(phoneLine, numberToDial);
call.CallStateChanged += call_CallStateChanged;
call.Start();
}
private void SetupDevices()
{
connector.Connect(microphone, mediaSender);
connector.Connect(mediaReceiver, speaker);
mediaSender.AttachToCall(call);
mediaReceiver.AttachToCall(call);
microphone.Start();
speaker.Start();
}
void call_CallStateChanged(object sender, CallStateChangedArgs e)
{
if (e.State == CallState.Answered)
{
WireUpCallEvents();
}
if (e.State == CallState.Completed)
{
WireDownCallEvents();
}
logOutput("Call state: " + e.State);
}
private void WireUpCallEvents()
{
call.CallStateChanged += (call_CallStateChanged);
SetupDevices();
}
private void WireDownCallEvents()
{
call.CallStateChanged -= (call_CallStateChanged);
}

After trying another extension on another PBX I found that the issue was caused by the additional setting "nat" not being set. Once I set this with the value "yes" I was able to get 2-way audio on both parties.
This was a Thridlane PBX so the setting was in "Selected Tenants PBX" => "Extensions and Contacts" => "User Extensions" => (The extension number I was using) => Phone.

Related

Discord.net and TwitchLib C# Communication

I am stuck on a personal project to create a question bot for a twitch channel I mod for. The idea is to take questions in channel with the prefix [q] followed by the question. It then posts the question into #questions in discord. I have both sides of the bot working in their own right, however, I cannot figure out how to actually send a message to discord from that point. Here is an example of what I have.
Twitch receiving a messaging:
TwitchClient tclient;
DiscordClient dclient;
CommandService commands;
private void Client_OnMessageReceived(object sender, OnMessageReceivedArgs e)
{
if (e.ChatMessage.Message.StartsWith("[q]", StringComparison.InvariantCultureIgnoreCase))
{
// Do stuff here
}
} else if(e.ChatMessage.Message.StartsWith("!uptime", StringComparison.InvariantCultureIgnoreCase))
{
tclient.SendMessage(GetUptime()?.ToString() ?? "Offline");
} else if(e.ChatMessage.Message.StartsWith("[test]", StringComparison.InvariantCultureIgnoreCase))
{
tclient.SendMessage("Received");
}
}
And on the discord side I can send a message directly to them via:
public void dMessage(object sender, MessageEventArgs e)
{
//TODO: Add !clearall to clear a channel
//TODO: Add !start and !stop
if (e.Message.RawText.StartsWith("test"))
{
e.Channel.SendMessage(e.User.Mention + "Test confirmed");
}
else if (e.Message.RawText.StartsWith("test2"))
{
e.User.SendMessage("Test 2 confirmed");
}
}
Or I can:
commands.CreateCommand("test").Do(async (e) =>
{
await e.Channel.SendMessage("test 1 confirmed");
});
I am using TwitchLib by swiftyspiffy 1.4.9 nuget.org/packages/TwitchLib/1.4.9 and Discord.Net 0.9.6 w/ Discord.Net.Commands 0.9.6
But the scopes of the two sides seem to be completely independant and I cannot figure out how to get them to communicate. I even put them both into one large file for testing purposes. I seem to not grasp something important. I apologize if this is covered somewhere, I couldn't find anything like my problem.

sending email in xamarin forms

I'm trying to send an email in my xamarin forms project, I have tried both in the iPhone simulator and on an iPhone device. When I push the send email button on the iPhone, nothing happens, not even a debug error. I have also made sure i am logged in with my email on the device.
I have used serviceDependency and followed the setup at this link:
https://developer.xamarin.com/recipes/ios/shared_resources/email/send_an_email/
my interface:
public interface InterfaceEmail
{
void sendEmail();
}
iOS implementation:
[assembly: Xamarin.Forms.Dependency(typeof(SendEmail))]
namespace myProject.iOS
{
public partial class SendEmail : InterfaceEmail
{
MFMailComposeViewController mailController;
public SendEmail() {}
public void sendEmail()
{
if (MFMailComposeViewController.CanSendMail)
{
mailController = new MFMailComposeViewController();
mailController.SetToRecipients (new string[] {"my#email.com"});
mailController.SetSubject ("test mail");
mailController.SetMessageBody ("This is a test", false);
mailController.Finished += (object sender, MFComposeResultEventArgs e) =>
{
Console.WriteLine(e.Result.ToString());
e.Controller.DismissViewController(true, null);
};
UIApplication.SharedApplication.KeyWindow.RootViewController.PresentViewController(mailController, true, null);
}}}}
Implementation in my shared code:
async void Handle_ToolbarButton(object sender, System.EventArgs e)
{
var action = await DisplayActionSheet("What do you want to do?", "Abort", null, "Send email");
if(action == "Send email")
{
DependencyService.Get<InterfaceEmail>().sendEmail();
}
}
Does anyone have an idea on what could be wrong here?
For a better way to send email without even writing platform specific code install this nuget into your solution
xam.plugin.Messaging(https://www.nuget.org/packages/Xam.Plugins.Messaging/)
Then write the code below in PCL
var email = new EmailMessageBuilder()
.To("to.plugins#xamarin.com")
.Subject("Xamarin Messaging Plugin")
.Body("Well hello there from Xam.Messaging.Plugin")
.Build();
You can also add attachments. For more details please go through https://github.com/cjlotz/Xamarin.Plugins/blob/master/Messaging/Details.md
Probably it is related to this bug:
https://bugzilla.xamarin.com/show_bug.cgi?id=58933
Just remove DisplayActionSheet.
Or if you want to use it, then there is a temporary solution in this Xamarin forum topic
Add
await Task.Delay(100);
after DisplayActionSheet
The iPhone simulator will always return false to CanSendMail as it can not send mail. On a physical device, you will need to configure at least on e mail account.
Also:
Typo in:
[assembly: Xamarin.Forms.Dependency(typeof(sendEmail))]
Should be:
[assembly: Xamarin.Forms.Dependency(typeof(SendEmail))]
Typo in:
mailController.Finnished += ~~~~~
Should be:
mailController.Finished += ~~~~~

How to programmatically pair a bluetooth device

I recently bought a Lilypad Simblee BLE Board and I'd like to pair it programmatically to my computer (using the 32feet.NET library in C#).
I'm aware the "How to programmatically pair a bluetooth device" has already been asked on StackOverflow (here for example), however for some reason, all my attempts to pair the device programmatically have failed. Indeed, I successfully paired the device with the "Manage Bluetooth devices" window in Windows 10 Settings panel (Settings > Devices > Bluetooth).
Firstly, I don't know the pairing method (either legacy or SSP) to use with my device. Windows never asked me for a PIN or something, so I guess it's SSP, but I'm unsure.
I searched on Google how to do a SSP pairing request with 32feet.NET: I found this.
However, once it discovered my device (the device discovery works properly), the pairing request instantly fails.
My code:
using InTheHand.Net.Bluetooth;
using InTheHand.Net.Sockets;
using System;
using System.Collections.Generic;
namespace HLK_Client
{
class HLKBoard
{
public event HLKBoardEventHandler HLKBoardConnectionComplete;
public delegate void HLKBoardEventHandler(object sender, HLKBoardEventArgs e);
private BluetoothClient _bluetoothClient;
private BluetoothComponent _bluetoothComponent;
private List<BluetoothDeviceInfo> _inRangeBluetoothDevices;
private BluetoothDeviceInfo _hlkBoardDevice;
private EventHandler<BluetoothWin32AuthenticationEventArgs> _bluetoothAuthenticatorHandler;
private BluetoothWin32Authentication _bluetoothAuthenticator;
public HLKBoard()
{
_bluetoothClient = new BluetoothClient();
_bluetoothComponent = new BluetoothComponent(_bluetoothClient);
_inRangeBluetoothDevices = new List<BluetoothDeviceInfo>();
_bluetoothAuthenticatorHandler = new EventHandler<BluetoothWin32AuthenticationEventArgs>(_bluetoothAutenticator_handlePairingRequest);
_bluetoothAuthenticator = new BluetoothWin32Authentication(_bluetoothAuthenticatorHandler);
_bluetoothComponent.DiscoverDevicesProgress += _bluetoothComponent_DiscoverDevicesProgress;
_bluetoothComponent.DiscoverDevicesComplete += _bluetoothComponent_DiscoverDevicesComplete;
}
public void ConnectAsync()
{
_inRangeBluetoothDevices.Clear();
_hlkBoardDevice = null;
_bluetoothComponent.DiscoverDevicesAsync(255, true, true, true, false, null);
}
private void PairWithBoard()
{
Console.WriteLine("Pairing...");
bool pairResult = BluetoothSecurity.PairRequest(_hlkBoardDevice.DeviceAddress, null);
if (pairResult)
{
Console.WriteLine("Success");
}
else
{
Console.WriteLine("Fail"); // Instantly fails
}
}
private void _bluetoothComponent_DiscoverDevicesProgress(object sender, DiscoverDevicesEventArgs e)
{
_inRangeBluetoothDevices.AddRange(e.Devices);
}
private void _bluetoothComponent_DiscoverDevicesComplete(object sender, DiscoverDevicesEventArgs e)
{
for (int i = 0; i < _inRangeBluetoothDevices.Count; ++i)
{
if (_inRangeBluetoothDevices[i].DeviceName == "HLK")
{
_hlkBoardDevice = _inRangeBluetoothDevices[i];
PairWithBoard();
return;
}
}
HLKBoardConnectionComplete(this, new HLKBoardEventArgs(false, "Didn't found any \"HLK\" discoverable device"));
}
private void _bluetoothAutenticator_handlePairingRequest(object sender, BluetoothWin32AuthenticationEventArgs e)
{
e.Confirm = true; // Never reach this line
}
}
}
Why does the pairing request fail?
The answer to the question you linked has a plausible suggestion... did you read it?
Also you should look at this question as well.
32feet library is built around legacy pairing, so that you either need to know the pin of the device you are connecting to, or you supply it with a null to get a popup window to enter a pin.
It also says that the windows function used by 32feet is deprecated in newer versions of windows. If that's true, the reason it's failing instantly is because you've passed a null pin in your pairing request and for it to proceed windows needs to show a dialog which no longer exists.
What happens if you try to connect with the pin "0000" or "1234" ?
I'm looking at the source code of WindowsBluetoothSecurity.cs in 32feet.net and I see if a pairing request fails, it logs the error code to Debug.WriteLine, any chance you could post that error code here?
One good work around to this problem might be to import BluetoothAuthenticateDeviceEx and use that manually to complete the pairing request. If you don't want to do this manually, it looks like in the latest version of the 32feet source, there is actually a SSP pairing method that utilises this method but it's not public and it's not used anywhere so you'll need to access it via reflection:
typeof(BluetoothSecurity)
.GetMethod("PairRequest", BindingFlags.Static | BindingFlags.NonPublic)
.Invoke(null, new object[] { _hlkBoardDevice.DeviceAddress, BluetoothAuthenticationRequirements.MITMProtectionNotRequired });

Skype bot (translation from VB) not working

I was following a tutorial on youtube on how to create a simple Skype bot. It was written in VB and with my limited knowledge I did my best to recreate it in C#
I stumbled upon "handles" which I can only assume is related to the eventhandler in C#
This is the code I've got so far but when I message myself from another skype account it doesn't respond. I've made sure to accept the little popup on skype that allows 3rd party software.
public partial class Form1 : Form
{
Skype oSkype = new Skype();
string trigger = "!";
public Form1()
{
InitializeComponent();
oSkype.Attach(7, false);
oSkype.MessageStatus += new _ISkypeEvents_MessageStatusEventHandler(oSkype_MessageStatus);
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void oSkype_MessageStatus(ChatMessage pMessage, TChatMessageStatus Status)
{
if (Status == TChatMessageStatus.cmsReceived || Status == TChatMessageStatus.cmsSent)
{
string msg = pMessage.Body;
Chat c = pMessage.Chat;
if (msg.StartsWith(trigger))
{
listBox1.Items.Add(DateTime.Now.ToLongTimeString() + ": " + pMessage.Sender.Handle + " sent you a message");
msg = msg.Remove(0, 1).ToLower();
if (msg == "test")
{
c.SendMessage("Test");
}
else
{
c.SendMessage("Unrecognizable command.");
}
}
}
}
}
The code from the tutorial that I was following had this instead:
oSkype_MessageStatus(pMessage as ChatMessage, Status as TChatMessageStatus) Handles oSkype.MessageStatus
The closest to what I could come to implement this in c# was to add the void to the eventhandler in public Form1() which you can see in my code.
Thanks in advance!
Skype4Com's chat functions are not supported in the newer Skype versions. They were deprecated somewhere in-between 2013-2014.
From Skype's blog post Feature evolution and support for the Skype Desktop API:
Iā€™m happy to share that we will be extending support for two of the most widely used features ā€“ call recording and compatibility with hardware devices ā€“ until we determine alternative options or retire the current solution. Although chat via third party applications, will cease to work as previously communicated.
It has been a while since I have worked with COM Skype bots, but your code seems to be fine.
Nevertheless, I would suggest you to move to a modern approach on bots. Please check out the new Microsoft Bot Framework

Windows Phone Offline routing

I am trying to made windows phone application with offline routing. I have found that It is possible by using Bing API.
I have registered and got the key, but I can't find, how can I use the key.
I am using following code:
private async void Button_Click(object sender, RoutedEventArgs e)
{
RouteQuery query = new RouteQuery();
List<GeoCoordinate> wayPoints = new List<GeoCoordinate>();
wayPoints.Add(new GeoCoordinate(47.23449, -121.172447));
wayPoints.Add(new GeoCoordinate(47.062638, -120.691795));
query.Waypoints = wayPoints;
query.QueryCompleted += geoQ_QueryCompleted;
query.QueryAsync();
}
private void geoQ_QueryCompleted(object sender, QueryCompletedEventArgs<Route> e)
{
try
{
Route myRoute = e.Result;
MessageBox.Show("Completed");
}
catch (TargetInvocationException)
{
/// Unauthorized access exception 0x8004231C
Thread.Sleep(1000); // waiting for completing the query
geoQ_QueryCompleted(sender, e);
}
}
But I am getting Unauthorized access exception 0x8004231C.
I would like to ask you, how can I fix it?
You don't need the key to show offline map. If you have map downloaded on your device, then offline routing should work. You can see the sample to get more details.
Following is the quote from msdn sample,
However, mapping services also work without Internet connectivity when maps are downloaded for offline use.

Categories