Ejemplo n.º 1
0
    def __init__(self, url=None, allow_exception=False):
        """
        :param url: URL of the Wwise Authoring API WAMP server, defaults to ws://127.0.0.1:8080/waapi
        :type: str
        :param allow_exception: Allow errors on call and subscribe to throw an exception. Default is False.
        :type allow_exception: bool
        :raises: CannotConnectToWaapiException
        """
        super(WaapiClient, self).__init__()

        self._allow_exception = allow_exception
        self._url = url or "ws://127.0.0.1:8080/waapi"
        self._client_thread = None
        """:type: Thread"""

        self._loop = asyncio.get_event_loop()
        if not self._loop.is_running():
            if not self._loop.is_closed():
                self._loop.close()
            if platform == 'win32':
                #  Prefer the ProactorEventLoop event loop on Windows
                self._loop = asyncio.ProactorEventLoop()
            else:
                self._loop = asyncio.new_event_loop()
            asyncio.set_event_loop(self._loop)

        self._decoupler = None
        """:type: AutobahnClientDecoupler"""

        self._subscriptions = set()
        """:type: set[EventHandler]"""

        # Connect on instantiation (RAII idiom)
        if not self.__connect():
            raise CannotConnectToWaapiException("Could not connect to " + self._url)
Ejemplo n.º 2
0
    def disconnect(self):
        """
        Gracefully disconnect from the Waapi server.

        :return: True if the call caused a successful disconnection, False otherwise.
        :rtype: bool
        """
        if self.is_connected() and self.__do_request(WampRequestType.STOP):
            # Wait for the runner thread to gracefully exit and the asyncio loop to close
            if self._client_thread.is_alive():
                self._client_thread.join()

            self._subscriptions.clear()  # No need to unsubscribe, subscriptions will be dropped anyways

            # Create a new loop for upcoming uses
            if asyncio.get_event_loop().is_closed():
                asyncio.set_event_loop(asyncio.new_event_loop())

            return True

        # Only the caller that truly caused the disconnection return True
        return False
Ejemplo n.º 3
0
    def disconnect(self):
        """
        Gracefully disconnect from the Waapi server.

        :return: True if successfully disconnected, False otherwise.
        :rtype: bool
        """
        if not self.is_connected():
            return False

        self.__do_request(WampRequestType.STOP)
        self._subscriptions.clear(
        )  # No need to unsubscribe, subscriptions will be dropped anyways

        # Wait for the runner thread to gracefully exit and the asyncio loop to close
        self._client_thread.join()

        assert (asyncio.get_event_loop().is_closed())
        # Create a new loop for upcoming uses
        asyncio.set_event_loop(asyncio.new_event_loop())

        return True
    def onDisconnect(self):
        self._log("The client was disconnected.")

        # Stop the asyncio loop, ultimately stopping the runner thread
        asyncio.get_event_loop().stop()