Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Made it fancier
  • Loading branch information
ajrice6713 committed Sep 13, 2022
commit 484052f13390adb4f6c7e82b51ff1f3a9baeac3f
37 changes: 21 additions & 16 deletions bandwidth/utilities/web_rtc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
from bandwidth.model.bxml.verbs import *


def generate_transfer_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
def _generate_transfer_verb(device_token: str, voice_call_id: str, sip_uri: str = 'sip:sipx.webrtc.bandwidth.com:5060') -> Transfer:

Choose a reason for hiding this comment

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

For better or worse, iIn the SDK for all of our other languages the generate_transfer_verb() equivalent returns the BXML. This is the node version: https://github.com/Bandwidth/node-webrtc/blob/main/src/controllers/apiController.ts#L345

To make it consistent across languages perhaps name this one something like generate_transfer_verb_model, generate_transfer_bxml would become generate_transfer_bxml_verb, and generate_transfer_bxml_document would become generate_transfer_bxml

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This version of the SDK Will be breaking - so we could take the opprotunity to standardize on new names for all of the languages. We will be writing migration documentation for each language before going live.

Im fine with

_generate_transfer_model()
generate_transfer_bxml_verb()
generate_transfer_bxml()

if you guys are happy

Choose a reason for hiding this comment

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

Sounds good to me

"""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:
str: <Transfer> BXML Verb
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(
Expand All @@ -20,12 +20,25 @@ def generate_transfer_verb(device_token: str, voice_call_id: str, sip_uri: str =
)
transfer = Transfer(
sip_uris=[sip_uri]

)
return transfer.to_bxml()
return transfer


def generate_transfer_bxml(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_verb(device_token, voice_call_id, sip_uri).to_bxml()


def generate_transfer_bxml_document(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:
Expand All @@ -36,14 +49,6 @@ def generate_transfer_bxml(device_token: str, voice_call_id: str, sip_uri: str =
Returns:
str: BXML document with transfer BXML
"""
uui = "".join(voice_call_id.split("-")[1::])
transfer_bxml = Response()
sip_uri = SipUri(
uui=f"{uui};encoding=base64,{device_token};encoding=jwt",
uri=sip_uri
)
transfer = Transfer(
sip_uris=[sip_uri]
)
transfer_bxml.add_verb(transfer)
return transfer_bxml.to_bxml()
response = Response()
response.add_verb(_generate_transfer_verb(device_token, voice_call_id, sip_uri))
return response.to_bxml()
8 changes: 4 additions & 4 deletions test/unit/test_webrtc_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ class TestWebRtcUtilities:
"""

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

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