Search code examples
c#windowsvoipozeki

Registering phoneline to Ozeki Voip SDK blocks phone ringing


I'm using Ozeki.VoIP.SDK to handle incoming VoIP calls in our Elastix system. What I'm trying to do is to read and show information about incoming calls in my application and let the desk phones ring too.

The problem is when I register a phone line from VoIP pool to Ozeki controller, incoming calls to that line will no longer ring on my desk phone. But when I un-register that phone line, my desk phone rings again when it receives phone calls.

I have no idea why Ozeki SDK blocks the calls I'm reading in my application.

    private ISoftPhone _softphone;
    private Dictionary<string,IPhoneLine> _phoneLines;

    public Softphone()
    {
        _softphone = SoftPhoneFactory.CreateSoftPhone(IP_ADDRESS, MIN_PORT, MAX_PORT, SIP_PORT);
        _softphone.ChangeNATSettings(Ozeki.Network.Nat.NATTraversalMethodType.NONE, "", "", "");
        _softphone.IncommingCall += softphone_IncommingCall;
        _phoneLines = new Dictionary<string, IPhoneLine>();
    }
    public bool IsRegistered(string username)
    {
        return (_phoneLines.Keys.Contains(username));
    }
    public void Register(SIPAccount account)
    {
        if (IsRegistered(account.UserName))
        {
            Unregister(account);
            Thread.Sleep(1000);
        }
        //throw new Exception(string.Format("The account with username={0} already registered.", account.UserName));

        // With the SIP account and the NAT configuration, we can create a phoneline.
        IPhoneLine phoneLine = _softphone.CreatePhoneLine(account);
        // If our phoneline is created, we can register that.
        _softphone.RegisterPhoneLine(phoneLine);

        _phoneLines.Add(account.UserName, phoneLine);
    }
    public void Unregister(SIPAccount account)
    {
        IPhoneLine phoneLine = _softphone.CreatePhoneLine(account);
        _phoneLines.Remove(account.UserName);
        _softphone.UnregisterPhoneLine(phoneLine);
    }

    private void DispatchAsync(Action action)
    {
        var task = new WaitCallback(o => action.Invoke());
        ThreadPool.QueueUserWorkItem(task);
    }

    private void softphone_IncommingCall(object sender, VoIPEventArgs<IPhoneCall> e)
    {
        DispatchAsync(() =>
        {
            onIncomingCall(e);
        });
    }
    private void onIncomingCall(VoIPEventArgs<IPhoneCall> e)
    {
        if (IncomingCall != null)
            IncomingCall(this, e);
    }

Has anyone seen this behavior before? I have no clue.


Solution

  • Following the link mjwills mentioned, I found out this was a known behavior of VoIP systems and its workaround is to define one followme line for each line and make the application register only to the followme lines and not the lines registered by desk phones.