-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathprojectfinal.py
204 lines (89 loc) · 3.65 KB
/
projectfinal.py
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
# SIP Client (Soft phone prototype)
# Created by Arpit Singh
# Run the server before running this file "$sudo asterisk -r" in other terminal
#In user URI enter only the Called user name
import sys
import pjsua as pj
import threading
import time
# Log of callback class
def log_cb(level, str, len):
print(str),
# Account Callback class to get notifications of Account registration
class MyAccountCallback(pj.AccountCallback):
def __init__(self, acc):
pj.AccountCallback.__init__(self, acc)
# Call Callback to receive events from Call
class SRCallCallback(pj.CallCallback):
def __init__(self, call=None):
pj.CallCallback.__init__(self, call)
def on_state(self):
print("Call is :", self.call.info().state_text),
print("last code :", self.call.info().last_code),
print("(" + self.call.info().last_reason + ")")
# Notification when call's media state is changed
def on_media_state(self):
global lib
if self.call.info().media_state == pj.MediaState.ACTIVE:
# Connect the call to sound device
call_slot = self.call.info().conf_slot
lib.conf_connect(call_slot, 0)
lib.conf_connect(0, call_slot)
print("Hey !!!!! Can you hear me !!!!!!!!!!")
print (lib)
# Main loop
try:
# Start of the Main Class
# Create library instance of Lib class
lib = pj.Lib()
# Instantiate library with default config
lib.init(log_cfg = pj.LogConfig(level=3, callback=log_cb))
# Configuring one Transport Object and setting it to listen at 5060 port and UDP protocol
trans_conf = pj.TransportConfig()
print "____________________REGISTRATION PROCESS BEGINS_______________________"
print "\n\n"
# 12345 is default port for SIP
trans_conf.port = 12345
# Here the client address is same as the Servers Address
a=raw_input("Please Enter the IP address of the Client: ")
print "Not Using the default port number, Instead using: 12345"
trans_conf.bound_addr = a
transport = lib.create_transport(pj.TransportType.UDP,trans_conf)
# Starting the instance of Lib class
lib.start()
lib.set_null_snd_dev()
# Configuring Account class to register with Registrar server
# Giving information to create header of REGISTER SIP message
# Hardcoded these values
ab4="192.168.131.152" # Server's address
ab='2020' # This clients User name
ab1="password" # Password same as "password"
ab2='y'
ab3=ab
acc_conf = pj.AccountConfig(domain = ab4, username = ab, password =ab1, display = ab3)
# registrar = 'sip:'+ab4+':5060', proxy = 'sip:'+ab4+':5060')
acc_conf.id ="sip:"+ab
acc_conf.reg_uri ='sip:'+ab4+':12345'
acc_callback = MyAccountCallback(acc_conf)
acc = lib.create_account(acc_conf,cb=acc_callback)
# creating instance of AccountCallback class
acc.set_callback(acc_callback)
print('\n')
print "Registration Complete-----------"
print('Status= ',acc.info().reg_status, \
'(' + acc.info().reg_reason + ')')
# Starting Calling process.
b=raw_input("Enter the username to be called: ")
#sip and address are hard coded here
b1="sip:"+ str(b)+"@192.168.0.1:5066"
call = acc.make_call(b1, SRCallCallback())
print('Press <ENTER> to exit and destroy library')
input = sys.stdin.readline().rstrip('\r\n')
# Shutting down the library
lib.destroy()
lib = None
except pj.Error, e:
print("Exception, error occured at : " + str(e))
lib.destroy()
lib = None
sys.exit(1)