public CStateMachine(CCallManager manager) { // store manager reference... _manager = manager; // create call proxy _sigProxy = _manager.Factory.createCallProxy(); // initialize call states _stateIdle = new CIdleState(this); _stateAlerting = new CAlertingState(this); _stateActive = new CActiveState(this); _stateCalling = new CConnectingState(this); _stateReleased = new CReleasedState(this); _stateIncoming = new CIncomingState(this); _stateHolding = new CHoldingState(this); // change state _state = _stateIdle; // initialize data Time = System.DateTime.Now; Duration = System.TimeSpan.Zero; // Initialize timers if (null != _manager) { _noreplyTimer = _manager.Factory.createTimer(); _noreplyTimer.Interval = 15000; // hardcoded to 15s _noreplyTimer.Elapsed = new TimerExpiredCallback(_noreplyTimer_Elapsed); _releasedTimer = _manager.Factory.createTimer(); _releasedTimer.Interval = 5000; // hardcoded to 15s _releasedTimer.Elapsed = new TimerExpiredCallback(_releasedTimer_Elapsed); } }
private void button1_Click(object sender, EventArgs e) { // create call proxy () ICallProxyInterface call = pjsipProxy.createCallProxy(); int sessionId = call.makeCall(textBox1.Text, 0); label2.Text = (sessionId >= 0 ? "Success" : "Failed") + " (" + sessionId + ")"; }
/// <summary> /// /// </summary> /// <param name="callId"></param> /// <param name="sturi"></param> /// <returns></returns> private static int onCallIncoming(int callId, string sturi) { string uri = sturi; string display = ""; string number = ""; if (null != uri) { // get indices int startNum = uri.IndexOf("<sip:"); int atPos = uri.IndexOf('@'); // search for number if ((startNum >= 0) && (atPos > startNum)) { number = uri.Substring(startNum + 5, atPos - startNum - 5); } // extract display name if exists if (startNum >= 0) { display = uri.Remove(startNum, uri.Length - startNum).Trim(); } else { int semiPos = display.IndexOf(';'); if (semiPos >= 0) { display = display.Remove(semiPos, display.Length - semiPos); } else { int colPos = display.IndexOf(':'); if (colPos >= 0) { display = display.Remove(colPos, display.Length - colPos); } } } } // invoke callback ICallProxyInterface.BaseCallStateChanged(callId, ESessionState.SESSION_STATE_INCOMING, ""); ICallProxyInterface.BaseIncomingCall(callId, number, display); return(1); }
/// <summary> /// Call/Session constructor. Initializes call states, creates signaling proxy, initialize time, /// initialize timers. /// </summary> public CStateMachine() { // store manager reference... _manager = CCallManager.Instance; // create call proxy _sigProxy = _manager.StackProxy.createCallProxy(); // create media proxy for this call _mediaProxy = new Sipek.Sip.pjsipMediaPlayerProxy(); // initialize call states _stateIdle = new CIdleState(this); _stateAlerting = new CAlertingState(this); _stateActive = new CActiveState(this); _stateCalling = new CConnectingState(this); _stateReleased = new CReleasedState(this); _stateIncoming = new CIncomingState(this); _stateHolding = new CHoldingState(this); _stateTerminated = new CTerminatedState(this); // change state _state = _stateIdle; // initialize data Time = DateTime.Now; Duration = TimeSpan.Zero; // Initialize timers if (null != _manager) { _noreplyTimer = _manager.Factory.CreateTimer(); _noreplyTimer.Interval = 60000; // hardcoded to 60s _noreplyTimer.Elapsed = new TimerExpiredCallback(_noreplyTimer_Elapsed); //_releasedTimer = _manager.Factory.createTimer(); //_releasedTimer.Interval = 1000; // hardcoded to 1s //_releasedTimer.Elapsed = new TimerExpiredCallback(_releasedTimer_Elapsed); _noresponseTimer = _manager.Factory.CreateTimer(); _noresponseTimer.Interval = 60000; // hardcoded to 60s _noresponseTimer.Elapsed = new TimerExpiredCallback(_noresponseTimer_Elapsed); } }
public void Transfer(string number) { Action method = new Action(() => { string num = Globals.NormalizeTelNumber(number); if (number.Length >= 9 && Settings.Prefix0) { num = "0" + num; } IStateMachine call; if (CallManager.getNoCallsInState(EStateId.ACTIVE) > 0) { call = CallManager.getCallInState(EStateId.ACTIVE); } else { call = CallManager.getCallInState(EStateId.INCOMING); } ICallProxyInterface proxy = StackProxy.createCallProxy(); proxy.SessionId = call.Session; if (call.StateId == EStateId.ACTIVE) { proxy.holdCall(); proxy.xferCall(num); } else { CallManager.onUserTransfer(call.Session, num); } }); if (this.InvokeRequired) { this.Invoke((MethodInvoker) delegate { method(); }); } else { method(); } }
private static int onCallIncoming(int callId, string sturi) { string str = sturi; string info = ""; string number = ""; if (str != null) { int index = str.IndexOf("<sip:"); int num2 = str.IndexOf('@'); if ((index >= 0) && (num2 > index)) { number = str.Substring(index + 5, (num2 - index) - 5); } if (index >= 0) { info = str.Remove(index, str.Length - index).Trim(); } else { int startIndex = info.IndexOf(';'); if (startIndex >= 0) { info = info.Remove(startIndex, info.Length - startIndex); } else { int num4 = info.IndexOf(':'); if (num4 >= 0) { info = info.Remove(num4, info.Length - num4); } } } } ICallProxyInterface.BaseIncomingCall(callId, number, info); return(1); }
/// <summary> /// /// </summary> /// <param name="callId"></param> /// <param name="callState"></param> private void OnCallStateChanged(int callId, ESessionState callState, string info) { if (callState == ESessionState.SESSION_STATE_INCOMING) { IStateMachine incall = Factory.createStateMachine(); // couldn't create new call instance (max calls?) if (incall.IsNull) { // check if CFB, activate redirection if (Config.CFBFlag == true) { // get stack proxy ICallProxyInterface proxy = StackProxy.createCallProxy(); // assign callid to the proxy... //proxy.SessionId = callId; proxy.serviceRequest((int)EServiceCodes.SC_CFB, Config.CFBNumber); return; } } // save session parameters incall.Session = callId; // check if callID already exists!!! if (CallList.ContainsKey(callId)) { // shouldn't be here // release the call CallList[callId].State.endCall(); return; } // add call to call table _calls.Add(callId, incall); return; } IStateMachine call = this[callId]; if (call.IsNull) { return; } switch (callState) { case ESessionState.SESSION_STATE_CALLING: //sm.getState().onCalling(); break; case ESessionState.SESSION_STATE_EARLY: call.State.onAlerting(); break; case ESessionState.SESSION_STATE_CONNECTING: call.State.onConnect(); break; case ESessionState.SESSION_STATE_DISCONNECTED: call.State.onReleased(); break; } }
/// <summary> /// /// </summary> /// <param name="callId"></param> /// <param name="callState"></param> /// <returns></returns> private static int onCallStateChanged(int callId, ESessionState callState) { ICallProxyInterface.BaseCallStateChanged(callId, callState, ""); return(0); }
private static int onCallHoldConfirm(int callId) { ICallProxyInterface.BaseCallNotification(callId, ECallNotification.CN_HOLDCONFIRM, ""); return(1); }