Metadata-Version: 2.5
Name: dtelecom-rtc
Version: 0.1.0
Summary: Server-side asyncio audio and data participant for dTelecom rooms
License-Expression: Apache-2.0
License-File: LICENSE
License-File: NOTICE
Requires-Python: >=3.11
Requires-Dist: aiortc<1.18,>=1.17
Requires-Dist: av<20,>=14
Requires-Dist: dtelecom-server-sdk==0.1.0
Requires-Dist: pyee<17,>=13
Requires-Dist: websockets<17,>=14
Description-Content-Type: text/markdown

# dTelecom RTC for Python

Join a dTelecom room from a Python process, receive remote audio as PCM16, and publish audio or room data. Supply a participant grant from your backend. Its response includes the signaling URL, token and ranked fallback URLs. [Room connections](https://docs.dtelecom.org/rooms/connect/)

```python
from dtelecom_rtc import AudioSource, Room

async def echo(grant, finished):
    source = AudioSource(sample_rate=16000)
    async with Room() as room:
        @room.on("track_subscribed")
        async def receive(track, publication, participant):
            async for frame in track.stream(sample_rate=16000):
                await source.capture_frame(frame)

        await room.connect(grant.ws_url, grant.token, fallback_urls=grant.fallback_urls)
        await room.publish_audio("echo", source)
        await finished.wait()
    source.close()
```

Use a distinct identity for each participant. Set `auto_subscribe=False` to choose remote tracks explicitly with `set_subscribed`. Register event handlers before joining to include publications already present in the room. A `data_received` handler receives payload bytes, the sender when known, the delivery kind and topic. `publish_data` accepts a string or bytes, optional topic and destination participant SIDs, and reliable or lossy delivery.

The SDK tries the issuer's ranked endpoints with the same grant after a transport failure. When extending a grant through Cloud, call `room.update_connection_token(token, fallback_urls)` so the room uses the refreshed credentials after a reconnect. Use `disconnect()` or exit the async context to leave.

Configure SDK log levels using Python's standard `logging.getLogger("dtelecom_rtc").setLevel(...)`. Use `AudioFrame.duration`, `samples_per_channel`, and the `resample`, `downsample` and `upsample` helpers for standalone PCM. `create_text_message`, `encode_data_packet` and `decode_data_packet` expose the fork's room-data format. The protocol message models and enums are exported from `dtelecom_rtc.models`.

For a live interoperability check, install Playwright and use the ESM bundle of `@dtelecom/livekit-client@1.13.0`. Set `DTELECOM_API_KEY`, `DTELECOM_API_SECRET`, `DTELECOM_CLOUD_URL` and `DTELECOM_BROWSER_MODULE`, then run `python tests/integration/browser_call.py`. The script creates a disposable room and uses synthetic audio. Add `--recovery` to test a grant with three ranked nodes and reconnect the Python publisher. `CHROME_EXECUTABLE` selects a local browser when needed.

On transport loss, `room.state` becomes `"reconnecting"` and the room emits `reconnecting` before releasing remote tracks and participants. A service can keep per-speaker state through that teardown, then reconcile the identities present at `reconnected`. A terminal `disconnected` ends the session.
