public int playTone(ETones toneId)
        {
            lock (_lockObj)
            {
                if (_isPlaying)
                {
                    //Task.Factory.StartNew(() => stopTone(), TaskCreationOptions.PreferFairness);
                    _isPlaying = false;

                    CommonDelegates.SafeInvoke(() => dll_releaseWav(_playerId));
                }

                if (_sessionId >= 0)
                {
                    _playerId = CommonDelegates.SafeInvoke(() => dll_playWav(GetToneFile(toneId), true, _sessionId));

                    if (_playerId >= 0)
                    {
                        _isPlaying = true;
                    }
                }

                return(_playerId);
            }
        }
Exemple #2
0
        /// <summary>
        /// Unregister all accounts
        /// </summary>
        /// <returns></returns>
        public override int unregisterAccounts()
        {
            CommonDelegates.SafeInvoke(() => dll_removeAccounts());

            Instance.BaseAccountStateChanged(-1);

            return(1);
        }
Exemple #3
0
        /// <summary>
        /// Shutdown pjsip stack
        /// </summary>
        /// <returns></returns>
        public override int shutdown()
        {
            if (!IsInitialized)
            {
                return(-1);
            }

            return(CommonDelegates.SafeInvoke(() => dll_shutdown()));
        }
Exemple #4
0
        /// <summary>
        /// Get number of all codecs
        /// </summary>
        /// <returns></returns>
        public override int getNoOfCodecs()
        {
            if (!IsInitialized)
            {
                return(0);
            }

            return(CommonDelegates.SafeInvoke(() => dll_getNumOfCodecs()));
        }
Exemple #5
0
        /// <summary>
        /// Set codec priority
        /// </summary>
        /// <param name="codecname"></param>
        /// <param name="priority"></param>
        public override void setCodecPriority(string codecname, int priority)
        {
            if (!IsInitialized)
            {
                return;
            }

            CommonDelegates.SafeInvoke(() => dll_setCodecPriority(codecname, priority));
        }
Exemple #6
0
        /////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Register all configured accounts
        /// </summary>
        /// <returns></returns>
        public override int registerAccounts()
        {
            if (!pjsipStackProxy.Instance.IsInitialized)
            {
                return(-1);
            }

            unregisterAccounts();

            // iterate all accounts
            IAccount acc = Config.Account;

            // check if accounts available
            if (null == acc)
            {
                return(-1);
            }

            // reset account Index field
            Config.Account.Index = -1;
            // reset account state
            Config.Account.RegState = -1;

            if (acc.Enabled && 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(reguri);

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

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

                // Indicate connecting state
                BaseAccountStateChanged(0);

                // store account Id to Index field
                Config.Account.Index = CommonDelegates.SafeInvoke(() => dll_registerAccount(uri, reguri, domain, username, password, proxy, true));
            }

            return(1);
        }
Exemple #7
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);

            CommonDelegates.SafeInvoke(() => dll_getCodec(index, codec));
            return(codec.ToString());
        }
Exemple #8
0
        internal void HandleDevicesRemoved(IEnumerable <AudioDevicesWatcher.AudioDeviceDescriptor> deviceDescriptors)
        {
            var devices = ConvertDeviceDescriptors(deviceDescriptors);

            // Call sync
            CommonDelegates.SafeInvoke <int>(() => { ReloadAudioDevices(); return(0); });

            if (devices != null && AudioDevicesRemoved != null)
            {
                AudioDevicesRemoved(devices);
            }
        }
        public int stopTone()
        {
            lock (_lockObj)
            {
                if (!_isPlaying)
                {
                    return(0);
                }

                _isPlaying = false;

                CommonDelegates.SafeInvoke(() => dll_releaseWav(_playerId));
            }

            return(0);
        }
        /// <summary>
        /// Set presence status
        /// </summary>
        /// <param name="status"></param>
        /// <returns></returns>
        public override int setStatus(EUserStatus status)
        {
            if (!pjsipStackProxy.Instance.IsInitialized)
            {
                return(-1);
            }

            if (Config.Account.RegState != 200)
            {
                return(-1);
            }
            if (!Config.PublishEnabled)
            {
                return(-1);
            }

            return(CommonDelegates.SafeInvoke(() => dll_setStatus(Config.Account.Index, (int)status)));
        }
