bool Manager::SendDTMF(const PString &dtmf) { PSafePtr<OpalCall> call = FindCallWithLock(currentCallToken); if (!call) { std::cerr << "no call found with token=" << currentCallToken << std::endl; return false; } bool ok = false; PSafePtr<OpalConnection> connection = call->GetConnection( listenmode ? 0 : 1); if (connection) { size_t i = 0; for (; i < dtmf.GetSize() - 1; i++) { if (!connection->SendUserInputTone(dtmf[i], 0)) break; else { // sleep a while std::cout << "sent DTMF: [" << dtmf[i] << "]" << std::endl; struct timespec tp; tp.tv_sec = 0; tp.tv_nsec = 500 * 1000 * 1000; // half a second nanosleep (&tp, 0); } } ok = (i == dtmf.GetSize() - 1 ? true : false); } if (!ok) std::cerr << "dtmf sending failed\n" << std::endl; return ok; }
bool ScriptablePluginObject::Invoke(NPIdentifier name, const NPVariant *args, uint32_t argCount, NPVariant *result) { if (name == sendCmd_id) { if ( argCount < 1 ) { return false; } PString strParam = ""; NPString npStr = NPVARIANT_TO_STRING( args[0] ); for (unsigned int i=0; i<npStr.utf8length; i++) { strParam += npStr.utf8characters[ i ]; } PString strResult = g_NativeLogic.InvokeFunction( strParam ); char* pszName = (char*)NPN_MemAlloc( strResult.GetSize() + 1 ); strcpy( pszName, strResult ); STRINGZ_TO_NPVARIANT(pszName, *result); return PR_TRUE; } return PR_FALSE; }
bool Manager::Init(PArgList &args) { std::cout << __func__ << std::endl; // Parse various command line arguments args.Parse( "u-user:"******"c-password:"******"l-localaddress:" "o-opallog:" "p-listenport:" "P-protocol:" "R-register:" "x-execute:" "f-file:" "g-gatekeeper:" "w-gateway:" "h-help:" ); if (args.HasOption('h')) { print_help(); return false; } // enable opal logging if requested. if (args.HasOption('o')) PTrace::Initialise(5, args.GetOptionString('o')); if (!args.HasOption('P')) { std::cerr << "please define a protocol to use!" << std::endl; return false; } if (args.HasOption('p')) { TPState::Instance().SetListenPort( args.GetOptionString('p').AsInteger()); } if (args.HasOption('l')) { TPState::Instance().SetLocalAddress(args.GetOptionString('l')); } string protocol = stringify(args.GetOptionString('P')); if (!protocol.compare("sip")) { cout << "initialising SIP endpoint..." << endl; sipep = new SIPEndPoint(*this); sipep->SetRetryTimeouts(10000, 30000); sipep->SetSendUserInputMode(OpalConnection::SendUserInputAsRFC2833); // AddRouteEntry("pc:.* = sip:<da>"); // AddRouteEntry("sip:.* = pc:<db>"); AddRouteEntry("local:.* = sip:<da>"); AddRouteEntry("sip:.* = local:<db>"); if (args.HasOption('u')) { sipep->SetDefaultLocalPartyName(args.GetOptionString('u')); } if (args.HasOption('c')) { SIPRegister::Params param; param.m_registrarAddress = args.GetOptionString('w'); param.m_addressOfRecord = args.GetOptionString('u'); param.m_password = args.GetOptionString('c'); param.m_realm = args.GetOptionString('g'); PString *aor = new PString(""); //sipep->SetProxy(args.GetOptionString('w')); if (!StartListener()) { return false; } if (!sipep->Register(param, *aor)) { cout << "Could not register to " << param.m_registrarAddress << endl; return false; } else { cout << "registered as " << aor->GetPointer(aor->GetSize()) << endl; } } TPState::Instance().SetProtocol(TPState::SIP); } else if (!protocol.compare("h323")) { cout << "initialising H.323 endpoint..." << endl; h323ep = new H323EndPoint(*this); AddRouteEntry("pc:.* = h323:<da>"); AddRouteEntry("h323:.* = pc:<da>"); if (args.HasOption('u')) { h323ep->SetDefaultLocalPartyName(args.GetOptionString('u')); } TPState::Instance().SetProtocol(TPState::H323); } else if (!protocol.compare("rtp")) { cout << "initialising RTP endpoint..." << endl; TPState::Instance().SetProtocol(TPState::RTP); } else { std::cerr << "invalid protocol" << std::endl; return false; } if (args.HasOption('w')) { std::string val = args.GetOptionString('w'); TPState::Instance().SetGateway(val); } SetAudioJitterDelay(20, 1000); DisableDetectInBandDTMF(true); localep = new LocalEndPoint(*this); TPState::Instance().SetManager(this); return true; }