MySafeCode commited on
Commit
3ef63de
·
verified ·
1 Parent(s): a6f3584

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +48 -0
app.py ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI
2
+ from pydantic import BaseModel
3
+ from datetime import datetime
4
+
5
+ app = FastAPI(title="1HIT RTC Signaling API")
6
+
7
+ # ---------- Data Models ----------
8
+ class Offer(BaseModel):
9
+ offer: str
10
+
11
+ class Answer(BaseModel):
12
+ answer: str
13
+
14
+ class IceCandidate(BaseModel):
15
+ candidate: str
16
+
17
+
18
+ # ---------- Basic Endpoints ----------
19
+ @app.get("/status")
20
+ def status():
21
+ return {"status": "running", "time": datetime.utcnow()}
22
+
23
+
24
+ @app.get("/time")
25
+ def get_time():
26
+ return {"time": datetime.utcnow().strftime("%H:%M:%S UTC")}
27
+
28
+
29
+ @app.post("/echo")
30
+ def echo_message(payload: dict):
31
+ return {"you_sent": payload}
32
+
33
+
34
+ # ---------- RTC Signaling Endpoints ----------
35
+ @app.post("/rtc/offer")
36
+ def rtc_offer(data: Offer):
37
+ # In production: store, forward, or route the offer to another client
38
+ return {"received_offer": data.offer}
39
+
40
+
41
+ @app.post("/rtc/answer")
42
+ def rtc_answer(data: Answer):
43
+ return {"received_answer": data.answer}
44
+
45
+
46
+ @app.post("/rtc/ice")
47
+ def rtc_ice(data: IceCandidate):
48
+ return {"received_candidate": data.candidate}