Skip to content

Commit

Permalink
added sip header manipulation routines
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelog committed Mar 28, 2012
1 parent f5bd8f7 commit 8d9e143
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 15 deletions.
26 changes: 21 additions & 5 deletions src/mg/PAGI/Client/AbstractClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -815,15 +815,31 @@ public function stopPlayingTones()
}

/**
* Convenient method to create a node.
*
* @param string $name
*
* @return Node
* (non-PHPdoc)
* @see IClient::createNode()
*/
public function createNode($name)
{
$node = new \PAGI\Node\Node();
return $node->setName($name)->setAgiClient($this);
}

/**
* (non-PHPdoc)
* @see IClient::sipHeaderAdd()
*/
public function sipHeaderAdd($name, $value)
{
$this->exec('SipAddHeader', array("$name: $value"));
}

/**
* (non-PHPdoc)
* @see IClient::sipHeaderRemove()
*/
public function sipHeaderRemove($name)
{
$result = $this->exec('SipRemoveHeader', array($name));
return $result->getData();
}
}
48 changes: 38 additions & 10 deletions src/mg/PAGI/Client/IClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ public function setVariable($name, $value);
* @param string[] $options Application arguments.
*
* @throws ExecuteCommandException
* @return ExecDecorator
* @return ExecResult
*/
public function exec($application, array $options = array());

Expand Down Expand Up @@ -483,31 +483,31 @@ public function faxReceive($tiffFile);
/**
* Indicates progress of a call, starting early audio.
*
* @return ExecDecorator
* @return ExecResult
*/
public function indicateProgress();
/**
* Indicates busy and waits for hangup. Does not play a busy tone.
*
* @param integer $timeout Time in seconds to wait for hangup
*
* @return ExecDecorator
* @return ExecResult
*/
public function indicateBusy($timeout);
/**
* Indicates congestion and waits for hangup. Does not play a busy tone.
*
* @param integer $timeout Time in seconds to wait for hangup
*
* @return ExecDecorator
* @return ExecResult
*/
public function indicateCongestion($timeout);
/**
* Plays a tone defined in indications.conf.
*
* @param string $tone Tone to play
*
* @return ExecDecorator
* @return ExecResult
*/
public function playTone($tone);
/**
Expand All @@ -516,33 +516,61 @@ public function playTone($tone);
* @param string[] $frequencies Frequencies for the tone: 425/50,0/50 or
* !950/330,!1400/330,!1800/330,0 etc.
*
* @return ExecDecorator
* @return ExecResult
*/
public function playCustomTones(array $frequencies);
/**
* Stop playing current played tones.
*
* @return ExecDecorator
* @return ExecResult
*/
public function stopPlayingTones();

/**
* Plays "Dial" tone, defined in indications.conf
*
* @return ExecDecorator
* @return ExecResult
*/
public function playDialTone();
/**
* Plays "Busy" tone, defined in indications.conf
*
* @return ExecDecorator
* @return ExecResult
*/
public function playBusyTone();

/**
* Plays "Congestion" tone, defined in indications.conf
*
* @return ExecDecorator
* @return ExecResult
*/
public function playCongestionTone();

/**
* Convenient method to create a node.
*
* @param string $name
*
* @return Node
*/
public function createNode($name);

/**
* Adds a SIP header to the first invite message in a dial command.
*
* @param string $name
* @param string $value
*
* @return ExecResult
*/
public function sipHeaderAdd($name, $value);

/**
* Removes a header previously added with sipHeaderAdd.
*
* @param string $name
*
* @return ExecResult
*/
public function sipHeaderRemove($name);
}
36 changes: 36 additions & 0 deletions test/client/Test_Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -1634,5 +1634,41 @@ public function can_get_node()
$this->assertTrue($node->getClient() instanceof \PAGI\Client\Impl\ClientImpl);
$this->assertEquals($node->getName(), 'name');
}

/**
* @test
*/
public function can_add_sip_header()
{
global $standardAGIStart;
setFgetsMock($standardAGIStart, array());
$client = \PAGI\Client\Impl\ClientImpl::getInstance($this->_properties);
$write = array(
'EXEC "SipAddHeader" "name: value"'
);
$read = array(
'200 result=0',
);
setFgetsMock($read, $write);
$result = $client->sipHeaderAdd('name', 'value');
}

/**
* @test
*/
public function can_add_sip_remove()
{
global $standardAGIStart;
setFgetsMock($standardAGIStart, array());
$client = \PAGI\Client\Impl\ClientImpl::getInstance($this->_properties);
$write = array(
'EXEC "SipRemoveHeader" "name"'
);
$read = array(
'200 result=0',
);
setFgetsMock($read, $write);
$result = $client->sipHeaderRemove('name');
}
}
}

0 comments on commit 8d9e143

Please sign in to comment.