/// <summary> /// Notify application on incoming call. /// </summary> ///<param name="sender">The current sender.</param> /// <param name="e">The event parameter.</param> private void _voipManager_OnIncomingCall(object sender, OnIncomingCallParam e) { // Is valid call. if (e.CallId >= 0) { // Create a new call. Call call = _voipManager.CreateCall(e.CallId); Param.CallParam callInfo = new Param.CallParam(call, _voipManager.MediaManager, _recordFilename); // Create the call settings. CallSetting setting = new CallSetting(true); CallOpParam parm = new CallOpParam(true); setting.AudioCount = 1; parm.Setting = setting; // Continue ringing. parm.Code = StatusCode.SC_RINGING; call.Answer(parm); // Send a notification to the call. Param.OnIncomingCallParam param = new Param.OnIncomingCallParam(); param.CallID = e.CallId; param.Info = e.RxData.Info; param.SrcAddress = e.RxData.SrcAddress; param.WholeMsg = e.RxData.WholeMsg; param.Call = callInfo; param.Contact = FindContact(param); // Call the event handler. OnIncomingCall?.Invoke(this, param); } }
/// <summary> /// Find the contact. /// </summary> /// <param name="param">The whole message.</param> /// <returns>The contact; else null.</returns> private Net.Sip.Contact FindContact(Param.OnIncomingCallParam param) { string from = string.Empty; string contact = string.Empty; Net.Sip.Contact uriContact = null; // Get the whole message. string[] headers = (String.IsNullOrEmpty(param.WholeMsg) ? new string[] { "" } : param.WholeMsg.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries)); foreach (string header in headers) { // Extract from. if (header.ToLower().StartsWith("from")) { // Get from. string[] fromHeader = header.Split(new char[] { ':' }); string combineFrom = String.Join(":", fromHeader.Skip(1)); fromHeader = combineFrom.Split(new char[] { ';' }); combineFrom = fromHeader[0]; from = combineFrom.Replace("<", "").Replace(">", "").Replace("sip:", "").Replace("sips:", "").Replace("\"", ""); param.From = from; } // Extract contact. if (header.ToLower().StartsWith("contact")) { // Get contact. string[] contactHeader = header.Split(new char[] { ':' }); string combineContact = String.Join(":", contactHeader.Skip(1)); contactHeader = combineContact.Split(new char[] { ';' }); combineContact = contactHeader[0]; contact = combineContact.Replace("<", "").Replace(">", "").Replace("sip:", "").Replace("sips:", "").Replace("\"", ""); param.FromContact = contact; } } try { // Find the contact. uriContact = _voipManager.FindContact(from); } catch { } // Return the contact. return(uriContact); }