Ejemplo n.º 1
0
    $_SESSION["inbound"] = $in;
    session_write_close();
}
require_once '../whatsprot.class.php';
$target = @$_POST["target"];
$username = "******";
$password = "******";
$w = new WhatsProt($username, 0, "WhatsApi AJAX Demo", true);
$w->eventManager()->bind("onGetImage", "onGetImage");
$w->eventManager()->bind("onGetProfilePicture", "onGetProfilePicture");
$w->connect();
$w->loginWithPassword($password);
$initial = @$_POST["initial"];
if ($initial == "true" && $target != null) {
    //request contact picture only on first call
    $w->sendGetProfilePicture($target);
}
//subscribe contact status
$w->SendPresenceSubscription($target);
//TODO: presense handling (online/offline/typing/last seen)
while (running($time)) {
    $w->pollMessages();
    running($time);
    //check again if timestamp has been updated
    //check for outbound messages to send:
    session_start();
    $outbound = $_SESSION["outbound"];
    $_SESSION["outbound"] = array();
    session_write_close();
    if (count($outbound) > 0) {
        foreach ($outbound as $message) {
Ejemplo n.º 2
0
//This function only needed to show how eventmanager works.
function onGetProfilePicture($from, $target, $type, $data)
{
    if ($type == "preview") {
        $filename = "preview_" . $target . ".jpg";
    } else {
        $filename = $target . ".jpg";
    }
    $filename = WhatsProt::PICTURES_FOLDER . "/" . $filename;
    $fp = @fopen($filename, "w");
    if ($fp) {
        fwrite($fp, $data);
        fclose($fp);
    }
    echo '<a href="' . $filename . '"><center><img src="' . $filename . '" height="250" width="250"></center></a><br><br>';
    echo '<center><b>Pulsa en la imagen para verlo a tamaño completo</b></center>';
}
$w->eventManager()->bind("onGetProfilePicture", "onGetProfilePicture");
$w->sendGetProfilePicture($target, true);
?>
 <ul>
                          <li>
                          </li>
                        </ul>
                      <div>
                      </div>
                    </div>
                  </li>
                </ol>
</html>