sekarpdkt / misc Goto Github PK
View Code? Open in Web Editor NEWmisc codes
misc codes
Hello, congratulations for sharing your knowledge, I need help, I need to create a code to make a call and as soon as the call is answered it plays an audio, my code below already does the authentication and when I try to make the call It fails, can you help me solve this problem?
import pjsua2 as pj
import time
# Subclass to extend the Account and get notifications etc.
class Account(pj.Account):
def onRegState(self, prm):
print("***OnRegState: " + prm.reason)
if prm.code == 200:
make_call(self)
# Subclass to handle call events
class MyCall(pj.Call):
def __init__(self, acc, dest_uri):
pj.Call.__init__(self, acc)
self.dest_uri = dest_uri
def on_state(self):
if self.info().state == pj.PJSIP_INV_STATE_CALLING:
print("Chamando", self.dest_uri)
elif self.info().state == pj.PJSIP_INV_STATE_INCOMING:
print("Chamada recebida de", self.info().remote_uri)
self.answer()
elif self.info().state == pj.PJSIP_INV_STATE_EARLY:
pass
elif self.info().state == pj.PJSIP_INV_STATE_CONNECTING:
pass
elif self.info().state == pj.PJSIP_INV_STATE_CONFIRMED:
print("Chamada conectada. Reproduzindo áudio...")
self.start_audio("testeaudio.wav")
elif self.info().state == pj.PJSIP_INV_STATE_DISCONNECTED:
print("Chamada desconectada, motivo:", self.info().last_reason)
self.delete()
# pjsua2 test function
def pjsua2_test():
# Create and initialize the library
ep_cfg = pj.EpConfig()
ep = pj.Endpoint()
ep.libCreate()
ep.libInit(ep_cfg)
# Create SIP transport. Error handling sample is shown
sipTpConfig = pj.TransportConfig()
sipTpConfig.port = 5064
ep.transportCreate(pj.PJSIP_TRANSPORT_UDP, sipTpConfig)
# Start the library
ep.libStart()
acfg = pj.AccountConfig()
acfg.idUri = "sip:[email protected]:5064"
acfg.regConfig.registrarUri = "sip:sbc.dominio.servidor:5064"
cred = pj.AuthCredInfo("digest", "*", "9999", 0, "9999#")
acfg.sipConfig.authCreds.append(cred)
# Create the account
acc = Account()
acc.create(acfg)
# Here we don't have anything else to do..
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
print("Encerrando chamada...")
if acc.calls.count > 0:
call = acc.calls[0]
call.hangup()
time.sleep(2)
ep.libDestroy()
def make_call(account):
dest_uri = "sip:[email protected]:5064" # Ramal 1571
call = MyCall(account, dest_uri)
call.make_call(dest_uri)
#
# main()
#
if __name__ == "__main__":
pjsua2_test()
When I try to make the call I get this error message here.
***OnRegState: OK
Traceback (most recent call last):
File "/app/notifica_voz/call_2.py", line 9, in onRegState
make_call(self)
File "/app/notifica_voz/call_2.py", line 72, in make_call
call.make_call(dest_uri)
AttributeError: 'MyCall' object has no attribute 'make_call'
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.