diff --git a/config/services.yaml b/config/services.yaml index ebf834ed..3fb4c50f 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -70,3 +70,8 @@ services: $ip_address: "%env(MQTT_IP_ADDRESS)%" $port: "%env(MQTT_PORT)%" $cert: "%env(MQTT_CERT)%" + + App\Service\APNSClient: + arguments: + $ip_address: "%env(APNS_REDIS_IP_ADDRESS)%" + $port: "%env(APNS_REDIS_PORT)%" diff --git a/src/Controller/JobOrderController.php b/src/Controller/JobOrderController.php index cc2ab1ac..26a1fe35 100644 --- a/src/Controller/JobOrderController.php +++ b/src/Controller/JobOrderController.php @@ -29,6 +29,7 @@ use App\Service\InvoiceCreator; use App\Service\MapTools; use App\Service\HubCounter; use App\Service\MQTTClient; +use App\Service\APNSClient; use Doctrine\ORM\Query; use Doctrine\DBAL\Connection; @@ -1110,7 +1111,7 @@ class JobOrderController extends BaseController return $this->render('job-order/form.html.twig', $params); } - public function assigningSubmit(Request $req, ValidatorInterface $validator, MQTTCLient $mclient, $id) + public function assigningSubmit(Request $req, ValidatorInterface $validator, MQTTCLient $mclient, APNSClient $aclient, $id) { $this->denyAccessUnlessGranted('jo_assign.list', null, 'No access.'); @@ -1201,6 +1202,10 @@ class JobOrderController extends BaseController $mclient->sendEvent($obj, $payload); $mclient->sendRiderEvent($obj, $payload); + // sned push notification + $aclient->sendPush($obj, "A RESQ rider is on his way to you."); + + // return successful response return $this->json([ 'success' => 'Changes have been saved!' diff --git a/src/Service/APNSClient.php b/src/Service/APNSClient.php new file mode 100644 index 00000000..4ac5c23d --- /dev/null +++ b/src/Service/APNSClient.php @@ -0,0 +1,51 @@ +redis = new Redis(); + $this->redis->connect($ip_address, $port); + } + + public function __destruct() + { + // $this->mclient->disconnect(); + } + + public function push($token, $message) + { + // $this->mclient->publish($channel, $message); + + $data = $token . '|' . $message; + $this->redis->lpush(self::REDIS_KEY, $data); + } + + public function sendPush($jo, $message) + { + $sessions = $jo->getCustomer()->getMobileSessions(); + if (count($sessions) == 0) + { + error_log("no sessions to send mqtt event to"); + return; + } + + foreach ($sessions as $sess) + { + $push_id = $sess->getDevicePushID(); + if ($push_id != null && strlen(trim($push_id)) > 0) + $this->push($push_id, $message); + } + } +}