public FunctionWrapper GenerateFuncWrapper(string qualifiedMethodName, string typeMapping, Dictionary <string, Delegate> defaultHandlers) { // Validate default handlers. foreach (KeyValuePair <string, Delegate> defaultHandler in defaultHandlers) { FunctionCall.ValidateHandler(defaultHandler.Key, defaultHandler.Value); } return((FunctionWrapper) delegate(object[] parameters) { int callID = NextCallID++; List <object> callMessage = new List <object>(); callMessage.Add("call"); callMessage.Add(callID); callMessage.Add(qualifiedMethodName); callMessage.AddRange(parameters); Connection.Send(JsonConvert.SerializeObject(callMessage)); if (IsOneWay(qualifiedMethodName)) { return null; } FunctionCall callObj = new FunctionCall(); foreach (KeyValuePair <string, Delegate> defaultHandler in defaultHandlers) { callObj.On(defaultHandler.Key, defaultHandler.Value); } ActiveCalls.Add(callID, callObj); return callObj; }); }
/// <summary> /// For a call from the test methods below /// </summary> public override void RejectCall(CodecActiveCallItem call) { Debug.Console(1, this, "RejectCall"); ActiveCalls.Remove(call); SetNewCallStatusAndFireCallStatusChange(eCodecCallStatus.Disconnected, call); //ActiveCallCountFeedback.FireUpdate(); }
//public void svcPhoneHangUp() //{ // if (EntsvcPhoneHangUp != null) // { // EntsvcPhoneHangUp(); // } //} //public void svcAgentLoggedIn(clsActive_InActiveAgent objAgentInfo) //{ // if (EntsvcAgentLoggedIn != null) // { // EntsvcAgentLoggedIn(objAgentInfo); // } //} public void svcActiveCalls(ActiveCalls objActiveCalls) { if (EntsvcActiveCalls != null) { EntsvcActiveCalls(objActiveCalls); } }
public void HandleError(string reason) { foreach (KeyValuePair <int, FunctionCall> call in ActiveCalls) { call.Value.SetResult("error", reason); } ActiveCalls.Clear(); }
public override void EndAllCalls() { Debug.Console(1, this, "EndAllCalls"); for (int i = ActiveCalls.Count - 1; i >= 0; i--) { var call = ActiveCalls[i]; ActiveCalls.Remove(call); SetNewCallStatusAndFireCallStatusChange(eCodecCallStatus.Disconnected, call); } }
/// <summary> /// /// </summary> /// <param name="url"></param> public void TestIncomingAudioCall(string number) { Debug.Console(1, this, "TestIncomingAudioCall from {0}", number); var call = new CodecActiveCallItem() { Name = number, Id = number, Number = number, Type = eCodecCallType.Audio, Direction = eCodecCallDirection.Incoming }; ActiveCalls.Add(call); SetNewCallStatusAndFireCallStatusChange(eCodecCallStatus.Ringing, call); }
public static void CompletedCall(LocationalCall call) { var locationalCall = ActiveCalls.Find(p => p.Sid == call.Sid); if (locationalCall == null) { return; } ActiveCalls.Remove(locationalCall); InactiveCalls.Add(locationalCall); }
//******************************************************** // SIMULATION METHODS /// <summary> /// /// </summary> /// <param name="url"></param> public void TestIncomingVideoCall(string url) { Debug.Console(1, this, "TestIncomingVideoCall from {0}", url); var call = new CodecActiveCallItem() { Name = url, Id = url, Number = url, Type = eCodecCallType.Video, Direction = eCodecCallDirection.Incoming }; ActiveCalls.Add(call); SetNewCallStatusAndFireCallStatusChange(eCodecCallStatus.Ringing, call); //OnCallStatusChange(eCodecCallStatus.Unknown, eCodecCallStatus.Ringing, call); }
/// <summary> /// Dials, yo! /// </summary> public override void Dial(string number) { Debug.Console(1, this, "Dial: {0}", number); var call = new CodecActiveCallItem() { Name = number, Number = number, Id = number, Status = eCodecCallStatus.Dialing, Direction = eCodecCallDirection.Outgoing, Type = eCodecCallType.Video }; ActiveCalls.Add(call); OnCallStatusChange(call); //ActiveCallCountFeedback.FireUpdate(); // Simulate 2-second ring, then connecting, then connected new CTimer(o => { call.Type = eCodecCallType.Video; SetNewCallStatusAndFireCallStatusChange(eCodecCallStatus.Connecting, call); new CTimer(oo => SetNewCallStatusAndFireCallStatusChange(eCodecCallStatus.Connected, call), 1000); }, 2000); }
public override void Dial(string number) { if (!IsInCall) { Debug.Console(1, this, "Dial: {0}", number); var call = new CodecActiveCallItem() { Name = "Mock Outgoing Call", Number = number, Type = eCodecCallType.Audio, Status = eCodecCallStatus.Connected, Direction = eCodecCallDirection.Outgoing, Id = "mockAudioCall-1" }; ActiveCalls.Add(call); OnCallStatusChange(call); } else { Debug.Console(1, this, "Already in call. Cannot dial new call."); } }
public override void EndCall(CodecActiveCallItem call) { Debug.Console(1, this, "EndCall"); ActiveCalls.Remove(call); SetNewCallStatusAndFireCallStatusChange(eCodecCallStatus.Disconnected, call); }
/// <summary> /// Parses incoming subscription-related messages directed to this object /// </summary> /// <param name="customName">CustomName of subscribed control within the component</param> /// <param name="value">Data to be parsed</param> public void ParseSubscriptionMessage(string customName, string value) { try { Debug.Console(2, this, "New Subscription Message to Dialer"); if (customName == ControlStatusCustomName || customName == PotsDialerCustomName) { //Pulls Entire Value "array" and seperates call appearances const string pattern1 = "\\[([^\\[\\]]+)\\]"; //Seperates each call appearance into their constituent parts const string pattern2 = "\\[(?<state>\\d+)\\s+(?<line>\\d+)\\s+(?<call>\\d+)\\s+(?<action>\\d+)\\s+(?<cid>\".+\"|\"\")\\s+(?<prompt>\\d+)\\]"; //Pulls CallerID Data const string pattern3 = "(?:(?:\\\\\"(?<time>.*)\\\\\")(?:\\\\\"(?<number>.*)\\\\\")(?:\\\\\"(?<name>.*)\\\\\"))|\"\""; var myMatches = Regex.Matches(value, pattern1); Debug.Console(2, this, "This is the list of Call States - {0}", myMatches.ToString()); var match = myMatches[CallAppearance - 1]; var match2 = Regex.Match(match.Value, pattern2); if (match2.Success) { Debug.Console(2, this, "VoIPControlStatus Subscribed Response = {0}", match.Value); var lineNumber = (int)(ushort.Parse(match2.Groups["line"].Value) + 1); var callStatusInt = int.Parse(match2.Groups["state"].Value); CallStatusEnum = (eCallStatus)(callStatusInt); Debug.Console(2, this, "Callstate for Line {0} is {1}", lineNumber, int.Parse(match2.Groups["state"].Value)); Debug.Console(2, this, "Callstate Enum for Line {0} is {1}", lineNumber, (int)CallStatusEnum); IncomingCallFeedback.FireUpdate(); OffHookFeedback.FireUpdate(); var match3 = Regex.Match(match2.Groups["cid"].Value, pattern3); if (match3.Success) { CallerIdNumber = match3.Groups["number"].Value; CallerIdName = match3.Groups["name"].Value; ActiveCalls.First().Name = CallerIdName; ActiveCalls.First().Number = CallerIdNumber; if (lineNumber == LineNumber) { Debug.Console(2, this, "CallState Complete - Firing Updates"); CallerIdNumberFeedback.FireUpdate(); OffHookFeedback.FireUpdate(); if (IsVoip) { VoipIsSubscribed = true; } if (!IsVoip) { PotsIsSubscribed = true; } } } else { ActiveCalls.First().Name = ""; ActiveCalls.First().Number = ""; } } } } catch (Exception e) { Debug.Console(0, this, "Error in ParseSubscriptioMessage - {0}", e.Message); } if (customName == AutoAnswerCustomName) { AutoAnswerState = bool.Parse(value); AutoAnswerIsSubscribed = true; AutoAnswerFeedback.FireUpdate(); } if (customName == HookStateCustomName) { if (value.IndexOf("OFF", StringComparison.Ordinal) > -1) { OffHookStatus = true; } if (value.IndexOf("ON", StringComparison.Ordinal) > -1) { OffHookStatus = false; } OffHookFeedback.FireUpdate(); } if (customName != LastDialedCustomName) { return; } LastDialed = value; LastDialedFeedback.FireUpdate(); }
public static void AddNewCall(LocationalCall call) { ActiveCalls.Add(call); }
private void HandleMessage(string message) { List <object> data = JsonConvert.DeserializeObject <List <object> >(message); string msgType = (string)data[0]; if (msgType == "call-reply") { int callID = Convert.ToInt32(data[1]); if (ActiveCalls.ContainsKey(callID)) { bool success = (bool)data[2]; object retValOrException = data[3]; ActiveCalls[callID].SetResult(success ? "result" : "exception", retValOrException); } else { throw new Error(ErrorCode.CONNECTION_ERROR, "Received a response for an unrecognized call id: " + callID); } } else if (msgType == "call") { int callID = Convert.ToInt32(data[1]); string methodName = (string)data[2]; if (RegisteredFunctions.ContainsKey(methodName)) { Delegate nativeMethod = RegisteredFunctions[methodName]; ParameterInfo[] paramInfo = nativeMethod.Method.GetParameters(); if (paramInfo.Length != data.Count - 3) { throw new Error(ErrorCode.INVALID_ARGUMENT, "Incorrect number of arguments for method: " + methodName + ". Expected: " + paramInfo.Length + ". Got: " + (data.Count - 3)); } List <object> parameters = new List <object>(); for (int i = 0; i < paramInfo.Length; i++) { parameters.Add(ConversionUtils.CastJObject( data[i + 3], paramInfo[i].ParameterType)); } object returnValue = null; object exception = null; bool success = true; try { returnValue = nativeMethod.DynamicInvoke(parameters.ToArray()); } catch (Exception e) { exception = e; success = false; } if (!IsOneWay(methodName)) { // Send call-reply message. List <object> callReplyMessage = new List <object>(); callReplyMessage.Add("call-reply"); callReplyMessage.Add(callID); callReplyMessage.Add(success); if (!success) { callReplyMessage.Add(exception); } else if (nativeMethod.Method.ReturnType != typeof(void)) { callReplyMessage.Add(returnValue); } Connection.Send(JsonConvert.SerializeObject(callReplyMessage)); } } else { throw new Error(ErrorCode.CONNECTION_ERROR, "Received a call for an unregistered method: " + methodName); } } else { throw new Error(ErrorCode.CONNECTION_ERROR, "Unknown message type: " + msgType); } }