Exemple #1
0
    def events(self, session_id, handler):
        """
        Listen for session events.

        :param int session_id: id of session
        :param handler: handler for every event
        :return: nothing
        :raises grpc.RpcError: when session doesn't exist
        """
        request = core_pb2.EventsRequest(session_id=session_id)
        stream = self.stub.Events(request)
        start_streamer(stream, handler)
Exemple #2
0
    def events(self, session_id, handler, events=None):
        """
        Listen for session events.

        :param int session_id: id of session
        :param handler: handler for received events
        :param list events: events to listen to, defaults to all
        :return: stream processing events, can be used to cancel stream
        :raises grpc.RpcError: when session doesn't exist
        """
        request = core_pb2.EventsRequest(session_id=session_id, events=events)
        stream = self.stub.Events(request)
        start_streamer(stream, handler)
        return stream
Exemple #3
0
    def events(
        self,
        session_id: int,
        handler: Callable[[core_pb2.Event], None],
        events: List[core_pb2.Event] = None,
    ) -> Any:
        """
        Listen for session events.

        :param session_id: id of session
        :param handler: handler for received events
        :param events: events to listen to, defaults to all
        :return: stream processing events, can be used to cancel stream
        :raises grpc.RpcError: when session doesn't exist
        """
        request = core_pb2.EventsRequest(session_id=session_id, events=events)
        stream = self.stub.Events(request)
        logging.info("STREAM TYPE: %s", type(stream))
        start_streamer(stream, handler)
        return stream
Exemple #4
0
    def events(
        self,
        session_id: int,
        handler: Callable[[wrappers.Event], None],
        events: List[wrappers.EventType] = None,
    ) -> grpc.Future:
        """
        Listen for session events.

        :param session_id: id of session
        :param handler: handler for received events
        :param events: events to listen to, defaults to all
        :return: stream processing events, can be used to cancel stream
        :raises grpc.RpcError: when session doesn't exist
        """
        request = core_pb2.EventsRequest(session_id=session_id, events=events)
        stream = self.stub.Events(request)
        thread = threading.Thread(target=event_listener,
                                  args=(stream, handler),
                                  daemon=True)
        thread.start()
        return stream