-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
209 lines (159 loc) · 4.07 KB
/
main.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
203
204
205
206
207
208
209
from flask import Flask, request, render_template, send_from_directory
import random
global meetings
meetings = {}
global call, ans, ice
call, ans, ice = None, None, None
app = Flask(__name__)
@app.route('/')
def index():
return render_template('index.html')
@app.route('/Share')
def sender():
return render_template('Share.html')
@app.route('/Receive')
def receiver():
return render_template('Receive.html')
@app.route('/Closed')
def closed():
return render_template('Closed.html')
@app.route('/Help')
def help():
return render_template('Help.html')
@app.route('/assets/<path:path>')
def send_report(path):
return send_from_directory('assets', path)
#Using Bulma 0.7.2 and Jquery 1.10.2
@app.route('/getId')
def getId():
global meetings
SDP = request.args.get("sdp")
#ICE = request.args.get("ice")
assert SDP != ''
#assert ICE != ''
while True:
MeetingId = str(random.randint(100, 999))
try:
meetings[MeetingId]
continue
except KeyError:
break
meetings[MeetingId] = {'sdp': SDP, 'ice': '', 'ans': None}
print("New meeting: " + MeetingId)
print(SDP)
#print(ICE)
return MeetingId
@app.route('/connectId')
def connectId():
global meetings
MeetingId = request.args.get("id")
try:
return meetings[MeetingId]['sdp']
except KeyError:
return "None"
@app.route('/sendAns')
def sendAns():
global meetings
MeetingId = request.args.get('id')
ICE = request.args.get('ice')
Ans = request.args.get('ans')
assert Ans != ''
assert ICE != ''
assert MeetingId != ''
meetings[MeetingId]['ans'] = Ans
meetings[MeetingId]['ice'] += ICE + "\n"
return "Sent"
@app.route('/checkAns')
def checkAns():
global meetings
MeetingId = request.args.get("id")
print(MeetingId)
try:
if meetings[MeetingId]['ans'] == None:
return "wait"
else:
return meetings[MeetingId]['ans']
except KeyError:
return "wait"
@app.route('/getIce')
def getIce():
global meetings
MeetingId = request.args.get("id")
if meetings[MeetingId]['ice'] == '':
return "wait"
else:
return meetings[MeetingId]['ice']
app.run(host='0.0.0.0', port=81)
#Old code when I was trying out stuff
'''@app.route('/ICUCast')
def senderICU():
return render_template('Share2.html')
@app.route('/S')
def sender2():
return render_template('S.html')
@app.route('/R')
def receiver2():
return render_template('R.html')
@app.route('/test')
def test():
return render_template('test.html')
@app.route('/getName')
def whoami():
return "3 Charity Integrated Classroom Unit"
@app.route('/dashboard')
def dashboard():
return render_template('Dashboard.html')
@app.route('/connect')
def connect():
global call
if request.args.get('sdp') != None:
call = request.args.get('sdp')
return "sent"
else:
return "missing ans"
@app.route('/getAns')
def getAns():
global ans
if ans != None:
return ans
else:
return "no ans"
@app.route('/getIce2')
def getIce2():
global ice
if ice != None:
return ice
else:
return "no ice"
@app.route('/getCall')
def getCall():
global call
if call != None:
return call
else:
return "no call"
@app.route('/sendAns2')
def sendAns2():
if True:
global ans, ice
if request.args.get('ans') == None:
return "missing ans"
elif request.args.get('ice') == None:
return "missing ice"
else:
ice = request.args.get('ice')
ans = request.args.get('ans')
return "wait for client"
else:
return "You are not authorised to visit this page."
@app.route('/clearConn')
def clearConnections():
if True:
global call, ans, ice
call, ans, ice = None, None, None
return "Done"
else:
return "You are not authorised to visit this page."
@app.route('/ICUClosed')
def ICUClosed():
return render_template("Closed2.html")'''