PHP Version 5
Author: Marcelo Gornstein (marcelog@gmail.com)
Inheritance: implements PAGI\CallSpool\ICallSpool
コード例 #1
1
ファイル: Test_CallSpool.php プロジェクト: d4rkstar/pagi
        /**
         * @test
         */
        public function can_spool_and_schedule()
        {
            $tmpDir = sys_get_temp_dir() . DIRECTORY_SEPARATOR . microtime(true);
            $spoolDir = $tmpDir . DIRECTORY_SEPARATOR . 'spool';
            if (@mkdir($tmpDir, 0755, true) === false) {
                $this->fail('Could not create temporary directory');
            }
            if (@mkdir($spoolDir . DIRECTORY_SEPARATOR . 'outgoing', 0755, true) === false) {
                $this->fail('Could not create temporary spool directory');
            }
            $props = array('tmpDir' => $tmpDir, 'spoolDir' => $spoolDir);
            $spool = \PAGI\CallSpool\Impl\CallSpoolImpl::getInstance($props);
            $call = new \PAGI\CallSpool\CallFile(new \PAGI\DialDescriptor\SIPDialDescriptor('target', 'provider'));
            $call->unserialize(<<<TEXT
Channel: SIP/target@provider
Archive: Yes
Context: context
Priority: priority
Extension: extension
Application: application
AlwaysDelete: Yes
CallerID: callerId
MaxRetries: 33
RetryTime: 44
WaitTime: 22
Account: account
Data: a,b,c
aaaa:
Set: var=value
Set: var2=
TEXT
);
            $file = $spool->spool($call, 12);
            $content = <<<TEXT
Channel: SIP/target@provider
Archive: Yes
Context: context
Priority: priority
Extension: extension
Application: application
AlwaysDelete: Yes
CallerID: callerId
MaxRetries: 33
RetryTime: 44
WaitTime: 22
Account: account
Data: a,b,c
aaaa: ?
Set: var=value
Set: var2=?
TEXT;
            $this->assertEquals(file_get_contents($file), $content);
            $this->assertEquals(filemtime($file), 12);
            if (@unlink($file) === false) {
                $this->fail('could not remove call file: ' . $file);
            }
            if (@rmdir($spoolDir . DIRECTORY_SEPARATOR . 'outgoing') === false) {
                $this->fail('could not remove temporary spool outgoing directory');
            }
            if (@rmdir($spoolDir) === false) {
                $this->fail('could not remove temporary spool directory');
            }
            if (@rmdir($tmpDir) === false) {
                $this->fail('could not remove temporary directory');
            }
        }
コード例 #2
-1
ファイル: spooling.php プロジェクト: marcelog/pagi
use PAGI\DialDescriptor\SIPDialDescriptor;
use PAGI\DialDescriptor\DAHDIDialDescriptor;
$dialDescriptor = new DAHDIDialDescriptor('1949890333', 1);
$callFile = new CallFile($dialDescriptor);
$callFile->setContext('campaign');
$callFile->setExtension('failed');
$callFile->setVariable('foo', 'bar');
$callFile->setPriority('1');
$callFile->setMaxRetries('0');
$callFile->setWaitTime(10);
$callFile->setCallerId('some<123123>');
echo "Call file generated (DAHDI dial descriptor):\n";
echo $callFile->serialize();
echo "\n\n";
$dialDescriptor = new SIPDialDescriptor('24', 'example.com');
$callFile = new CallFile($dialDescriptor);
$callFile->setContext('default');
$callFile->setExtension('777');
$callFile->setVariable('foo', 'bar');
$callFile->setPriority('1');
$callFile->setMaxRetries('0');
$callFile->setWaitTime(10);
$callFile->setCallerId('some<123123>');
echo "Call file generated (SIP dial descriptor):\n";
echo $callFile->serialize();
echo "\n\n\n";
echo "Spooling generated SIP call\n";
$spool = CallSpoolImpl::getInstance(array('tmpDir' => '/tmp', 'spoolDir' => '/tmp/spoolExample'));
$spool->spool($callFile);
echo "Spooling generated SIP call to run in 30 seconds\n";
$spool->spool($callFile, time() + 30);