Make sure we only send to unique channels when sending user app events #162

This commit is contained in:
Kendrick Chan 2018-08-15 09:14:18 +08:00
parent e0b98d00fe
commit 4bb2374d66

View file

@ -57,14 +57,23 @@ class MQTTClient
return;
}
$channels = [];
// send to every customer session
foreach ($sessions as $sess)
{
$phone_num = $sess->getPhoneNumber();
$channel = self::PREFIX . $phone_num;
$this->publish($channel, json_encode($payload));
error_log('sent to ' . $channel);
// gather channels, so we only send once
$channels[$channel] = json_encode($payload);
}
foreach ($channels as $channel => $json_payload)
{
$this->publish($channel, $json_payload);
// error_log('sent to ' . $channel);
}
}