billy1234567892 / php-sip

Automatically exported from code.google.com/p/php-sip
0 stars 0 forks source link

Quarues #16

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
<?php $src_ip = '192.168.7.55' /* Change this to your server IP address */ ?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">

<head><title>PHP-SIP Click to Call</title></head>

<body>

<?php if (isset($_POST['from']) && isset($_POST['to'])) : ?>

  <?php require_once('php-sip/PhpSIP.class.php') ?>

  <?php $from = $_POST['from']; $to = $_POST['to'] ?>

  Trying call from <?php echo $from ?> to <?php echo $to ?> ...<br />

  <?php flush() ?>

  <pre>
  <?php 

    try{

      $api = new PhpSIP($src_ip);
      $api->setDebug(true);
      //$api->setUsername('auth_username');
      //$api->setPassword('auth_password');
      $api->addHeader('Subject: click2call');
      $api->setMethod('INVITE');
      $api->setFrom('sip:c2c@'.$src_ip);
      $api->setUri($from);

      $res = $api->send();

      if ($res == 200)
      { 
        $api->setMethod('REFER');
        $api->addHeader('Refer-to: '.$to);
        $api->addHeader('Referred-By: sip:c2c@'.$src_ip);
        $api->send();

        $api->setMethod('BYE');
        $api->send();

        $api->listen('NOTIFY');
        $api->reply(481,'Call Leg/Transaction Does Not Exist');
      }

      if ($res == 'No final response in 5 seconds.')
      {
        $api->setMethod('CANCEL');
        $res = $api->send();
      }

      echo $res;

    } catch (Exception $e) {

      echo "Opps... Caught exception:";
      echo $e;
    }

  ?>
  </pre>
  <hr />

  <a href="<?php echo $_SERVER['PHP_SELF']; ?>">Back</a>

<?php else : ?>

  <form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post">
    <fieldset>
      From: <input type="text" name="from" size="25" value="" />
      To: <input type="text" name="to" size="25" value="sip:
 soumyadey111187@gmail.com" />
      <input type="submit" value="Call" />
    </fieldset>
  </form>

<?php endif ?>

</body>
</html>

Original issue reported on code.google.com by soumyade...@gmail.com on 23 Jul 2012 at 3:26