Skip to content

Commit

Permalink
Add documentation and fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
acopeland-bw committed Jul 23, 2021
1 parent 684ebe0 commit 62f13c3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
12 changes: 12 additions & 0 deletions src/WebRtc/Utils/WebRtcTransfer.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,22 @@

class WebRtcTransfer {
public static function generateBxml($deviceToken, $voiceCallId, $sipUri = "sip:sipx.webrtc.bandwidth.com:5060") {
/**
* Returns BXML string with WebRTC a device token to perform a SIP transfer
* @param string $deviceToken The device token
* @param array $voiceCallId The Bandwidth Voice Call Id
* @return string $sipUri The SIP URI to transfer the call to
*/
return '<?xml version="1.0" encoding="UTF-8"?><Response>' . WebRtcTransfer::generateTransferBxmlVerb($deviceToken, $voiceCallId, $sipUri) . '</Response>';
}

public static function generateTransferBxmlVerb($deviceToken, $voiceCallId, $sipUri = "sip:sipx.webrtc.bandwidth.com:5060") {
/**
* Returns the Transfer verb to perform the SIP transfer
* @param string $deviceToken The device token
* @param array $voiceCallId The Bandwidth Voice Call Id
* @return string $sipUri The SIP URI to transfer the call to
*/
$formattedCallId = substr(str_replace("-", "", $voiceCallId), 1);
return '<Transfer><SipUri uui="' . $formattedCallId . ';encoding=base64' . $deviceToken . ';encoding=jwt">' . $sipUri . '</SipUri></Transfer>';
}
Expand Down
8 changes: 4 additions & 4 deletions tests/WebRtcBxmlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
final class WebRtcBxmlTest extends TestCase
{
public function testGenerateBxml() {
$expected = '<?xml version="1.0" encoding="UTF-8"?><Response><Transfer><SipUri uui="asdf;encoding=jwt">sip:sipx.webrtc.bandwidth.com:5060</SipUri></Transfer></Response>';
$actual = BandwidthLib\WebRtc\Utils\WebRtcTransfer::generateBxml('asdf');
$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 = BandwidthLib\WebRtc\Utils\WebRtcTransfer::generateBxml('asdf', 'c-93d6f3c0-be584596-0b74-4fa2-8015-d8ede84bd1a4');
$this->assertEquals($expected, $actual);
}

public function testGenerateTransferBxmlVerb() {
$expected = '<Transfer><SipUri uui="asdf;encoding=jwt">sip:sipx.webrtc.bandwidth.com:5060</SipUri></Transfer>';
$actual = BandwidthLib\WebRtc\Utils\WebRtcTransfer::generateTransferBxmlVerb('asdf');
$expected = '<Transfer><SipUri uui="93d6f3c0be5845960b744fa28015d8ede84bd1a4;encoding=base64,asdf;encoding=jwt">sip:sipx.webrtc.bandwidth.com:5060</SipUri></Transfer>';
$actual = BandwidthLib\WebRtc\Utils\WebRtcTransfer::generateTransferBxmlVerb('asdf', 'c-93d6f3c0-be584596-0b74-4fa2-8015-d8ede84bd1a4');
$this->assertEquals($expected, $actual);
}
}

0 comments on commit 62f13c3

Please sign in to comment.