From: Tom Szabo on 30 Nov 2008 03:36 With Alessandro's help I have got it going, so I thought others may be in the same situation. So here is my implementation - it is not very sophisticated yet, but it helps at start ====================================================== method Make_Call(cPhoneNumber) class Phone_List_BF local cChan, cHeadSet as string local oASocket as Asterisk_Socket cChan := "SIP/Pennytel821" cHeadSet := goSys:cHeadSetExt cPhoneNumber := StrTran(cPhoneNumber, " ", "") oASocket := Asterisk_Socket{"10.0.0.106", 5038, self} oASocket:Authenticate("admin", "elastix456") oASocket:MakeCall( cChan , cPhoneNumber, cHeadSet) ====================================================== > > http://www.voip-info.org/wiki/view/Asterisk+manager+API > ======================================================= The actual class to manage Asterisk ======================================================= class Asterisk_Manager export oSocket as usual ======================================================= method Init(cAddr, nPort, oW) class Asterisk_Manager local nSocket as dword self:oSocket := cSocket{SOCK_STREAM} nSocket := self:oSocket:NumSocket if !self:oSocket:connect(cAddr , nPort) WB("Error Connecting",self:oSocket:ErrorMsg) self:oSocket:Close() self:oSocket := NULL_OBJECT endif if ( WSAAsyncSelect(nSocket, oW:Handle(), 1, FD_READ+FD_WRITE+FD_CLOSE) ==0 ) WB("Socket accepting IN non-blocking mode") else self:oSocket := NULL_OBJECT WB("ERROR Socket NON accepting IN non-blocking mode") endif if self:oSocket = NULL_OBJECT if shutdown(nSocket,SD_BOTH)==0 closesocket(nSocket) endif nSocket := INVALID_SOCKET endif ======================================================= method Authenticate(cUser, cPasswd) class Asterisk_Manager local cText as string self:Send_Ln( "Action: Login") self:Send_Ln("ActionID: AStringYouPrefer") self:Send_Ln("Username: Admin") self:Send_Ln("Secret: elastix456") self:Send_Ln("Events: On") self:Send_Ln(CrLf ) AltD() cText := self:oSocket:GetRaw() WB("Autentication:", cText) ======================================================= method MakeCall(cChan, cToCall, cExten, cCallerID, cContext, cPriority, cAsync) class Asterisk_Manager local cToBeCalled, cText as string cToBeCalled := AllTrim(cChan) + "/" + AllTrim(cToCall) Default(@cContext, "default") Default(@cCallerID, "38472202") Default(@cPriority, "1") Default(@cAsync, "yes") self:Send_Ln( "Action: Originate" ) self:Send_Ln( "Channel: " + AllTrim(cToBeCalled)) self:Send_Ln( "Context: " + AllTrim(cContext)) self:Send_Ln( "Exten: " + AllTrim(cExten)) self:Send_Ln( "CallerID: " + AllTrim(cCallerID)) self:Send_Ln( "Priority: " + AllTrim(cPriority)) self:Send_Ln( "Async: " + AllTrim(cAsync)) self:Send_Ln() cText := self:oSocket:GetRaw() WB("MakeCall:", cText) cText := self:oSocket:GetRaw() WB("MakeCall2:", cText) ======================================================= method Send_Ln(cText) class Asterisk_Manager local nLength as dword local cMsg as string local ptrMsg as ptr Default(@cText, "") cMsg := cText + CRLF nLength := SLen(cMsg) ptrMsg := String2Psz(cMsg) self:oSocket:SendRaw( ptrMsg, nLength) access NumSocket() class cSocket return self:nSocket ======================================================= func WB(cCaption, cMessage) local oWB as Warningbox oWB := WarningBox{goShell, cCaption, cMessage} oWB:Show() return nil ======================================================= END =======================================================
|
Pages: 1 Prev: News from GrafXsoft Next: Vulcan Advantages (was Choice SQL Database) |