Skip to content

Commit 984d3a5

Browse files
committed
More stuff
1 parent 93a072d commit 984d3a5

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

main.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,29 @@
11
import asyncio
2-
import aiohttp
32
import json
43
import simpleobsws
54
import liteconfig
5+
import aiohttp
6+
from aiohttp import web
67

78
cfg = liteconfig.Config("config.ini")
9+
loop = asyncio.get_event_loop()
10+
ws = simpleobsws.obsws(host=cfg.obsws.ws_address, port=cfg.obsws.ws_port, password=cfg.obsws.ws_password, loop=loop)
11+
12+
async def handle_emit_request(request):
13+
"""Handler function for all emit-based HTTP requests. Assumes that you know what you are doing because it will never return an error."""
14+
requesttype = request.match_info['type']
15+
requestdata = await request.json()
16+
await ws.emit(requesttype, requestdata)
17+
return web.json_response({'status':'ok'})
18+
19+
async def handle_call_request(request):
20+
"""Handler function for all call-based HTTP requests."""
21+
pass
22+
23+
app = web.Application()
24+
app.add_routes([web.post('/emit/{type}, handle_emit_request), web.post('/call/{type}, handle_call_request)])
25+
loop.run_until_complete(ws.connect())
26+
try:
27+
web.run_app(app)
28+
except KeyboardInterrupt:
29+
print('Shutting down...')

0 commit comments

Comments
 (0)