transports(inputs): handle start/stop interruption frames
This commit is contained in:
@@ -77,6 +77,10 @@ class BaseInputTransport(FrameProcessor):
|
||||
await self.push_frame(frame, direction)
|
||||
elif isinstance(frame, BotInterruptionFrame):
|
||||
await self._handle_interruptions(frame, False)
|
||||
elif isinstance(frame, StartInterruptionFrame):
|
||||
await self._start_interruption()
|
||||
elif isinstance(frame, StopInterruptionFrame):
|
||||
await self._stop_interruption()
|
||||
# All other system frames
|
||||
elif isinstance(frame, SystemFrame):
|
||||
await self.push_frame(frame, direction)
|
||||
@@ -120,6 +124,9 @@ class BaseInputTransport(FrameProcessor):
|
||||
#
|
||||
|
||||
async def _start_interruption(self):
|
||||
if not self.interruptions_allowed:
|
||||
return
|
||||
|
||||
# Cancel the task. This will stop pushing frames downstream.
|
||||
self._push_frame_task.cancel()
|
||||
await self._push_frame_task
|
||||
@@ -131,6 +138,9 @@ class BaseInputTransport(FrameProcessor):
|
||||
self._create_push_task()
|
||||
|
||||
async def _stop_interruption(self):
|
||||
if not self.interruptions_allowed:
|
||||
return
|
||||
|
||||
await self.push_frame(StopInterruptionFrame())
|
||||
|
||||
async def _handle_interruptions(self, frame: Frame, push_frame: bool):
|
||||
|
||||
Reference in New Issue
Block a user