summaryrefslogtreecommitdiffstats
path: root/For Weekly Test/Backup/landlineReceiver.py
blob: 22ae8725853d57a880decbcc5e3d51a942af2363 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import sys
import pjsua as pj
from time import sleep
import string

server = "sipgate.de"
username = "1289459"
password = "MMW9AX"
current_call = None
incomingCallNumber = ""

LOG_LEVEL=2
userInput = ""

# Logging callback
def log_cb(level, str, len):
    print str,


# Callback to receive events from account
class MyAccountCallback(pj.AccountCallback):

    def __init__(self, account=None):
        pj.AccountCallback.__init__(self, account)

# Notification on incoming call
    def on_incoming_call(self, call):
        global current_call

        if current_call:
            call.answer(486, "Busy")
            return
            
        incomingCallNumber = call.info().remote_uri
	print "This number "+incomingCallNumber+" is calling."

        current_call = call
        call_cb = MyCallCallback(current_call)
        current_call.set_callback(call_cb)
	current_call.answer(180)

        
# Callback to receive events from Call
class MyCallCallback(pj.CallCallback):
   
    def __init__(self, call=None):
        pj.CallCallback.__init__(self, call)

    # Notification when call state has changed
    def on_state(self):
        global current_call
	
	if self.call.info().state == pj.CallState.CONNECTING:
		print "CONNECTING"
	
	if self.call.info().state == pj.CallState.EARLY:
		print "RINGING"
		
	if self.call.info().state == pj.CallState.CONFIRMED:
		print "CALL CONFIRMED"
        
       	if self.call.info().state == pj.CallState.DISCONNECTED:
       		current_call = None
       		print "CURRENT CALL DISCONNECTED"


lib = pj.Lib()
lib.init(log_cfg = pj.LogConfig(level=LOG_LEVEL, callback=log_cb))
transport = lib.create_transport(pj.TransportType.UDP, pj.TransportConfig(0))
lib.start()
lib.set_null_snd_dev()

try:
	acc_cfg = pj.AccountConfig(server,username,password)	
	acc = lib.create_account(acc_cfg, cb=MyAccountCallback())

except ValueError:    
	print "Exception: " + str(e)

print "You want to receive a call then."
print "Receive another call?"
userInput = sys.stdin.readline().rstrip("\r\n") 

while userInput == "yes":
				
	if acc.info().reg_status < 700:			
		if not current_call:
			continue
    	        else:		
			sleep(5)			
			current_call.answer(200)
			sleep(5)
			current_call.hangup()
			sleep(3)			
			print "Receive another call? "			
			userInput = sys.stdin.readline().rstrip("\r\n") 
						
	else:
		print "REGISTRATION ERROR"
		lib.destroy()
		lib = None
    		acc = None

sleep(2)
print "LOGGING OUT..."
acc.delete()
lib.destroy()
lib = None
acc = None
print "LOGOUT WAS SUCCESSFULL!!"