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

1import asyncio
2from signalwire.relay import RelayClient
3
4client = RelayClient(
5 project="your-project-id",
6 token="your-api-token",
7 host="your-space.signalwire.com",
8 contexts=["default"],
9)
10
11async def main():
12 await client.connect()
13
14 # Do work ...
15 message = await client.send_message(
16 to_number="+15559876543",
17 from_number="+15551234567",
18 body="Hello!",
19 )
20 await message.wait()
21
22 await client.disconnect()
23
24asyncio.run(main())