Skip to content

Commit 099f67d

Browse files
rtc: added sip publish dtmf feature (#273)
Co-authored-by: Théo Monnom <[email protected]>
1 parent 9e0e452 commit 099f67d

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

livekit-rtc/livekit/rtc/participant.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ def __init__(self, message: str) -> None:
5151
self.message = message
5252

5353

54+
class PublishDTMFError(Exception):
55+
def __init__(self, message: str) -> None:
56+
self.message = message
57+
58+
5459
class PublishTranscriptionError(Exception):
5560
def __init__(self, message: str) -> None:
5661
self.message = message
@@ -147,6 +152,34 @@ async def publish_data(
147152
if cb.publish_data.error:
148153
raise PublishDataError(cb.publish_data.error)
149154

155+
async def publish_dtmf(self, *, code: int, digit: str) -> None:
156+
"""
157+
Publish SIP DTMF message.
158+
159+
Args:
160+
code (int): DTMF code.
161+
digit (str): DTMF digit.
162+
163+
Raises:
164+
PublishDTMFError: If there is an error in publishing SIP DTMF message.
165+
"""
166+
req = proto_ffi.FfiRequest()
167+
req.publish_sip_dtmf.local_participant_handle = self._ffi_handle.handle
168+
req.publish_sip_dtmf.code = code
169+
req.publish_sip_dtmf.digit = digit
170+
171+
queue = FfiClient.instance.queue.subscribe()
172+
try:
173+
resp = FfiClient.instance.request(req)
174+
cb = await queue.wait_for(
175+
lambda e: e.publish_sip_dtmf.async_id == resp.publish_sip_dtmf.async_id
176+
)
177+
finally:
178+
FfiClient.instance.queue.unsubscribe(queue)
179+
180+
if cb.publish_sip_dtmf.error:
181+
raise PublishDTMFError(cb.publish_sip_dtmf.error)
182+
150183
async def publish_transcription(self, transcription: Transcription) -> None:
151184
"""
152185
Publish transcription data to the room.

0 commit comments

Comments
 (0)