Merge pull request #1560 from pipecat-ai/bot_left_signalling
Bot left signalling message
This commit is contained in:
@@ -308,7 +308,7 @@ class SmallWebRTCClient:
|
|||||||
if self.is_connected and not self.is_closing:
|
if self.is_connected and not self.is_closing:
|
||||||
logger.info(f"Disconnecting to Small WebRTC")
|
logger.info(f"Disconnecting to Small WebRTC")
|
||||||
self._closing = True
|
self._closing = True
|
||||||
await self._webrtc_connection.close()
|
await self._webrtc_connection.disconnect()
|
||||||
await self._handle_client_disconnected()
|
await self._handle_client_disconnected()
|
||||||
|
|
||||||
async def send_message(self, frame: TransportMessageFrame | TransportMessageUrgentFrame):
|
async def send_message(self, frame: TransportMessageFrame | TransportMessageUrgentFrame):
|
||||||
|
|||||||
@@ -44,6 +44,10 @@ class RenegotiateMessage(BaseModel):
|
|||||||
type: Literal["renegotiate"] = "renegotiate"
|
type: Literal["renegotiate"] = "renegotiate"
|
||||||
|
|
||||||
|
|
||||||
|
class PeerLeftMessage(BaseModel):
|
||||||
|
type: Literal["peerLeft"] = "peerLeft"
|
||||||
|
|
||||||
|
|
||||||
class SignallingMessage:
|
class SignallingMessage:
|
||||||
Inbound = Union[TrackStatusMessage] # in case we need to add new messages in the future
|
Inbound = Union[TrackStatusMessage] # in case we need to add new messages in the future
|
||||||
outbound = Union[RenegotiateMessage]
|
outbound = Union[RenegotiateMessage]
|
||||||
@@ -226,7 +230,7 @@ class SmallWebRTCConnection(BaseObject):
|
|||||||
logger.debug("Closing old peer connection")
|
logger.debug("Closing old peer connection")
|
||||||
# removing the listeners to prevent the bot from closing
|
# removing the listeners to prevent the bot from closing
|
||||||
self._pc.remove_all_listeners()
|
self._pc.remove_all_listeners()
|
||||||
await self.close()
|
await self._close()
|
||||||
# we are initializing a new peer connection in this case.
|
# we are initializing a new peer connection in this case.
|
||||||
self._initialize()
|
self._initialize()
|
||||||
|
|
||||||
@@ -271,7 +275,11 @@ class SmallWebRTCConnection(BaseObject):
|
|||||||
else:
|
else:
|
||||||
logger.warning("Video transceiver not found. Cannot replace video track.")
|
logger.warning("Video transceiver not found. Cannot replace video track.")
|
||||||
|
|
||||||
async def close(self):
|
async def disconnect(self):
|
||||||
|
self.send_app_message({"type": SIGNALLING_TYPE, "message": PeerLeftMessage().model_dump()})
|
||||||
|
await self._close()
|
||||||
|
|
||||||
|
async def _close(self):
|
||||||
if self._pc:
|
if self._pc:
|
||||||
await self._pc.close()
|
await self._pc.close()
|
||||||
self._message_queue.clear()
|
self._message_queue.clear()
|
||||||
@@ -296,7 +304,7 @@ class SmallWebRTCConnection(BaseObject):
|
|||||||
await self._call_event_handler(state)
|
await self._call_event_handler(state)
|
||||||
if state == "failed":
|
if state == "failed":
|
||||||
logger.warning("Connection failed, closing peer connection.")
|
logger.warning("Connection failed, closing peer connection.")
|
||||||
await self.close()
|
await self._close()
|
||||||
|
|
||||||
# Despite the fact that aiortc provides this listener, they don't have a status for "disconnected"
|
# Despite the fact that aiortc provides this listener, they don't have a status for "disconnected"
|
||||||
# So, there is no advantage in looking at self._pc.connectionState
|
# So, there is no advantage in looking at self._pc.connectionState
|
||||||
|
|||||||
Reference in New Issue
Block a user