Exemplo n.º 1
0
        void Init()
        {
            if (_inited)
            {
                return;
            }
            _shouldBeRegistered = true;
            _sdkLib             = new PortSIPLib(0, 0, this);

            //
            // Create and set the SIP callback handers, this MUST called before
            // _sdkLib.initialize();
            //
            _sdkLib.createCallbackHandlers();

            //var logFilePath = Host.GetPluginDirectory("Telephone");
            var rd     = new Random();
            var portno = rd.Next(10000, 11000);
            // Initialize the SDK

            /*
             * TRANSPORT_TYPE transportType,
             *                            String localIp,
             *                            Int32 localSIPPort,
             *                            PORTSIP_LOG_LEVEL logLevel,
             *                            String logFilePath,
             *                            Int32 maxCallSessions,
             *                            String sipAgentString,
             *                            Int32 audioDeviceLayer,
             *                            Int32 videoDeviceLayer
             */
            var tt = TRANSPORT_TYPE.TRANSPORT_UDP;
            //switch (tt)
            //{
            //    case SipTransportType.Tcp:
            //        tt = TRANSPORT_TYPE.TRANSPORT_TCP;
            //        break;
            //    case SipTransportType.Tls:
            //        tt = TRANSPORT_TYPE.TRANSPORT_TLS;
            //        break;
            //}

            int rt = _sdkLib.initialize(tt,
                                        "0.0.0.0",
                                        portno,
                                        PORTSIP_LOG_LEVEL.PORTSIP_LOG_NONE,
                                        "",
                                        1,
                                        "PortSIP VoIP SDK 15.0",
                                        0,
                                        0);

            if (rt != 0)
            {
                _sdkLib.releaseCallbackHandlers();
                return;
            }
            rt = _sdkLib.setLicenseKey("1WINoR00RTg2NUQzM0I4OEJFQUQ1MzZGOTZFOUI5REMxMTE2OUBGQkFCNDNCQUEyRTFEOUQyNDI1RERDNzAzQkI3MjU5QkA4MjY2MjRERjAwNUJGMUEyRDYzNDNCQjNDNDExNURFNkA0NDREMzUyNENCRDY5QTJCOEIxNzAwMEI1MTYyQjc0MQ");
            if (rt == PortSIP_Errors.ECoreTrialVersionLicenseKey)
            {
                _logger.Warn(this, "This sample was built base on evaluation PortSIP VoIP SDK, which allows only three minutes conversation. The conversation will be cut off automatically after three minutes, then you can't hearing anything. Feel free contact us at: [email protected] to purchase the official version.");
            }
            else if (rt == PortSIP_Errors.ECoreWrongLicenseKey)
            {
                _logger.Warn(this, "The wrong license key was detected, please check with [email protected] or [email protected]");
            }
            _sdkLib.enableAEC(EC_MODES.EC_DEFAULT);
            _sdkLib.enableVAD(true);
            _sdkLib.enableAGC(AGC_MODES.AGC_NONE);
            _sdkLib.enableANS(NS_MODES.NS_DEFAULT);
            foreach (AUDIOCODEC_TYPE val in Enum.GetValues(typeof(AUDIOCODEC_TYPE)))
            {
                _sdkLib.addAudioCodec(val);
            }


            /*
             * String userName,
             *           String displayName,
             *           String authName,
             *           String password,
             *           String sipDomain,
             *           String sipServerAddr,
             *           Int32 sipServerPort,
             *           String stunServerAddr,
             *           Int32 stunServerPort,
             *           String outboundServerAddr,
             *           Int32 outboundServerPort*/
            rt = _sdkLib.setUser(
                Account.Username,
                Account.Username,
                Account.Username,
                Account.Password,
                "",
                Account.Server,
                5060,
                null,
                -1,
                Account.Server,
                5060);
            if (rt != 0)
            {
                _logger.Error(this, "Telephone registration failed");
                _sdkLib.unInitialize();
                _sdkLib.releaseCallbackHandlers();
                return;
            }
            _sdkLib.setSrtpPolicy(SRTP_POLICY.SRTP_POLICY_NONE);
            _sdkLib.setDoNotDisturb(false);
            _inited = true;
            _logger.Info(this, "Registration successful");
        }