我目前正在尝试通过 SipSorcery 在我的 Windows 电脑上使用小型 WPF 应用程序进行呼叫。我正在使用 .net 6 和最新版本的 SipSorcery 包。在用户代理注册期间,我没有收到任何错误,并且看到成功响应。我认为这部分没问题。但当我打电话时我就明白了
403 禁止
响应错误。我不知道是什么原因造成的。但我可以在注册和邀请期间看到用户代理正在使用不同的端口。我开始认为这可能是个问题。我尝试通过向当前 SipTransport 对象添加新通道来为注册和邀请设置相同的端口,但它不起作用。我设置什么并不重要,因为端口号看起来像 SipSorcery 每次都会分配不同的端口。
我的注册请求:
我的邀请请求:
这就是我打电话的方式:
public async Task MakeCall()
{
// ...
var sipTransport = new SIPTransport();
sipTransport.PreferIPv6NameResolution = preferIPv6;
//sipTransport.AddSIPChannel(new List<SIPChannel> { new SIPTCPChannel(IPAddress.Any, 47063) });
sipTransport.CreateChannel(SIPProtocolsEnum.udp,AddressFamily.Unknown,47063);
sipTransport.EnableTraceLogs();
SIPURI callUri = SIPURI.ParseSIPURI(DEFAULT_DESTINATION_SIP_URI);
var audioSession = new WindowsAudioEndPoint(new AudioEncoder());
audioSession.RestrictFormats(x => x.Codec == AudioCodecsEnum.PCMA || x.Codec == AudioCodecsEnum.PCMU);
var rtpSession = new VoIPMediaSession(audioSession.ToMediaEndPoints());
var offerSDP = rtpSession.CreateOffer(preferIPv6 ? IPAddress.IPv6Any : IPAddress.Any);
var uac = new SIPClientUserAgent(sipTransport);
// Codes for trying and failing ... etc
SIPCallDescriptor callDescriptor = new SIPCallDescriptor(
username: DEFAULT_USERNAME,
password: DEFAULT_PASSWORD,
uri: callUri.ToString(),
from: $"sip:{DEFAULT_USERNAME}@{DEFAULT_SERVER}",
to: DEFAULT_DESTINATION_SIP_URI,
routeSet: null,
customHeaders: new List<string> {
"Allow:INVITE,ACK,CANCEL,OPTIONS,BYE,REFER,SUBSCRIBE,NOTIFY,INFO,PUBLISH,MESSAGE"
,"User-Agent:SIP.js/0.14.6"
},
authUsername: null,
callDirection: SIPCallDirection.Out,
contentType: SDP.SDP_MIME_CONTENTTYPE,
content: offerSDP.ToString(),
mangleIPAddress: null);
uac.Call(callDescriptor, null);
// ...
}
这是注册:
public void RegisterSipUser()
{
SIPTransport.PreferIPv6NameResolution = true;
SIPTransport.EnableTraceLogs();
Log = AddFileLogger(LogEventLevel.Verbose);
SIPURI sIPURI = new SIPURI(DEFAULT_USERNAME, HOST, null, SIPSchemesEnum.sip, SIPProtocolsEnum.udp);
SIPEndPoint sIPEndPoint = new SIPEndPoint(sIPURI);
_userAgent = new SIPRegistrationUserAgent(SIPTransport, sIPEndPoint, sIPURI, DEFAULT_USERNAME, DEFAULT_PASSWORD, "xxx.net", HOST, sIPURI, DEFAULT_EXPIRY,null);
_userAgent.UserAgent = "SIP.js/0.14.6";
// Event handlers for the different stages of the registration.
_userAgent.RegistrationFailed += (uri, err) => Log.LogError($"{uri}: {err}");
_userAgent.RegistrationTemporaryFailure += (uri, msg) => Log.LogError($"{uri}: {msg}");
_userAgent.RegistrationRemoved += (uri) => Log.LogWarning($"{uri} registration failed.");
_userAgent.RegistrationSuccessful += (uri) => Log.LogInformation($"{uri} registration succeeded.");
_userAgent.Start();
}
两个问题:
也许您正在使用 SIPTransport 类的 2 个不同实例?两种情况下的 SIPTransport 应该相同。