summaryrefslogtreecommitdiffstats
path: root/For Weekly Test/20-07-2011/localsipReceiver.py
blob: 5739af2c6cc0e460852b6214b2d3f93ba6a3b8b9 (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
import sys
import pjsua as pj
import classServer
from time import sleep



def log_cb(level, str, len):
    print str, "SIP Handler Receiver Log"


class MyAccountCallback(pj.AccountCallback):

	def on_incoming_call(self, call):

		current_call = call
		print current_call
		
		sleep(1)
		call.answer(200)

		sleep(0.5)

		if current_call <> None:
			print "hangup the call"
			call.hangup()
		
		print "send result"
		server.sendData('200')

        
lib = pj.Lib()
stop = False

try:
	
	server = classServer.ServerHandler(50107)
	tried = server.openSocket()
	
	lib.init(log_cfg = pj.LogConfig(level=1, 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("132.230.252.228", "4976120397897", "hB8M3WyFt61C")
    		acc = lib.create_account(acc_cfg, cb=MyAccountCallback())
		print acc.info().reg_status
		if acc.info().reg_status < 700:

			server.sendData('ready')
			server.closeConnection()
			tried = server.openSocket()
    			while stop <> True:
			
				data = server.receiveData(0)

				if data == "487":
					stop = True
					break
				sleep(3)

    			transport = None
    			acc.delete()
    			acc = None
    			lib.destroy()
    			lib = None
			server.closeConnection()
			
		else:
			print "Bad Register"

			lib.destroy()
			lib = None
    			acc = None
			server.closeConnection()
			

	except pj.Error, e:
		print "401 Unauthorized " +str(e)
    		lib.destroy()
    		lib = None
    		server.closeConnection()
    		

except pj.Error, e:
    print "Exception: " + str(e)
    lib.destroy()
    lib = None
    server.closeConnection()
    del server