Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added bandwidth/utilities/init.py
Empty file.
54 changes: 54 additions & 0 deletions bandwidth/utilities/web_rtc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
from bandwidth.model.bxml.response import Response
from bandwidth.model.bxml.verbs import *


def _generate_transfer_model(device_token: str, voice_call_id: str, sip_uri: str = 'sip:sipx.webrtc.bandwidth.com:5060') -> Transfer:
"""Generate a Transfer object for a WebRTC Session

Args:
device_token (str): The device token.
voice_call_id (str): The Bandwidth voice Call ID.
sip_uri (str, optional): The SIP URI to transfer the call to. Defaults to 'sip:sipx.webrtc.bandwidth.com:5060'.

Returns:
Transfer: Returns a Transfer BXML Verb Object
"""
uui = "".join(voice_call_id.split("-")[1::])

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could make a private helper to generate the Transfer and reuse it in this function and in generate_transfer_bxml

sip_uri = SipUri(
uui=f"{uui};encoding=base64,{device_token};encoding=jwt",
uri=sip_uri
)
transfer = Transfer(
sip_uris=[sip_uri]
)
return transfer


def generate_transfer_bxml_verb(device_token: str, voice_call_id: str, sip_uri: str = 'sip:sipx.webrtc.bandwidth.com:5060') -> str:
"""Returns the Transfer verb to perform the SIP transfer without the Response wrapper

Args:
device_token (str): The device token.
voice_call_id (str): The Bandwidth voice Call ID.
sip_uri (str, optional): The SIP URI to transfer the call to. Defaults to 'sip:sipx.webrtc.bandwidth.com:5060'.

Returns:
str: <Transfer> BXML Verb
"""
return _generate_transfer_model(device_token, voice_call_id, sip_uri).to_bxml()


def generate_transfer_bxml(device_token: str, voice_call_id: str, sip_uri: str = 'sip:sipx.webrtc.bandwidth.com:5060') -> str:
"""Generate BXML document with WebRTC a device token to perform a SIP transfer

Args:
device_token (str): The device token.
voice_call_id (str): The Bandwidth voice Call ID.
sip_uri (str, optional): The SIP URI to transfer the call to. Defaults to 'sip:sipx.webrtc.bandwidth.com:5060'.

Returns:
str: BXML document with transfer BXML
"""
response = Response()
response.add_verb(_generate_transfer_model(device_token, voice_call_id, sip_uri))
return response.to_bxml()
15 changes: 1 addition & 14 deletions test/unit/test_bxml.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from bandwidth.model.bxml.response import Response
from bandwidth.model.bxml.bxml import Bxml
from bandwidth.model.bxml.verbs import *
from bandwidth.utilities import web_rtc


class TestBxml:
Expand Down Expand Up @@ -396,20 +397,6 @@ def test_bxml_speak_sentence_pause(self):
bxml.add_verb(speak_sentence)
bxml.add_verb(pause)
assert bxml.to_bxml() == expected_bxml

@pytest.mark.skip(reason="This model is not yet implemented")
def test_generate_transfer_bxml(self):
expected = '<?xml version="1.0" encoding="UTF-8"?><Response><Transfer><SipUri uui="93d6f3c0be5845960b744fa28015d8ede84bd1a4;encoding=base64,asdf;encoding=jwt">sip:sipx.webrtc.bandwidth.com:5060</SipUri></Transfer></Response>'
actual = generate_transfer_bxml(
'asdf', 'c-93d6f3c0-be584596-0b74-4fa2-8015-d8ede84bd1a4')
assert actual == expected

@pytest.mark.skip(reason="This model is not yet implemented")
def test_generate_transfer_bxml_verb(self):
expected = '<Transfer><SipUri uui="93d6f3c0be5845960b744fa28015d8ede84bd1a4;encoding=base64,asdf;encoding=jwt">sip:sipx.webrtc.bandwidth.com:5060</SipUri></Transfer>'
actual = generate_transfer_bxml_verb(
'asdf', 'c-93d6f3c0-be584596-0b74-4fa2-8015-d8ede84bd1a4')
assert actual == expected

def test_start_stream_bxml_verb(self):
expected = '<?xml version="1.0" encoding="UTF-8"?><Response><StartStream destination="https://www.test.com/stream" name="test_stream" tracks="inbound" streamEventUrl="https://www.test.com/event" streamEventMethod="POST" username="username" password="password"/></Response>'
Expand Down
19 changes: 19 additions & 0 deletions test/unit/test_webrtc_utilities.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from bandwidth.utilities.web_rtc import *


class TestWebRtcUtilities:
"""
Class for the WebRTC Utilities Tests
"""

def test_generate_transfer_bxml(self):
expected = '<Transfer><SipUri uui="93d6f3c0be5845960b744fa28015d8ede84bd1a4;encoding=base64,asdf;encoding=jwt">sip:sipx.webrtc.bandwidth.com:5060</SipUri></Transfer>'
actual = generate_transfer_bxml_verb(
'asdf', 'c-93d6f3c0-be584596-0b74-4fa2-8015-d8ede84bd1a4')
assert actual == expected

def test_generate_transfer_bxml_document(self):
expected = '<?xml version="1.0" encoding="UTF-8"?><Response><Transfer><SipUri uui="93d6f3c0be5845960b744fa28015d8ede84bd1a4;encoding=base64,asdf;encoding=jwt">sip:sipx.webrtc.bandwidth.com:5060</SipUri></Transfer></Response>'
actual = generate_transfer_bxml(
'asdf', 'c-93d6f3c0-be584596-0b74-4fa2-8015-d8ede84bd1a4')
assert actual == expected