private void Channel_UnsolicitedEvent(object sender, UnsolicitedEventArgs e) { if (e.Line1 == "RING") { IncomingCall?.Invoke(this, new IncomingCallEventArgs()); } else if (e.Line1.StartsWith("VOICE CALL: BEGIN")) { CallStarted?.Invoke(this, new CallStartedEventArgs()); } else if (e.Line1.StartsWith("VOICE CALL: END")) { CallEnded?.Invoke(this, CallEndedEventArgs.CreateFromResponse(e.Line1)); } else if (e.Line1.StartsWith("MISSED_CALL: ")) { MissedCall?.Invoke(this, MissedCallEventArgs.CreateFromResponse(e.Line1)); } else if (e.Line1.StartsWith("+CMTI: ")) { SmsReceived?.Invoke(this, SmsReceivedEventArgs.CreateFromResponse(e.Line1)); } else if (e.Line1.StartsWith("+CUSD: ")) { UssdResponseReceived?.Invoke(this, UssdResponseEventArgs.CreateFromResponse(e.Line1)); } else if (e.Line1.StartsWith("+CME ERROR:")) { ErrorReceived?.Invoke(this, ErrorEventArgs.CreateFromCmeResponse(e.Line1)); } else if (e.Line1.StartsWith("+CMS ERROR:")) { ErrorReceived?.Invoke(this, ErrorEventArgs.CreateFromCmsResponse(e.Line1)); } }
public async Task <string> GetNumberDetailsAsync(string requestBody) { ValidateHostUrls(); Response responseResult; try { IncomingCall call = ParseCallParameters(requestBody); if (call == null) { _logger.LogWarning($"Returning Twilio Disconnect Call response. Incoming call is null."); responseResult = CallResponseService.DisconnectCallResponse(); } else { responseResult = await ProcessNumberRoutingAsync(call); } var resultJson = JsonConvert.SerializeObject(responseResult); _logger.LogInformation($"GetNumberDetailsAsync Success"); } catch (Exception ex) { _logger.LogError(ex, $"GetNumberDetailsAsync Exception. Details: {ex.Message}"); responseResult = CallResponseService.DisconnectCallResponse(); } _logger.LogDebug($"{JsonConvert.SerializeObject(responseResult)}"); var result = TwilioXmlSerializer.XmlSerialize(responseResult); _logger.LogInformation($"GetNumberRouteAsync response: {result}"); return(result); }
private async Task <Response> ProcessNumberRoutingAsync(IncomingCall call) { if (string.IsNullOrEmpty(call?.To)) { _logger.LogWarning($"Returning Twilio Reject response for callSid: '{call.CallSid}'"); return(CallResponseService.RejectResponse()); } try { var numberRouteInfo = await GetNumberRouteDataAsync(call.To); if (numberRouteInfo == null) { _logger.LogInformation($"Returning Twilio Hangup response for callSid: '{call.CallSid}', StatusId is 'Error'"); await LogCallAsync(call, CallStatus.NotAssigned); return(CallResponseService.HangupResponse()); } await LogCallAsync(call, CallStatus.Accepted, true); return(HandleBasicRoute(numberRouteInfo.routeDetails.routes[0])); } catch (Exception ex) { _logger.LogError(ex, $"ProcessNumberRoutingAsync Exception. Details: {ex.Message}"); await LogCallAsync(call, CallStatus.Error); throw; } }
/// <summary> /// Handler for processing incoming SIP requests. /// </summary> /// <param name="localSIPEndPoint">The end point the request was received on.</param> /// <param name="remoteEndPoint">The end point the request came from.</param> /// <param name="sipRequest">The SIP request received.</param> private Task SIPTransportRequestReceived(SIPEndPoint localSIPEndPoint, SIPEndPoint remoteEndPoint, SIPRequest sipRequest) { if (sipRequest.Header.From != null && sipRequest.Header.From.FromTag != null && sipRequest.Header.To != null && sipRequest.Header.To.ToTag != null) { // This is an in-dialog request that will be handled directly by a user agent instance. } else if (sipRequest.Method == SIPMethodsEnum.INVITE) { bool?callAccepted = IncomingCall?.Invoke(sipRequest); if (callAccepted == false) { // All user agents were already on a call return a busy response. UASInviteTransaction uasTransaction = new UASInviteTransaction(SIPTransport, sipRequest, null); SIPResponse busyResponse = SIPResponse.GetResponse(sipRequest, SIPResponseStatusCodesEnum.BusyHere, null); uasTransaction.SendFinalResponse(busyResponse); } } else { logger.Debug("SIP " + sipRequest.Method + " request received but no processing has been set up for it, rejecting."); SIPResponse notAllowedResponse = SIPResponse.GetResponse(sipRequest, SIPResponseStatusCodesEnum.MethodNotAllowed, null); return(SIPTransport.SendResponseAsync(notAllowedResponse)); } return(Task.FromResult(0)); }
public override void onIncomingCall(IncomingCall incomingCall) { Log.d(TAG, "Incoming call from " + incomingCall.From); outerInstance.activeIncomingCall = incomingCall; outerInstance.alertDialog = createIncomingCallDialog(outerInstance, incomingCall, outerInstance.answerCallClickListener(), outerInstance.cancelCallClickListener()); outerInstance.alertDialog.show(); }
private static void ConsultantAction(CallCenter center, string Consultant, ConsoleColor color) { Random random = new Random(); while (true) { IncomingCall call = center.Answer(Consultant); if (call != null) { Console.ForegroundColor = color; Log($"Call #{call.Id} from {call.ClientId} is answered by {call.Consultant}"); Console.ForegroundColor = ConsoleColor.Gray; Thread.Sleep(random.Next(1000, 5000)); center.End(call); Log($"Call #{call.Id} from {call.ClientId} is ended by {call.Consultant}"); Console.ForegroundColor = ConsoleColor.Gray; Thread.Sleep(random.Next(500, 1000)); } else { Thread.Sleep(100); } } }
private static void ConsultantAction(CallCenter callCenter, string name, ConsoleColor color) { Random random = new Random(); // TODO: change while true while (true) { IncomingCall call = callCenter.Answer(name); if (call == null) { Thread.Sleep(100); continue; } Console.ForegroundColor = color; Log($"Call #{call.Id} from {call.ClientId} is answered by {call.Consultant}"); Console.ForegroundColor = ConsoleColor.Gray; Thread.Sleep(random.Next(1000, 10000)); callCenter.End(call); Console.ForegroundColor = color; Log($"Call #{call.Id} from {call.ClientId} is ended by {call.Consultant}"); Console.ForegroundColor = ConsoleColor.Gray; Thread.Sleep(random.Next(500, 1000)); } }
public void ConnectedToPort(string number) { if (Status != PortStatus.Busy) { Status = PortStatus.Busy; connectedNumber = number; IncomingCall?.Invoke(this, number); } }
public static AlertDialog createIncomingCallDialog(Context context, IncomingCall incomingCall, DialogInterface.OnClickListener answerCallClickListener, DialogInterface.OnClickListener cancelClickListener) { AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context); alertDialogBuilder.Icon = R.drawable.ic_call_black_24dp; alertDialogBuilder.Title = "Incoming Call"; alertDialogBuilder.setPositiveButton("Accept", answerCallClickListener); alertDialogBuilder.setNegativeButton("Reject", cancelClickListener); alertDialogBuilder.Message = incomingCall.From + " is calling."; return(alertDialogBuilder.create()); }
public override void OnCallStateChanged(CallState state, string phoneNumber) { if (state == CallState.Idle) { Idle?.Invoke(this, phoneNumber); } else if (state == CallState.Ringing) { IncomingCall?.Invoke(this, phoneNumber); } }
/// <summary> /// This will be called when an incoming call received. /// To receive notifications from the call (eg. ringing), the program need to subscribe to the events of the call. /// </summary> private void softphone_IncomingCall(object sender, VoIPEventArgs <IPhoneCall> e) { _call = e.Item; WireUpCallEvents(); _incomingCall = true; DispatchAsync(() => { IncomingCall?.Invoke(e.Item.OtherParty.UserName); }); }
public void Call(int clientId) { IncomingCall call = new IncomingCall() { Id = ++_counter, ClientId = clientId, CallTime = DateTime.Now }; Calls.Enqueue(call); }
public override void onIncomingCallCancelled(IncomingCall incomingCall) { Log.d(TAG, "Incoming call from " + incomingCall.From + " was cancelled"); if (outerInstance.activeIncomingCall != null && incomingCall.CallSid == outerInstance.activeIncomingCall.CallSid && incomingCall.State == CallState.PENDING) { outerInstance.activeIncomingCall = null; if (outerInstance.alertDialog != null) { outerInstance.alertDialog.dismiss(); } } }
public IncomingCall Answer(string consultant) { if (Calls.Count <= 0) { return(null); } IncomingCall call = Calls.Dequeue(); call.Consultant = consultant; call.StartTime = DateTime.Now; return(call); }
/* * Disconnect an active Call */ private void disconnect() { if (activeOutgoingCall != null) { activeOutgoingCall.disconnect(); activeOutgoingCall = null; } else if (activeIncomingCall != null) { activeIncomingCall.reject(); activeIncomingCall = null; } }
public void OnEvent(SdkEvent sdkEvent) { if (sdkEvent.Event.Equals("Connected")) { Connected?.Invoke(this); } else if (sdkEvent.Event.Equals("ConnectionFailed")) { ConnectionFailed?.Invoke(this, sdkEvent.GetEventArgs <ConnectionFailedEventArgs>()); } else if (sdkEvent.Event.Equals("Disconnected")) { Disconnected?.Invoke(this); } else if (sdkEvent.Event.Equals("LoginSuccess")) { LoginSuccess?.Invoke(this, sdkEvent.GetEventArgs <LoginSuccessEventArgs>()); } else if (sdkEvent.Event.Equals("LoginFailed")) { LoginFailed?.Invoke(this, sdkEvent.GetEventArgs <LoginFailedEventArgs>()); } else if (sdkEvent.Event.Equals("RefreshTokenSuccess")) { RefreshTokenSuccess?.Invoke(this, sdkEvent.GetEventArgs <RefreshTokenSuccessEventArgs>()); } else if (sdkEvent.Event.Equals("RefreshTokenFailed")) { RefreshTokenFailed?.Invoke(this, sdkEvent.GetEventArgs <RefreshTokenFailedEventArgs>()); } else if (sdkEvent.Event.Equals("OneTimeKeyGenerated")) { OneTimeKeyGenerated?.Invoke(this, sdkEvent.GetEventArgs <OneTimeKeyGeneratedEventArgs>()); } else if (sdkEvent.Event.Equals("IncomingCall")) { var eventArgs = sdkEvent.GetEventArgs <IncomingCallEventArgs>(); eventArgs.Call = GetIncomingCall(eventArgs.callId); IncomingCall?.Invoke(this, eventArgs); } else { Debug.LogError($"Unknown Event '{sdkEvent.Event}'"); } }
private async Task LogCallAsync(IncomingCall call, CallStatus status, bool isLoadTest = false) { var callLogMessage = new CallLog(call.CallSid) { callerNumber = call.From, calledNumber = call.To, statusId = (int)status, statusName = status.ToString(), routeKey = string.Empty }; if (isLoadTest) { callLogMessage.ttl = 300; } await _callLoggingService.CreateCallLogAsync(callLogMessage); }
/// <summary> /// /// </summary> /// <param name="type"></param> public void SetControl(FormType type) { if (StackPanel != null && !Dispatcher.CheckAccess()) { ChangeControl d = SetControl; Dispatcher.Invoke(d, type); } else { switch (type) { case FormType.Conversation: MainGrid.Children.Remove(StackPanel); StackPanel = new Conversation(); Info.Text = string.Format("{0}: {1}", ChatHelper.CONVERSATION, caller); break; case FormType.Incoming: StackPanel = new IncomingCall(); Info.Text = string.Format("{0}: {1}", ChatHelper.INCOMING_CALL, caller); break; case FormType.Outcoming: StackPanel = new OutcomingCall(); Info.Text = string.Format("{0}: {1}", ChatHelper.OUTCOMING_CALL, caller); break; case FormType.File: StackPanel = new RecieveFile(); Info.Text = string.Format(ChatHelper.FILE_TRANSFER, caller); break; } if (StackPanel == null) { return; } SubscribePanel(); SetControl(); } }
public void Run() { Random random = new Random(); CallCenterPoint callCenter = new CallCenterPoint(); callCenter.Call(1234); callCenter.Call(5678); callCenter.Call(1468); callCenter.Call(9641); while (callCenter.AreWaitingCalls()) { IncomingCall call = callCenter.Answer("Maria"); Log($"Call #{call.Id} from {call.ClientId} is answered by {call.Consultant}"); Thread.Sleep(random.Next(1000, 10000)); callCenter.End(call); Log($"Call #{call.Id} from {call.ClientId} is ended by {call.Consultant}"); } }
protected virtual void OnIncomingCall(object sender, CallEventArgs args) { IncomingCall?.Invoke(sender, args); }
protected void CallIncomingCall(string PhoneNumber) { IncomingCall?.Invoke(this, new IncomingCallEventArgs(PhoneNumber)); }
public void Read(IncomingCall call) { AddToDb(call, true); }
protected void OnIncomingCall(string str) { IncomingCall?.Invoke(this, str); }
private IncomingCall ParseCallParameters(string data) { string[] items = data.Split('&'); if (items.Length == 0) { _logger.LogError("StartCallService Exception: Body missing data parameters"); return(null); } var ret = new IncomingCall { Language = "en-US" }; int found = 0; foreach (string item in items) { if (item.StartsWith("CallSid=")) { if (string.Compare(item.Substring(8), "LOADTEST", true) == 0) { ret.CallSid = Guid.NewGuid().ToString(); ret.IsLoadTest = true; } else { ret.CallSid = item.Substring(8); } found += 1; } else if (item.StartsWith("From=")) { ret.From = item.Substring(8); found += 1; } else if (item.StartsWith("To=")) { ret.To = item.Substring(6); if (ret.To.StartsWith("61")) { ret.Language = "en-AU"; } found += 1; } if (found == 3) { break; } } if (string.IsNullOrEmpty(ret.CallSid) || string.IsNullOrEmpty(ret.To)) { return(null); } return(ret); }
private void OnIncomingCall() { IncomingCall?.Invoke(this, null); }
protected void OnCalling(object sender, CallEventArgs arg) { IncomingCall?.Invoke(sender, arg); }
public void OnIncomingCall(CallEventArgs e) { Status = PortStatus.BUSY; IncomingCall?.Invoke(this, e); }
private void IncomingCallMethod(object sender, IncomingCall incomingCall) { Device.BeginInvokeOnMainThread(() => App.SetVideoCall(false, incomingCall.Caller, incomingCall.Opponents, incomingCall.VideoChatMessage)); }
public void OnIncomingCall(ConnectionDelegateArgs args) { IncomingCall?.Invoke(this, args); }
public void End(IncomingCall call) { call.EndTime = DateTime.Now; }
/// <summary> /// Data retrieved from server /// </summary> /// <param name="serverConnection">TCP connection with server</param> private static void ListenServer(TcpClient serverConnection) { serverConnection.ReceiveBufferSize = BUFFER_SIZE; serverConnection.SendBufferSize = BUFFER_SIZE; NetworkStream networkStream = serverConnection.GetStream(); while (serverConnection.Connected) { ServerObject data; try { data = (ServerObject)formatter.Deserialize(networkStream); } #region POSSIBLE EXCEPTIONS catch (IOException) { ExceptionHandler(networkStream); continue; } catch (SerializationException) { ExceptionHandler(networkStream); continue; } catch (DecoderFallbackException) { ExceptionHandler(networkStream); continue; } catch (OverflowException) { ExceptionHandler(networkStream); continue; } catch (OutOfMemoryException) { ExceptionHandler(networkStream); continue; } catch (NullReferenceException) { ExceptionHandler(networkStream); continue; } catch (IndexOutOfRangeException) { ExceptionHandler(networkStream); continue; } catch (FormatException) { ExceptionHandler(networkStream); continue; } catch (InvalidCastException) { ExceptionHandler(networkStream); continue; } catch (ArgumentOutOfRangeException) { ExceptionHandler(networkStream); continue; } catch (Exception e) { ExceptionHandler(networkStream); MessageBox.Show(e.Message, e.GetType().Name, MessageBoxButton.OK, MessageBoxImage.Error); continue; } #endregion POSSIBLE EXCEPTIONS switch (data.ServerFlag) { case ServerFlag.ConnectionState: Task.Run(() => SetConnectionState((KeyValuePair <ConnectionState, int>)data.Data)); break; case ServerFlag.Call: IncomingCall?.Invoke((int)data.Data); break; case ServerFlag.SendMessage: Task.Run(() => SendMessage((SenderObjectRelation)data.Data)); break; case ServerFlag.SendingData: Task.Run(() => SendingData((SenderObject)data.Data)); break; case ServerFlag.NewUserInCall: NewUserCall?.Invoke((int)data.Data); break; case ServerFlag.CallingToGroup: CallingToGroup?.Invoke((int)data.Data); break; case ServerFlag.DeclineCall: CallDeclined?.Invoke((int)data.Data); break; case ServerFlag.UserLeftRoom: UserLeftRoom?.Invoke((int)data.Data); break; case ServerFlag.RoomClosed: case ServerFlag.EndCall: EndCall?.Invoke(); break; case ServerFlag.ConnectionChecking: Task.Run(() => SendToServer(new ServerObject(ServerFlag.ConnectionChecking, Id))); break; case ServerFlag.ApiConnection: Task.Run(() => CheckApiConnectionFlag((ApiObject)data.Data)); break; default: break; } } MessageBox.Show("Disconnected from server"); }