summaryrefslogtreecommitdiffstats
path: root/notFinishedCode/landlineCall.py
diff options
context:
space:
mode:
Diffstat (limited to 'notFinishedCode/landlineCall.py')
-rw-r--r--notFinishedCode/landlineCall.py76
1 files changed, 48 insertions, 28 deletions
diff --git a/notFinishedCode/landlineCall.py b/notFinishedCode/landlineCall.py
index 76565f1..58ad851 100644
--- a/notFinishedCode/landlineCall.py
+++ b/notFinishedCode/landlineCall.py
@@ -6,13 +6,15 @@ import string
server = "sipgate.de"
username = "1289459"
password = "MMW9AX"
-number = "00497612034661449"
+number = "00497612034661455"
LOG_LEVEL = 2
current_call = None
-isDisconnected = False
+is486 = False
isConfirmed = False
isRinging = False
+isConnected = False
+TIMEOUT_LIMIT = 30
userInput = ""
# Logging callback
@@ -35,30 +37,28 @@ class MyCallCallback(pj.CallCallback):
def on_state(self):
global current_call
global isConfirmed
- global isDisconnected
+ global isConnected
global isRinging
-
-
- if self.call.info().state == pj.CallState.NULL:
- print "CALL NOT INITIALIZED"
+ global is486
if self.call.info().state == pj.CallState.CALLING:
- print "TRYING TO CALL"
-
- if self.call.info().state == pj.CallState.CONNECTING:
- print "CONNECTING"
+ print "CALLING..."
+ if self.call.info().last_code == 486:
+ is486 = True
+
if self.call.info().state == pj.CallState.EARLY:
- print "CALLEE IS RINGING"
isRinging = True
if self.call.info().state == pj.CallState.CONFIRMED:
isConfirmed = True
+ isConnected = True
+ isRinging = False
if self.call.info().state == pj.CallState.DISCONNECTED:
current_call = None
- isDisconnected = True
- isConfirmed = False
+ isConnected = False
+
def make_call(uri):
try:
@@ -87,32 +87,52 @@ print "You want to call then."
while userInput <> "quit":
- timeCounter = 0
+
+ timeCounterRinging = 0
+ firstTimeRinging = True
if acc.info().reg_status < 700:
numberToCall = "sip:"+number+"@"+server
current_call = make_call(numberToCall)
while 1:
- if isConfirmed and isDisconnected == False:
+
+ if isRinging:
sleep(1)
- timeCounter = timeCounter + 1
-
- if isConfirmed == False and isDisconnected:
- print "THE NUMBER THAT YOU'VE DIALLED IS EITHER BUSY OR OFFLINE"
+ timeCounterRinging = timeCounterRinging + 1
+ if firstTimeRinging:
+ print "RINGING..."
+ firstTimeRinging = False
+ if is486:
+ print "THE NUMBER THAT YOU'VE DIALLED IS BUSY!!"
isConfirmed = False
- isDisconnected = False
- break
+ isConnected = False
+ isRinging = False
+ is486 = False
+ break
- if timeCounter == 12 and isDisconnected == False:
+ if isConnected and isConfirmed:
+ print "CALL SUCCESSFULLY ESTABLISHED!!"
+ sleep(5)
current_call.hangup()
- print "CALL SUCCESSFULLY ESTABLISHED AND TERMNIATED"
+ print "CALL SUCCESSFULLY TERMINATED!!"
+ isConfirmed = False
+ isConnected = False
+ isRinging = False
+ is486 = False
+ break
+
+ if timeCounterRinging == TIMEOUT_LIMIT and isRinging:
+ current_call.hangup()
+ print "THE NUMBER THAT YOU'VE DIALLED IS NOT ANSWERING!!"
isConfirmed = False
- isDisconnected = False
+ isConnected = False
+ isRinging = False
+ is486 = False
break
else:
- print "REGISTRATION ERROR"
+ print "REGISTRATION ERROR!!!"
lib.destroy()
lib = None
acc = None
@@ -120,10 +140,10 @@ while userInput <> "quit":
userInput = sys.stdin.readline().rstrip("\r\n")
sleep(2)
-print "Deleting library and account info..."
+print "LOGGING OUT..."
acc.delete()
lib.destroy()
lib = None
acc = None
-print "Deleting was successful!"
+print "LOGOUT WAS SUCCESSFULL!!"