disconnect

View as MarkdownOpen in Claude

Cleanly close the WebSocket connection to SignalWire Relay. This cancels the internal receive loop, ping monitor, all pending JSON-RPC requests, any queued requests waiting for reconnection, and any in-progress dial operations. The client is fully reset and can be reconnected with connect().

When using the async context manager (async with client:), disconnect() is called automatically on exit. When using run(), disconnection happens automatically on Ctrl+C or when the event loop is stopped.

Parameters

None.

Returns

None

Example

import asyncio
from signalwire.relay import RelayClient
client = RelayClient(
project="your-project-id",
token="your-api-token",
contexts=["default"],
)
async def main():
await client.connect()
# Do work ...
message = await client.send_message(
to_number="+15559876543",
from_number="+15551234567",
body="Hello!",
)
await message.wait()
await client.disconnect()
asyncio.run(main())