The first major problem is that the application works with the debugger turned on, however, when debugging is disabled it does not work.
The second problem is that when using module to improve the code the call is performed but it presents an error in the command line of the call (SIP :: MakeCall), but when carrying out the direct call of the functions of the library everything happens well, the call is and the code runs normally.
Can anyone help?
The Library (pjsipDll_notls.dll) can be found at: https://github.com/pavram/sipeksdk
IN TIME: This library makes VoIP calls using an Asterisk server or account.
Code: Select all
EnableExplicit
DeclareModule SIP
#PJ_SUCCESS = 0
#PJ_TRUE = 1
#PJ_FALSE = 0
#SIP_OK = 200
#SIP_FORBIDDEN = 403
Enumeration 1;-CallStates
#Calling
#IncoingCall
#RingingUp
#Attended
#StopingCalling
#HungUp
EndEnumeration
Enumeration 1
#Register
#State
#Incomming
#Hold
#Received
#Status
#DTMFDigit
#Waiting
EndEnumeration
Structure cfg
domain.s
port.i
protocol.s
name.s
username.s
password.s
proxy.s
isdefault.i
uri.s
reguri.s
EndStructure
Global cfg.cfg
Global RegisterAccount, getNumOfCodecs, GetCodec, MakeCall, AnswerCall, HoldCall
Global *onRegStateCallback, *onCallStateCallback, *onCallIncoming, *onCallHoldConfirmCallback, *onMessageReceivedCallback, *onBuddyStatusChangedCallback,
*onDtmfDigitCallback, *onMessageWaitingCallback
Prototype.i dll_RegisterAccount(uri.p-ascii, reguri.p-ascii, name.p-ascii, username.p-ascii, password.p-ascii, proxy.p-ascii, isdefault.i)
Prototype.i dll_makeCall(accountId.i, uri.p-ascii)
Prototype.s dll_getCodec(index.i)
Prototype.i dll_getNumOfCodecs()
Prototype.i dll_answerCall(callId.i, code.i)
Prototype.i dll_holdCall(callId.i)
Declare Init()
Declare Destroy()
Declare SetSIPCallBack(target.i, function.i)
; Declare Register()
Declare getNumCodecs()
; Declare.s getCodec_(index.i)
Declare Call(accountId.i, uri.s)
Declare SetAccount(domain.s,port.i,protocol.s,name.s,username.s,password.s,proxy.s="",isdefault.i=#True)
; -NOT WORK in DeclareModule
; PJSIP:
; IncludeBinary "pjsipDll_notls.dll"
; PJSIPEnd:
;
EndDeclareModule
Module SIP
Procedure Init()
; Shared PJSIPLib.i
; OpenFile(0,(GetTemporaryDirectory()+"pjsipDll_notls.dll"))
; WriteData(0,?PJSIP,(?PJSIPend-?PJSIP)):CloseFile(0)
; OpenLibrary(0,(GetTemporaryDirectory()+"pjsipDll_notls.dll"))
; CompilerIf #PB_Compiler_Debugger
PJSIPLib = OpenLibrary(0, "pjsipDll_notls.dll")
; CompilerElse
; PJSIPLib = OpenLibrary(0, GetTemporaryDirectory()+"pjsipDll_notls.dll")
; CompilerEndIf
Debug PJSIPLib
If PJSIPLib
CompilerIf #PB_Compiler_Debugger
ExamineLibraryFunctions(0)
While NextLibraryFunction()
Debug LibraryFunctionName()
Wend
CompilerEndIf
;-Prototype
RegisterAccount.dll_registerAccount = GetFunction(0, "dll_registerAccount");(char* uri, char* reguri, char* name, char* username, char* password, char* proxy, bool isdefault);
getNumOfCodecs.dll_getNumOfCodecs = GetFunction(0, "dll_getNumOfCodecs") ;();
GetCodec.dll_getCodec = GetFunction(0, "dll_getCodec") ;(int index, char* codec);
MakeCall.dll_makeCall = GetFunction(0, "dll_makeCall") ;(int accountId, char* uri);
AnswerCall.dll_answerCall = GetFunction(0, "dll_answerCall") ;(int callId, int code);
HoldCall.dll_holdCall = GetFunction(0, "dll_holdCall") ;(int callId);
;// Callback registration
*onRegStateCallback = GetFunction(0, "onRegStateCallback") ;(fptr_regstate cb); // register registration notifier
*onCallStateCallback = GetFunction(0, "onCallStateCallback") ;(fptr_callstate cb); // register call notifier
;*onCallIncoming = GetFunction(0, "onCallIncoming");(fptr_callincoming cb) ; // register incoming call notifier
*onCallIncoming = GetFunction(0, "onCallIncoming") ;(fptr_callincoming cb); // register incoming call notifier
*onCallHoldConfirmCallback = GetFunction(0, "onCallHoldConfirmCallback") ;(fptr_callholdconf cb); // register call notifier
;//GetFunction(0, "onCallRetrieveConfirm(fptr_callretrieveconf cb) ; // register call notifier
*onMessageReceivedCallback = GetFunction(0, "onMessageReceivedCallback") ;(fptr_msgrec cb); // register call notifier
*onBuddyStatusChangedCallback = GetFunction(0, "onBuddyStatusChangedCallback");(fptr_buddystatus cb); // register call notifier
*onDtmfDigitCallback = GetFunction(0, "onDtmfDigitCallback") ;(fptr_dtmfdigit cb); // register dtmf digit notifier
*onMessageWaitingCallback = GetFunction(0, "onMessageWaitingCallback") ;(fptr_mwi cb); // register MWI notifier
*onCallReplaced = GetFunction(0, "onCallReplaced") ;(fptr_crep cb); // register Call replaced notifier
;// pjsip common API
*dll_setSipConfig = GetFunction(0, "dll_setSipConfig") ;(SipConfigStruct* config);
*dll_init = GetFunction(0, "dll_init")
*dll_shutdown = GetFunction(0, "dll_shutdown")
*dll_main = GetFunction(0, "dll_main") ;(void);
*dll_setCodecPriority = GetFunction(0, "dll_setCodecPriority") ;(char* name, int index);
;// pjsip call API
*dll_releaseCall = GetFunction(0, "dll_releaseCall") ;(int callId);
*dll_retrieveCall = GetFunction(0, "dll_retrieveCall") ;(int callId);
*dll_xferCall = GetFunction(0, "dll_xferCall") ;(int callid, char* uri);
*dll_xferCallWithReplaces = GetFunction(0, "dll_xferCallWithReplaces") ;(int callId, int dstSession);
*dll_serviceReq = GetFunction(0, "dll_serviceReq") ;(int callId, int serviceCode, const char* destUri);
*dll_dialDtmf = GetFunction(0, "dll_dialDtmf") ;(int callId, char* digits, int mode);
*dll_removeAccounts = GetFunction(0, "dll_removeAccounts")
*dll_sendInfo = GetFunction(0, "dll_sendInfo") ;(int callid, char* content);
*dll_getCurrentCodec = GetFunction(0, "dll_getCurrentCodec") ;(int callId, char* codec);
*dll_makeConference = GetFunction(0, "dll_makeConference") ;(int callId);
*dll_sendCallMessage = GetFunction(0, "dll_sendCallMessage") ;(int callId, char* message);
;// IM & Presence api
*dll_addBuddy = GetFunction(0, "dll_addBuddy") ;(char* uri, bool subscribe);
*dll_removeBuddy = GetFunction(0, "dll_removeBuddy") ;(int buddyId);
*dll_sendMessage = GetFunction(0, "dll_sendMessage") ;(int accId, char* uri, char* message);
*dll_setStatus = GetFunction(0, "dll_setStatus") ;(int accId, int presence_state);
*dll_setSoundDevice = GetFunction(0, "dll_setSoundDevice") ;(char* playbackDeviceId, char* recordingDeviceId);
*dll_pollForEvents = GetFunction(0, "dll_pollForEvents") ;(int timeout);
CallCFunctionFast(*dll_init)
CallCFunctionFast(*dll_main)
Else
MessageRequester("Attention!", "pjsipDll_notls.dll Not loaded!", #PB_MessageRequester_Error)
End
EndIf
EndProcedure
Procedure getNumCodecs()
ProcedureReturn getNumOfCodecs()
EndProcedure
; Procedure.s getCodec_(index.i)
; *buffer = UTF8(getCodec(index))
; ProcedureReturn PeekS(*buffer)
; EndProcedure
Procedure SetAccount(domain.s,port.i,protocol.s,name.s,username.s,password.s,proxy.s="",isdefault.i=#True)
cfg\domain = domain
cfg\port = port
cfg\protocol = protocol
cfg\name = name
cfg\username = username
cfg\password = password
cfg\proxy = proxy
cfg\isdefault = isdefault
cfg\uri = "sip:" + cfg\username + "@" + cfg\domain
cfg\reguri = cfg\uri + ":" + Str( cfg\port ) + ";transport=" + cfg\protocol
EndProcedure
Procedure Destroy()
If IsLibrary(0): CloseLibrary(0): EndIf
Delay(100)
If FileSize(GetTemporaryDirectory()+"pjsipDll_notls.dll") > 0
DeleteFile(GetTemporaryDirectory()+"pjsipDll_notls.dll")
EndIf
EndProcedure
Procedure SetSIPCallBack(target.i, function.i)
Select target
Case #Register
CallCFunctionFast(*onRegStateCallback, @function)
Case #State
CallCFunctionFast(*onCallStateCallback, @function)
Case #Incomming
CallCFunctionFast(*onCallIncoming, @function)
Case #Hold
CallCFunctionFast(*onCallHoldConfirmCallback, @function)
Case #Received
CallCFunctionFast(*onMessageReceivedCallback, @function)
Case #Status
CallCFunctionFast(*onBuddyStatusChangedCallback, @function)
Case #DTMFDigit
CallCFunctionFast(*onDtmfDigitCallback, @function)
Case #Waiting
CallCFunctionFast(*onMessageWaitingCallback, @function)
EndSelect
EndProcedure
; Procedure Register()
; ProcedureReturn RegisterAccount(cfg\uri, cfg\reguri, cfg\name, cfg\username, cfg\password, cfg\proxy, cfg\isdefault)
; EndProcedure
Procedure Call(accountId.i, uri.s)
MakeCall(accountId, uri)
EndProcedure
EndModule
;-TEST
CompilerIf #PB_Compiler_IsMainFile
; UseModule SIP
Structure reg
accountId.i
regState.i
stateName.s
EndStructure
Global Dim reg.reg(1)
Procedure onRegStateChanged(accountId, regState)
Define c
Debug "onRegStateChanged"
Debug accountId
Debug regState
Debug c
Select regState
Case SIP::#SIP_OK
reg(accountId)\accountId = accountId
reg(accountId)\regState = regState
reg(accountId)\stateName = "200 OK"
Case SIP::#SIP_FORBIDDEN
reg(accountId)\accountId = accountId
reg(accountId)\regState = regState
reg(accountId)\stateName = "403 Forbidden"
EndSelect
Debug "Status: " + reg(accountId)\stateName
EndProcedure
Procedure OnCallStateChanged(a, b)
Debug "OnCallStateChanged "
Debug a
Debug b
Select b
Case SIP::#Calling
Debug "Calling"
Case SIP::#IncoingCall
Debug "Incoing Call: " + b
; answerCall(b, 200)
Case SIP::#RingingUp
Debug "Ringing Up"
Case SIP::#Attended
Debug "Attended"
Case SIP::#StopingCalling
Debug "Stoping Calling"
Case SIP::#HungUp
Debug "Hung Up"
Default
Debug "DEFAULT = " + Str(b)
EndSelect
EndProcedure
Procedure onCallIncomingChange(a, *b)
Debug "onCallIncomingChange"
Debug a
Debug *b
Debug PeekS(*b, -1, #PB_UTF8)
EndProcedure
Procedure onCallHoldConfirmCallbackChange(a, b)
Debug "onCallHoldConfirmCallbackChange"
Debug a
Debug b
; Debug PeekS(*b, -1, #PB_UTF8)
EndProcedure
Procedure onMessageReceivedCallbackChange(a, b)
Debug "onMessageReceivedCallbackChange"
Debug a
Debug b
; Debug PeekS(*b, -1, #PB_UTF8)
EndProcedure
Procedure onBuddyStatusChangedCallbackChange(a, b)
Debug "onBuddyStatusChangedCallbackChange"
Debug a
Debug b
; Debug PeekS(*b, -1, #PB_UTF8)
EndProcedure
Procedure onDtmfDigitCallbackChange(a, b)
Debug "onDtmfDigitCallbackChange"
Debug a
Debug b
; Debug PeekS(*b, -1, #PB_UTF8)
EndProcedure
Procedure onMessageWaitingCallbackChange(a, *b)
Protected.s msg
Debug "onMessageWaitingCallbackChange"
Debug a
Debug *b
msg = PeekS(*b, -1, #PB_UTF8)
Debug "msg.....: " + msg
EndProcedure
Procedure onCallReplacedChange(a, b)
Debug "onCallReplaced"
Debug a
Debug b
; Debug PeekS(*b, -1, #PB_UTF8)
EndProcedure
;When you cancel this line the call is performed but it shows error in the MakeCall line
; #SimulateGhostError = #True
Procedure SIPTest()
SIP::Init()
CompilerIf Defined(SimulateGhostError, #PB_Constant)
;{ GHOST ERROR
SIP::SetSIPCallBack(SIP::#Register, @onRegStateChanged())
SIP::SetSIPCallBack(SIP::#State, @OnCallStateChanged())
SIP::SetSIPCallBack(SIP::#Incomming, @onCallIncomingChange())
SIP::SetSIPCallBack(SIP::#Hold, @onCallHoldConfirmCallbackChange())
SIP::SetSIPCallBack(SIP::#Received, @onMessageReceivedCallbackChange())
SIP::SetSIPCallBack(SIP::#Status, @onBuddyStatusChangedCallbackChange())
SIP::SetSIPCallBack(SIP::#DTMFDigit, @onDtmfDigitCallbackChange())
SIP::SetSIPCallBack(SIP::#Waiting, @onMessageWaitingCallbackChange())
;}
CompilerElse
CallCFunctionFast(SIP::*onRegStateCallback, @onRegStateChanged())
CallCFunctionFast(SIP::*onCallStateCallback, @OnCallStateChanged())
CallCFunctionFast(SIP::*onCallIncoming, @onCallIncomingChange())
CallCFunctionFast(SIP::*onCallHoldConfirmCallback, @onCallHoldConfirmCallbackChange())
CallCFunctionFast(SIP::*onMessageReceivedCallback, @onMessageReceivedCallbackChange())
CallCFunctionFast(SIP::*onBuddyStatusChangedCallback, @onBuddyStatusChangedCallbackChange())
CallCFunctionFast(SIP::*onDtmfDigitCallback, @onDtmfDigitCallbackChange())
CallCFunctionFast(SIP::*onMessageWaitingCallback, @onMessageWaitingCallbackChange())
CompilerEndIf
Define.i ID, nrCodecs, time
;Format Parameters
;
;uri.p-ascii = "sip:username@ip_or_domain"
;reguri.p-ascii = "sip:username@ip_or_domain:port;transport=udp"
;name.p-ascii = "name_account or * (example)"
;username.p-ascii = "username"
;password.p-ascii = "passwords"
;proxy.p-ascii = "ip_or_domaind or "" (example)"
;isdefault.i = #true or #false
ID = SIP::RegisterAccount("sip:1000@your_asterisk_domain.myvnc.com", "sip:1000@your_asterisk_domain.myvnc.com:5060;transport=udp", "*", "1000", "1234", "",#True);-Example
Debug "ID: " + Str(ID)
If ID > 0
ReDim reg.reg(ID)
nrCodecs = SIP::getNumCodecs()
Debug "Number of Codecs: " + Str(nrCodecs)
SIP::MakeCall(ID, "sip:1001@your_asterisk_domain.myvnc.com")
For time=1 To 10000
Delay(1)
Next
Else
MessageRequester("Error", "Error")
EndIf
SIP::Destroy()
EndProcedure
SIPTest()
CompilerEndIf
If anyone can help, I will be very grateful and happy.
Reading the PJSIP license well it could turn into an official PB library in the future.