Beispiel #1
0
        /// <summary>
        /// Get number of all codecs
        /// </summary>
        /// <returns></returns>
        public override int getNoOfCodecs()
        {
            if (!IsInitialized)
            {
                return(0);
            }

            int no = PjsipMethods.dll_getNumOfCodecs();

            return(no);
        }
Beispiel #2
0
        /// <summary>
        /// Get codec by index
        /// </summary>
        /// <param name="index"></param>
        /// <returns></returns>
        public override string getCodec(int index)
        {
            if (!IsInitialized)
            {
                return("");
            }

            StringBuilder codec = new StringBuilder(256);

            PjsipMethods.dll_getCodec(index, codec);
            return(codec.ToString());
        }
        /// <summary>
        /// Set presence status
        /// </summary>
        /// <param name="accId"></param>
        /// <param name="status"></param>
        /// <returns></returns>
        public int setStatus(int accId, EUserStatus status)
        {
            if ((!pjsipStackProxy.Instance.IsInitialized) || (accId < 0))
            {
                return(-1);
            }

            if ((Config.Accounts.Count > 0) && (Config.Accounts[accId].RegState != 200))
            {
                return(-1);
            }
            if (!Config.PublishEnabled)
            {
                return(-1);
            }

            return(PjsipMethods.dll_setStatus(Config.Accounts[accId].Index, (int)status));
        }
Beispiel #4
0
        /// <summary>
        /// Initialize pjsip stack
        /// </summary>
        /// <returns></returns>
        public override int initialize()
        {
            // shutdown if started already
            shutdown();

            // register callbacks (delegates)
            PjsipMethods.onDtmfDigitCallback(dtdel);
            PjsipMethods.onMessageWaitingCallback(mwidel);
            //PjsipMethods.onCallReplacedCallback(crepdel);

            // init call proxy (callbacks)
            pjsipCallProxy.initialize();

            // Initialize pjsip...
            int status = start();

            // set initialized flag
            IsInitialized = (status == 0) ? true : false;

            return(status);
        }
Beispiel #5
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        private int start()
        {
            int status = -1;

            // prepare configuration struct
            // read data from Config interface. If null read all values directly from SipConfigMore
            if (!Config.IsNull)
            {
                ConfigMore.listenPort = Config.SIPPort;
            }

            PjsipMethods.dll_setSipConfig(ConfigMore);
            status = PjsipMethods.dll_init();

            if (status != 0)
            {
                return(status);
            }

            status |= PjsipMethods.dll_main();

            return(status);
        }
Beispiel #6
0
        /// <summary>
        /// Method makeCall creates call session. Checks the 1st parameter
        /// format is SIP URI, if not build one.
        /// </summary>
        /// <param name="dialedNo"></param>
        /// <param name="accountId"></param>
        /// <returns>SessionId chosen by pjsip stack</returns>
        public override int makeCall(string dialedNo, int accountId)
        {
            string sipuri = "";

            // check if call by URI
            if (dialedNo.IndexOf("sip:") == 0)
            {
                // do nothing...
                sipuri = dialedNo;
            }
            else
            {
                // prepare URI
                sipuri = "sip:" + dialedNo + "@" + Config.Accounts[accountId].HostName;
            }
            // Select configured transport for this account: udp, tcp, tls
            sipuri = pjsipStackProxy.Instance.SetTransport(accountId, sipuri);

            // Don't forget to convert accontId here!!!
            // Store session identification for further requests
            SessionId = PjsipMethods.dll_makeCall(Config.Accounts[accountId].Index, sipuri);

            return(SessionId);
        }
        /// <summary>
        /// Send an instance message
        /// </summary>
        /// <param name="dest"></param>
        /// <param name="message"></param>
        /// <returns></returns>
        public int sendMessage(string destAddress, string message, int accId)
        {
            if (!pjsipStackProxy.Instance.IsInitialized)
            {
                return(-1);
            }

            string sipuri = "";

            // check if name contains URI
            if (destAddress.IndexOf("sip:") == 0)
            {
                // do nothing...
                sipuri = destAddress;
            }
            else
            {
                sipuri = "sip:" + destAddress + "@" + Config.Accounts[accId].HostName;
            }
            // set transport
            sipuri = pjsipStackProxy.Instance.SetTransport(accId, sipuri);

            return(PjsipMethods.dll_sendMessage(Config.Accounts[accId].Index, sipuri, message));
        }
        /// <summary>
        /// Add new entry in a buddy list and subscribe presence
        /// </summary>
        /// <param name="ident">Buddy address (without hostname part</param>
        /// <param name="presence">subscribe presence flag</param>
        /// <returns></returns>
        public int addBuddy(string name, bool presence, int accId)
        {
            string sipuri = "";

            if (!pjsipStackProxy.Instance.IsInitialized)
            {
                return(-1);
            }

            // check if name contains URI
            if (name.IndexOf("sip:") == 0)
            {
                // do nothing...
                sipuri = name;
            }
            else
            {
                sipuri = "sip:" + name + "@" + Config.Accounts[accId].HostName;
            }
            // check transport - if TCP add transport=TCP
            sipuri = pjsipStackProxy.Instance.SetTransport(accId, sipuri);

            return(PjsipMethods.dll_addBuddy(sipuri, presence));
        }
Beispiel #9
0
 /// <summary>
 /// Transfer call to other session
 /// </summary>
 /// <param name="sessionId"></param>
 /// <param name="session"></param>
 /// <returns></returns>
 public override bool xferCallSession(int session)
 {
     PjsipMethods.dll_xferCallWithReplaces(SessionId, session);
     return(true);
 }
