Example #1
0
async def daemon(client: CompanionClient,
                 stream: Stream[RecordResponse, RecordRequest]) -> None:
    client.logger.info(f"Starting connection to backend")
    request = await stream.recv_message()
    output_file = none_throws(request).start.file_path
    async with client.stub.record.open() as forward_stream:
        if client.is_local:
            client.logger.info(
                f"Starting video recording to local file {output_file}")
            await forward_stream.send_message(
                RecordRequest(start=Start(file_path=output_file)))
        else:
            client.logger.info(f"Starting video recording with response data")
            await forward_stream.send_message(
                RecordRequest(start=Start(file_path=None)))
        client.logger.info("Request sent")
        await stream.recv_message()
        client.logger.info("Stopping video recording")
        await forward_stream.send_message(RecordRequest(stop=Stop()))
        await forward_stream.stream.end()
        if client.is_local:
            client.logger.info("Responding with file path")
            response = await forward_stream.recv_message()
            await stream.send_message(response)
        else:
            client.logger.info(f"Decompressing gzip to {output_file}")
            await drain_gzip_decompress(_generate_bytes(forward_stream),
                                        output_path=output_file)
            client.logger.info(f"Finished decompression to {output_file}")
            await stream.send_message(
                RecordResponse(payload=Payload(file_path=output_file)))
Example #2
0
async def record_video(client: CompanionClient, stop: asyncio.Event,
                       output_file: str) -> None:
    client.logger.info(f"Starting connection to backend")
    async with client.stub.record.open() as stream:
        client.logger.info("Starting video recording")
        await stream.send_message(
            RecordRequest(start=Start(file_path=output_file)))
        client.logger.info("Request sent")
        await stop.wait()
        client.logger.info("Stopping video recording")
        await stream.send_message(RecordRequest(stop=Stop()), end=True)
        await stream.recv_message()
Example #3
0
 async def record_video(self, stop: asyncio.Event, output_file: str) -> None:
     self.logger.info(f"Starting connection to backend")
     async with self.get_stub() as stub, stub.record.open() as stream:
         if none_throws(self.companion_info).is_local:
             self.logger.info(
                 f"Starting video recording to local file {output_file}"
             )
             await stream.send_message(
                 RecordRequest(start=RecordRequest.Start(file_path=output_file))
             )
         else:
             self.logger.info(f"Starting video recording with response data")
             await stream.send_message(
                 RecordRequest(start=RecordRequest.Start(file_path=None))
             )
         await stop.wait()
         self.logger.info("Stopping video recording")
         await stream.send_message(RecordRequest(stop=RecordRequest.Stop()))
         await stream.end()
         if none_throws(self.companion_info).is_local:
             self.logger.info("Video saved at output path")
             await stream.recv_message()
         else:
             self.logger.info(f"Decompressing gzip to {output_file}")
             await drain_gzip_decompress(
                 generate_video_bytes(stream), output_path=output_file
             )
             self.logger.info(f"Finished decompression to {output_file}")