Exemple #11
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        private int start()
        {
            // prepare configuration struct
            // read data from Config interface. If null read all values directly from SipConfigMore
            if (!Config.IsNull)
            {
                ConfigMore.listenPort = Config.SIPPort;
                ConfigMore.rtpPort    = Config.RTPPort;
            }

            CommonDelegates.SafeInvoke(() => dll_setSipConfig(ConfigMore));

            int status = CommonDelegates.SafeInvoke(() => { return(dll_init()); });

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

            status = CommonDelegates.SafeInvoke(() => dll_main());
            return(status);
        }
        /// <summary>
        /// Add new entry in a buddy list and subscribe presence
        /// </summary>
        /// <param name="name">Buddy address (without hostname part</param>
        /// <param name="presence">subscribe presence flag</param>
        /// <returns></returns>
        public override int addBuddy(string name, bool presence)
        {
            string sipuri;

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

            // check if name contains URI
            if (name != null && name.IndexOf("sip:", StringComparison.Ordinal) == 0)
            {
                // do nothing...
                sipuri = name;
            }
            else
            {
                sipuri = "sip:" + name + "@" + Config.Account.HostName;
            }
            // check transport - if TCP add transport=TCP
            sipuri = pjsipStackProxy.Instance.SetTransport(sipuri);

            return(CommonDelegates.SafeInvoke(() => dll_addBuddy(sipuri, presence)));
        }
        /// <summary>
        /// Send an instance message
        /// </summary>
        /// <param name="destAddress"></param>
        /// <param name="message"></param>
        /// <returns></returns>
        public override int sendMessage(string destAddress, string message)
        {
            if (!pjsipStackProxy.Instance.IsInitialized)
            {
                return(-1);
            }

            string sipuri = "";

            // check if name contains URI
            if (destAddress != null && destAddress.IndexOf("sip:", StringComparison.Ordinal) == 0)
            {
                // do nothing...
                sipuri = destAddress;
            }
            else
            {
                sipuri = "sip:" + destAddress + "@" + Config.Account.HostName;
            }
            // set transport
            sipuri = pjsipStackProxy.Instance.SetTransport(sipuri);

            return(CommonDelegates.SafeInvoke(() => dll_sendMessage(Config.Account.Index, sipuri, message)));
        }
 /// <summary>
 ///
 /// </summary>
 /// <param name="buddyId"></param>
 /// <returns></returns>
 public override int delBuddy(int buddyId)
 {
     return(CommonDelegates.SafeInvoke(() => dll_removeBuddy(buddyId)));
 }
Exemple #15
0
        public override void renewAccount(int accountIndex)
        {
            CommonDelegates.SafeInvoke(() => dll_renewAccount(accountIndex));

            Instance.BaseAccountStateChanged(accountIndex);
        }
Exemple #16
0
 private T SafeInvoke <T>(Func <T> func)
 {
     return(CommonDelegates.SafeInvoke(func));
 }
Exemple #17
0
 private void SafeInvoke(Action action)
 {
     CommonDelegates.SafeInvoke(action);
 }
Exemple #18
0
 private T SafeInvoke <T>(Delegate del)
 {
     return(CommonDelegates.SafeInvoke <T>(del));
 }
Exemple #19
0
 /// <summary>
 /// Set sound device for playback and recording
 /// </summary>
 /// <param name="deviceId"></param>
 public void setSoundDevice(string playbackDeviceId, string recordingDeviceId)
 {
     CommonDelegates.SafeInvoke(() => dll_setSoundDevice(playbackDeviceId, recordingDeviceId));
 }