Merge branch '162-phase-2-changes' into 'master'
Resolve "Phase 2 changes" Closes #162 See merge request jankstudio/resq!179
This commit is contained in:
commit
21ea4156d5
3 changed files with 62 additions and 1 deletions
|
|
@ -70,3 +70,8 @@ services:
|
||||||
$ip_address: "%env(MQTT_IP_ADDRESS)%"
|
$ip_address: "%env(MQTT_IP_ADDRESS)%"
|
||||||
$port: "%env(MQTT_PORT)%"
|
$port: "%env(MQTT_PORT)%"
|
||||||
$cert: "%env(MQTT_CERT)%"
|
$cert: "%env(MQTT_CERT)%"
|
||||||
|
|
||||||
|
App\Service\APNSClient:
|
||||||
|
arguments:
|
||||||
|
$ip_address: "%env(APNS_REDIS_IP_ADDRESS)%"
|
||||||
|
$port: "%env(APNS_REDIS_PORT)%"
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,7 @@ use App\Service\InvoiceCreator;
|
||||||
use App\Service\MapTools;
|
use App\Service\MapTools;
|
||||||
use App\Service\HubCounter;
|
use App\Service\HubCounter;
|
||||||
use App\Service\MQTTClient;
|
use App\Service\MQTTClient;
|
||||||
|
use App\Service\APNSClient;
|
||||||
|
|
||||||
use Doctrine\ORM\Query;
|
use Doctrine\ORM\Query;
|
||||||
use Doctrine\DBAL\Connection;
|
use Doctrine\DBAL\Connection;
|
||||||
|
|
@ -1110,7 +1111,7 @@ class JobOrderController extends BaseController
|
||||||
return $this->render('job-order/form.html.twig', $params);
|
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.');
|
$this->denyAccessUnlessGranted('jo_assign.list', null, 'No access.');
|
||||||
|
|
||||||
|
|
@ -1201,6 +1202,10 @@ class JobOrderController extends BaseController
|
||||||
$mclient->sendEvent($obj, $payload);
|
$mclient->sendEvent($obj, $payload);
|
||||||
$mclient->sendRiderEvent($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 successful response
|
||||||
return $this->json([
|
return $this->json([
|
||||||
'success' => 'Changes have been saved!'
|
'success' => 'Changes have been saved!'
|
||||||
|
|
|
||||||
51
src/Service/APNSClient.php
Normal file
51
src/Service/APNSClient.php
Normal file
|
|
@ -0,0 +1,51 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Service;
|
||||||
|
|
||||||
|
use Mosquitto\Client as MosquittoClient;
|
||||||
|
use App\Entity\JobOrder;
|
||||||
|
use Redis;
|
||||||
|
|
||||||
|
class APNSClient
|
||||||
|
{
|
||||||
|
const REDIS_KEY = 'apns_push';
|
||||||
|
|
||||||
|
// protected $mclient;
|
||||||
|
protected $redis;
|
||||||
|
|
||||||
|
public function __construct($ip_address, $port)
|
||||||
|
{
|
||||||
|
$this->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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue