feat: streaming via socket io and redis
This commit is contained in:
49
worker.py
Normal file
49
worker.py
Normal file
@@ -0,0 +1,49 @@
|
||||
import sched
|
||||
from threading import Thread
|
||||
|
||||
from redis import Redis
|
||||
|
||||
# from control.walle import WallE
|
||||
from control.camera import Camera
|
||||
|
||||
INTERVAL_TICK = 0.05 # 20/s
|
||||
INTERVAL_IMAGE = 0.05 # 20/s
|
||||
|
||||
|
||||
class EventListener(Thread):
|
||||
def __init__(self):
|
||||
super(EventListener, self).__init__()
|
||||
self.dbcon = Redis()
|
||||
self.pubsub = self.dbcon.pubsub()
|
||||
self.pubsub.subscribe(['move', 'look'])
|
||||
|
||||
def run(self) -> None:
|
||||
for item in self.pubsub.listen():
|
||||
channel = item['channel'].decode()
|
||||
data = item['data']
|
||||
print(channel)
|
||||
print(data)
|
||||
|
||||
|
||||
scheduler = sched.scheduler()
|
||||
camera = Camera()
|
||||
|
||||
|
||||
def walle_tick():
|
||||
pass
|
||||
|
||||
|
||||
def camera_image():
|
||||
scheduler.enter(INTERVAL_IMAGE, 1, camera_image)
|
||||
image = camera.get_image()
|
||||
redisdb.publish('image', image)
|
||||
|
||||
|
||||
scheduler.enter(INTERVAL_TICK, 1, walle_tick)
|
||||
scheduler.enter(INTERVAL_IMAGE, 1, camera_image)
|
||||
|
||||
if __name__ == '__main__':
|
||||
redisdb = Redis()
|
||||
event_listener = EventListener()
|
||||
event_listener.start()
|
||||
scheduler.run()
|
||||
Reference in New Issue
Block a user