dkumor / rtcbot

A python WebRTC remote control library
https://rtcbot.readthedocs.io/en/latest/?badge=latest
MIT License
70 stars 30 forks source link

Implemented ProcessSubscriptionConsumer #37

Closed henriksod closed 2 years ago

henriksod commented 2 years ago

Implemented ProcessSubscriptionConsumer. Tested and working on Linux, Python3.8, using the following example:

import logging
import asyncio

from rtcbot.base import ProcessSubscriptionConsumer, SubscriptionClosed
from rtcbot.subscriptions import MostRecentSubscription

class TestProcessSubscriptionConsumer(ProcessSubscriptionConsumer):

    _log = logging.getLogger("rtcbot.TestProcessSubscriptionConsumer")

    def __init__(self, loop=None):

        self._loop = loop
        if self._loop is None:
            self._loop = asyncio.get_event_loop()

        super().__init__(
            directPutSubscriptionType=MostRecentSubscription,
            logger=self._log,
            loop=self._loop,
        )

    def _consumer(self):

        self._log.info("Started TestProcessSubscriptionConsumer")

        self._setReady(True)
        while not self._shouldClose:
            try:
                data = self._get()
                self._log.info(data)

            except SubscriptionClosed:
                pass

        self._setReady(False)
        self._log.info("Ended TestProcessSubscriptionConsumer")