Beispiel #10
0
 /// <summary>
 /// Retrieve request for a given session
 /// </summary>
 /// <param name="sessionId"></param>
 /// <returns></returns>
 public override bool retrieveCall()
 {
     PjsipMethods.dll_retrieveCall(SessionId);
     return(true);
 }
Beispiel #11
0
 /// <summary>
 /// Hold request for a given session
 /// </summary>
 /// <param name="sessionId"></param>
 /// <returns></returns>
 public override bool holdCall()
 {
     PjsipMethods.dll_holdCall(SessionId);
     return(true);
 }
Beispiel #12
0
 private pjsipRegistrar()
 {
     PjsipMethods.onRegStateCallback(rsDel);
 }
Beispiel #13
0
        /// <summary>
        /// Make a conference call
        /// </summary>
        /// <returns></returns>
        public override bool conferenceCall()
        {
            int status = PjsipMethods.dll_makeConference(SessionId);

            return(status == 1 ? true : false);
        }
 /// <summary>
 ///
 /// </summary>
 /// <param name="buddyId"></param>
 /// <returns></returns>
 public int delBuddy(int buddyId)
 {
     return(PjsipMethods.dll_removeBuddy(buddyId));
 }
Beispiel #15
0
 /// <summary>
 /// Set sound device for playback and recording
 /// </summary>
 /// <param name="deviceId"></param>
 public void setSoundDevice(string playbackDeviceId, string recordingDeviceId)
 {
     int status = PjsipMethods.dll_setSoundDevice(playbackDeviceId, recordingDeviceId);
 }
Beispiel #16
0
 /// <summary>
 /// Make conference with given session
 /// </summary>
 /// <param name="sessionId"></param>
 /// <param name="session"></param>
 /// <returns></returns>
 public override bool threePtyCall(int session)
 {
     PjsipMethods.dll_serviceReq(SessionId, (int)EServiceCodes.SC_3PTY, "");
     return(true);
 }
Beispiel #17
0
        /// <summary>
        /// Send dtmf digit
        /// </summary>
        /// <param name="sessionId"></param>
        /// <param name="digits"></param>
        /// <param name="mode"></param>
        /// <returns></returns>
        public override bool dialDtmf(string digits, EDtmfMode mode)
        {
            int status = PjsipMethods.dll_dialDtmf(SessionId, digits, (int)mode);

            return(true);
        }
 private pjsipPresenceAndMessaging()
 {
     PjsipMethods.onBuddyStatusChangedCallback(bscdel);
     PjsipMethods.onMessageReceivedCallback(mrdel);
 }
Beispiel #19
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        public override bool sendCallMessage(string message)
        {
            int status = PjsipMethods.dll_sendCallMessage(SessionId, message);

            return((status == 1) ? true : false);
        }
Beispiel #20
0
 /// <summary>
 /// Signals sip stack that device is alerted (ringing)
 /// </summary>
 /// <param name="sessionId"></param>
 /// <returns></returns>
 public override bool alerted()
 {
     PjsipMethods.dll_answerCall(SessionId, 180);
     return(true);
 }
Beispiel #21
0
 /// <summary>
 /// End call for a given session
 /// </summary>
 /// <param name="sessionId"></param>
 /// <returns></returns>
 public override bool endCall()
 {
     PjsipMethods.dll_releaseCall(SessionId);
     return(true);
 }
Beispiel #22
0
 /// <summary>
 /// Signals that user accepts the call (asnwer)
 /// </summary>
 /// <param name="sessionId"></param>
 /// <returns></returns>
 public override bool acceptCall()
 {
     PjsipMethods.dll_answerCall(SessionId, 200);
     return(true);
 }
Beispiel #23
0
        /////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Register all configured accounts
        /// </summary>
        /// <returns></returns>
        public int registerAccounts()
        {
            if (!pjsipStackProxy.Instance.IsInitialized)
            {
                return(-1);
            }

            if (Config.Accounts.Count <= 0)
            {
                return(0);
            }

            // unregister accounts
            PjsipMethods.dll_removeAccounts();

            // iterate all accounts
            for (int i = 0; i < Config.Accounts.Count; i++)
            {
                IAccount acc = Config.Accounts[i];
                // check if accounts available
                if (null == acc)
                {
                    return(-1);
                }

                // reset account Index field
                Config.Accounts[i].Index = -1;
                // reset account state
                Config.Accounts[i].RegState = -1;

                if (acc.Enabled && (acc.Id.Length > 0) && (acc.HostName.Length > 0))
                {
                    string displayName = acc.DisplayName;
                    // warning:::Publish do not work if display name in uri !!!
                    string uri = "sip:" + acc.UserName;
                    if (acc.UserName.IndexOf("@") < 0)
                    {
                        uri += "@" + acc.HostName;
                    }
                    string reguri = "sip:" + acc.HostName;
                    // check transport - if TCP add transport=TCP
                    reguri = pjsipStackProxy.Instance.SetTransport(i, reguri);

                    string domain   = acc.DomainName;
                    string username = acc.UserName;
                    string password = acc.Password;

                    string proxy = "";
                    if (acc.ProxyAddress.Length > 0)
                    {
                        proxy = "sip:" + acc.ProxyAddress;
                    }

                    int accId = PjsipMethods.dll_registerAccount(uri, reguri, domain, username, password, proxy, (i == Config.DefaultAccountIndex ? true : false));

                    // store account Id to Index field
                    Config.Accounts[i].Index = accId;
                }
                else
                {
                    // trigger callback
                    BaseAccountStateChanged(i, -1);
                }
            }
            return(1);
        }
Beispiel #24
0
        /// <summary>
        /// Shutdown pjsip stack
        /// </summary>
        /// <returns></returns>
        public override int shutdown()
        {
            //if (!IsInitialized) return -1;

            return(PjsipMethods.dll_shutdown());
        }