Beispiel #1
0
BlabbleCall::BlabbleCall(const BlabbleAccountPtr& parent_account)
	: call_id_(-1), ringing_(false)
{
	if (parent_account) 
	{
		acct_id_ = parent_account->id();
		audio_manager_ = parent_account->GetManager()->audio_manager();
		parent_ = BlabbleAccountWeakPtr(parent_account);
	}
	else 
	{
		acct_id_ = -1;
	}
	
	id_ = BlabbleCall::GetNextId();
	BLABBLE_LOG_DEBUG("New call created. Global id: " << id_);

	registerMethod("answer", make_method(this, &BlabbleCall::Answer));
	registerMethod("hangup", make_method(this, &BlabbleCall::LocalEnd));
	registerMethod("hold", make_method(this, &BlabbleCall::Hold));
	registerMethod("unhold", make_method(this, &BlabbleCall::Unhold));
	registerMethod("sendDTMF", make_method(this, &BlabbleCall::SendDTMF));
	registerMethod("transferReplace", make_method(this, &BlabbleCall::TransferReplace));
	registerMethod("transfer", make_method(this, &BlabbleCall::Transfer));

	registerProperty("callerId", make_property(this, &BlabbleCall::caller_id));
	registerProperty("isActive", make_property(this, &BlabbleCall::is_active));
	registerProperty("status", make_property(this, &BlabbleCall::status));

	registerProperty("onCallConnected", make_write_only_property(this, &BlabbleCall::set_on_call_connected));
	registerProperty("onCallEnd", make_write_only_property(this, &BlabbleCall::set_on_call_end));
}
Beispiel #2
0
// REITEK: Added insecure and secure SIP ports
PjsuaManager::PjsuaManager(const std::string& executionPath, bool enableIce,
	const std::string& stunServer, const int& sipPort, const int& sipTlsPort)
{
	pj_status_t status;
	pjsua_config cfg;
	pjsua_logging_config log_cfg;
	pjsua_media_config media_cfg;
	pjsua_transport_config tran_cfg, tls_tran_cfg;

	pjsua_transport_config_default(&tran_cfg);
	pjsua_transport_config_default(&tls_tran_cfg);
	pjsua_media_config_default(&media_cfg);
	pjsua_config_default(&cfg);
	pjsua_logging_config_default(&log_cfg);

	//cfg.max_calls = 511;
	cfg.max_calls = 2;

	cfg.cb.on_incoming_call = &PjsuaManager::OnIncomingCall;
	cfg.cb.on_call_media_state = &PjsuaManager::OnCallMediaState;
	cfg.cb.on_call_state = &PjsuaManager::OnCallState;
	cfg.cb.on_reg_state = &PjsuaManager::OnRegState;
	cfg.cb.on_transport_state = &PjsuaManager::OnTransportState;
	cfg.cb.on_call_transfer_status = &PjsuaManager::OnCallTransferStatus;
	cfg.cb.on_call_tsx_state = &PjsuaManager::OnCallTsxState;

	log_cfg.level = 4;
	log_cfg.console_level = 4;
	// REITEK: Log messages!
	log_cfg.msg_logging = PJ_TRUE;
	log_cfg.decor = PJ_LOG_HAS_SENDER | PJ_LOG_HAS_SPACE | PJ_LOG_HAS_LEVEL_TEXT;
	log_cfg.cb = BlabbleLogging::blabbleLog;

	// REITEK: !!! CHECK: Make TLS port configurable ?
	tls_tran_cfg.port = 0;
	//tran_cfg.tls_setting.verify_server = PJ_TRUE;
	tls_tran_cfg.tls_setting.timeout.sec = 5;
	tls_tran_cfg.tls_setting.method = PJSIP_TLSV1_METHOD;

	tran_cfg.port = sipPort;

	// REITEK: !!! CHECK: Make port range configurable ?
	tran_cfg.port_range = 200;

	media_cfg.no_vad = 1;
	media_cfg.enable_ice = enableIce ? PJ_TRUE : PJ_FALSE;

	// REITEK: Disable EC
	media_cfg.ec_tail_len = 0;

	if (!stunServer.empty()) 
	{
		cfg.stun_srv_cnt = 1;
		cfg.stun_srv[0] = pj_str(const_cast<char*>(stunServer.c_str()));
	}

	// REITEK: User-Agent header handling
	cfg.user_agent = pj_str("Reitek PluginSIP");

	status = pjsua_create();
	if (status != PJ_SUCCESS)
		throw std::runtime_error("pjsua_create failed");

	status = pjsua_init(&cfg, &log_cfg, &media_cfg);
	if (status != PJ_SUCCESS) 
		throw std::runtime_error("Error in pjsua_init()");

	try
	{
		status = pjsua_transport_create(PJSIP_TRANSPORT_TLS, &tls_tran_cfg, &this->tls_transport);
		has_tls_ = status == PJ_SUCCESS;
		if (!has_tls_) {
			BLABBLE_LOG_DEBUG("Error in tls pjsua_transport_create. Tls will not be enabled");
			this->tls_transport = -1;
		}

		status = pjsua_transport_create(PJSIP_TRANSPORT_UDP, &tran_cfg, &this->udp_transport);
		if (status != PJ_SUCCESS)
			throw std::runtime_error("Error in pjsua_transport_create for UDP transport");

		status = pjsua_start();
		if (status != PJ_SUCCESS)
			throw std::runtime_error("Error in pjsua_start()");

		// REITEK: Codecs priority handling
		pj_str_t tmpstr;

		// !!! FIXME: Hardwired now in order to test G. 729
		pjsua_codec_set_priority(pj_cstr(&tmpstr, "*"), 0);
		pjsua_codec_set_priority(pj_cstr(&tmpstr, "g729"), 255);
		pjsua_codec_set_priority(pj_cstr(&tmpstr, "pcmu"), 240);
		pjsua_codec_set_priority(pj_cstr(&tmpstr, "pcma"), 230);
		pjsua_codec_set_priority(pj_cstr(&tmpstr, "speex/8000"), 190);
		pjsua_codec_set_priority(pj_cstr(&tmpstr, "ilbc"), 189);
		pjsua_codec_set_priority(pj_cstr(&tmpstr, "speex/16000"), 180);
		pjsua_codec_set_priority(pj_cstr(&tmpstr, "speex/32000"), 0);
		pjsua_codec_set_priority(pj_cstr(&tmpstr, "gsm"), 100);

#if 0
		// REITEK: G.729 codec handling
		pjmedia_codec_param g729_param;

		status = pjsua_codec_get_param(pj_cstr(&tmpstr, "g729"), &g729_param);
		if (status != PJ_SUCCESS)
			throw std::runtime_error("Cannot get G.729 default parameters");

		g729_param.setting.frm_per_pkt = m_config.getG729FramesPerPacket();
		pjsua_codec_set_param(pj_cstr(&tmp, "g729"), &g729_param);
#endif

		// REITEK: Use our own directory for ringtones etc
#if 0
		std::string path = executionPath;
		unsigned int tmp = path.find("plugins");
		if (tmp != std::string::npos)
		{
			path = path.substr(0, tmp + 7);
		}
		tmp = path.find(FBSTRING_PluginFileName".");
		if (tmp != std::string::npos)
		{
			path = path.substr(0, tmp - 1);
		}
#endif
		
		std::string path;

#if defined(XP_WIN)
		std::string appdata = getenv("ALLUSERSPROFILE");
		path = appdata + "\\Mozilla\\Plugins";
#elif defined(XP_LINUX)
		std::string appdata = getenv("HOME");
		path = appdata + "/Reitek/Contact/BrowserPlugin";
#endif
		
		audio_manager_ = boost::make_shared<BlabbleAudioManager>(path);

		BLABBLE_LOG_DEBUG("PjsuaManager startup complete.");
	}
	catch (std::runtime_error& e)
	{
		std::string str = "Error in PjsuaManager. " + boost::lexical_cast<std::string>(e.what());
		BlabbleLogging::blabbleLog(0, str.c_str(), 0);
		//BLABBLE_LOG_ERROR("Error in PjsuaManager. " << e.what());
		pjsua_destroy();
		throw e;
	}
}
Beispiel #3
0
BlabbleCall::~BlabbleCall(void)
{
	BLABBLE_LOG_DEBUG("Call Deleted. Global id: " << id_);
	on_call_end_.reset();
	LocalEnd();
}