From 4bb2374d66a24e3d34cc0af584c3c5d931805a38 Mon Sep 17 00:00:00 2001 From: Kendrick Chan Date: Wed, 15 Aug 2018 09:14:18 +0800 Subject: [PATCH] Make sure we only send to unique channels when sending user app events #162 --- src/Service/MQTTClient.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/Service/MQTTClient.php b/src/Service/MQTTClient.php index f652ca76..79fa9dac 100644 --- a/src/Service/MQTTClient.php +++ b/src/Service/MQTTClient.php @@ -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); } }