# Path: irisett/event.py
# class EventListener:
# class EventTracer:
#     def __init__(self, tracer: 'EventTracer', callback: Callable, *,
#                  event_filter: Optional[List[str]] = None,
#                  active_monitor_filter: Optional[List[Union[str, int]]] = None) -> None:
#     def set_event_filter(self, filter: Optional[List]) -> None:
#     def set_active_monitor_filter(self, filter: Optional[List]) -> None:
#     def _parse_active_monitor_filter(filter: Optional[List]) -> Any:
#     def _parse_filter_list(filter: Optional[List]) -> Any:
#     def wants_event(self, event_name: str, args: Dict) -> bool:
#     def __init__(self) -> None:
#     def listen(self, callback: Callable, *,
#                event_filter: Optional[List[str]] = None,
#                active_monitor_filter: Optional[List[Union[str, int]]] = None) -> EventListener:
#     def stop_listening(self, listener: EventListener) -> None:
#     def running(self, event_name: str, **kwargs: Any) -> None:


from typing import Any, Optional
from aiohttp import web
from irisett import (
    event,
)
import asyncio
import aiohttp
import json
            event.stop_listening(self.listener)
            self.listener = None
            if not self.ws.closed:
                self.ws.close()

    async def _ws_read(self) -> None:
        if not self.listener:
            return
        # noinspection PyTypeChecker
        async for msg in self.ws:
            if msg.type == aiohttp.WSMsgType.TEXT:
                data = json.loads(msg.data)
                if data['cmd'] == 'start':
                    self.client_started = True
                elif data['cmd'] == 'stop':
                    self.client_started = False
                elif data['cmd'] == 'event_filter':
                    self.listener.set_event_filter(data['filter'])
                elif data['cmd'] == 'active_monitor_filter':
                    self.listener.set_active_monitor_filter(data['filter'])
            elif msg.type in [aiohttp.WSMsgType.CLOSE, aiohttp.WSMsgType.CLOSED, aiohttp.WSMsgType.ERROR]:
                break
            else:
                break
        self.running = False

    async def _handle_events(self, listener: event.EventListener, event_name: str, timestamp: int, data: Any) -> None:
        if not self.client_started:
            return
        if not self.running or self.ws.closed:

# Path: irisett/event.py
# class EventListener:
# class EventTracer:
#     def __init__(self, tracer: 'EventTracer', callback: Callable, *,
#                  event_filter: Optional[List[str]] = None,
#                  active_monitor_filter: Optional[List[Union[str, int]]] = None) -> None:
#     def set_event_filter(self, filter: Optional[List]) -> None:
#     def set_active_monitor_filter(self, filter: Optional[List]) -> None:
#     def _parse_active_monitor_filter(filter: Optional[List]) -> Any:
#     def _parse_filter_list(filter: Optional[List]) -> Any:
#     def wants_event(self, event_name: str, args: Dict) -> bool:
#     def __init__(self) -> None:
#     def listen(self, callback: Callable, *,
#                event_filter: Optional[List[str]] = None,
#                active_monitor_filter: Optional[List[Union[str, int]]] = None) -> EventListener:
#     def stop_listening(self, listener: EventListener) -> None:
#     def running(self, event_name: str, **kwargs: Any) -> None:


# Path: irisett/webmgmt/ws_event_proxy.py
from typing import Any, Optional
from aiohttp import web
from irisett import (
    event,
)
import asyncio
import aiohttp
import json

            event.stop_listening(self.listener)
            self.listener = None
            if not self.ws.closed:
                self.ws.close()

    async def _ws_read(self) -> None:
        if not self.listener:
            return
        # noinspection PyTypeChecker
        async for msg in self.ws:
            if msg.type == aiohttp.WSMsgType.TEXT:
                data = json.loads(msg.data)
                if data['cmd'] == 'start':
                    self.client_started = True
                elif data['cmd'] == 'stop':
                    self.client_started = False
                elif data['cmd'] == 'event_filter':
                    self.listener.set_event_filter(data['filter'])
                elif data['cmd'] == 'active_monitor_filter':
                    self.listener.set_active_monitor_filter(data['filter'])
            elif msg.type in [aiohttp.WSMsgType.CLOSE, aiohttp.WSMsgType.CLOSED, aiohttp.WSMsgType.ERROR]:
                break
            else:
                break
        self.running = False

    async def _handle_events(self, listener: event.EventListener, event_name: str, timestamp: int, data: Any) -> None:
        if not self.client_started:
            return
        if not self.running or self.ws.closed:

            event.stop_listening(listener)