Skip to content

Commit

Permalink
Removed pollMessages()
Browse files Browse the repository at this point in the history
use pollMessage() instead
  • Loading branch information
shirioko committed Aug 12, 2014
1 parent 9832b1d commit 46494f3
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 24 deletions.
2 changes: 1 addition & 1 deletion examples/ajaxDemo/socket.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ function onGetImage($mynumber, $from, $id, $type, $t, $name, $size, $url, $file,
//TODO: presense handling (online/offline/typing/last seen)

while (running($time)) {
$w->pollMessages();
while($w->pollMessage());

running($time); //check again if timestamp has been updated
//check for outbound messages to send:
Expand Down
8 changes: 4 additions & 4 deletions examples/bulk.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function Login()
$this->wa->loginWithPassword($this->password);
$this->wa->sendClientConfig();
$this->wa->sendGetServerProperties();
$this->wa->pollMessages();
while($this->wa->pollMessage());
echo "Ready for work!<br />";
}

Expand Down Expand Up @@ -123,7 +123,7 @@ public function SendBroadcast($targets, $message)
}
echo "Sending broadcast... ";
$this->wa->sendBroadcastMessage($targets, $message);
$this->wa->pollMessages();
$this->wa->pollMessage();
echo "done!<br />";
}

Expand All @@ -137,10 +137,10 @@ public function SendBulk($targets, $message)
foreach($targets as $target)
{
$this->wa->sendPresenceSubscription($target);
$this->wa->pollMessages();
$this->wa->pollMessage();
$this->wa->sendMessageComposing($target);
sleep(1);
$this->wa->pollMessages();
$this->wa->pollMessage();
$this->wa->sendMessagePaused($target);
static::$sendLock = true;
echo "Sending message from " . $this->username . " to $target... ";
Expand Down
2 changes: 1 addition & 1 deletion examples/contactsync.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,5 @@ function onSyncResult($result)
//wait for response
while(true)
{
$wa->pollMessages();
$wa->pollMessage();
}
4 changes: 2 additions & 2 deletions examples/exampleFunctional.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ function onPresenceReceived($username, $from, $type)
$w->sendMessage($target, "Guess the number :)");
$w->sendMessage($target, "Sent from WhatsApi at " . date('H:i'));

$w->pollMessages();
while($w->pollMessage());

/**
* You can create a ProcessNode class (or whatever name you want) that has a process($node) function
Expand All @@ -115,7 +115,7 @@ function onPresenceReceived($username, $from, $type)
echo "\n\nYou can also write and send messages to $target (interactive conversation)\n\n> ";

while (1) {
$w->pollMessages();
$w->pollMessage();
$msgs = $w->getMessages();
foreach ($msgs as $m) {
# process inbound messages
Expand Down
15 changes: 1 addition & 14 deletions src/whatsprot.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -475,19 +475,6 @@ public function loginWithPassword($password)
$this->doLogin();
}

/**
* Pull from the socket, and place incoming messages in the message queue.
*/
public function pollMessages($autoReceipt = true)
{
$stanza = $this->readStanza();
while($stanza)
{
$this->processInboundData($stanza, $autoReceipt);
$stanza = $this->readStanza();
}
}

/**
* Fetch a single message node
* @param bool $autoReceipt
Expand Down Expand Up @@ -1418,7 +1405,7 @@ public function waitForMessageReceipt()
{
$received = false;
do {
$this->pollMessages();
$this->pollMessage();
$msgs = $this->getMessages();
foreach ($msgs as $m) {
// Process inbound messages.
Expand Down
4 changes: 2 additions & 2 deletions tests/whatsapp.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function fgets_u($pStdn)
echo "\n[] Interactive conversation with $dst:\n";
stream_set_timeout(STDIN,1);
while (TRUE) {
$wa->pollMessages();
while($wa->pollMessage());
$buff = $wa->getMessages();
if (!empty($buff)) {
print_r($buff);
Expand Down Expand Up @@ -84,7 +84,7 @@ function fgets_u($pStdn)
if ($_SERVER['argv'][1] == "-l") {
echo "\n[] Listen mode:\n";
while (TRUE) {
$wa->pollMessages();
$wa->pollMessage();
$data = $wa->getMessages();
if(!empty($data)) print_r($data);
sleep(1);
Expand Down

5 comments on commit 46494f3

@ardianys
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't use pollMessages() in my project, but could you explain your reason removing it ?

@shirioko
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because people were using it all over the place and then complaining about how slow WhatsAPI was. No shit.

@Amirjan
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi shirioko,
Whats while($w->pollMessage()) VS $w->pollMessage() !?
I send messages without pollMessage() after it, Does it matter or wrong.
Thanx.

@shirioko
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I swear to god if I see one more "?!" or "??" or "!!"...

You don't need to call pollMessage() after sendMessage() as it already makes a call to waitForServer();

@hugorodriguesbr
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi shirioko,
When I receive a message, it is encrypted. What am I doing wrong?
exemple:
[data:ProtocolNode:private] => ?ۚ!Uÿ4???o??$E?˒??Յ9?+?i?O?"<!?T?[?<(~???Fݐ???<ݛ?BWysZ.N"B3
!t?%(iݿ?m???[{?m?Q???n?8??kr""._???p?Y?K?lg?<??r?L(،ģ0

Please sign in to comment.