-
Notifications
You must be signed in to change notification settings - Fork 53
Expand file tree
/
Copy pathDriverLocationChanged.php
More file actions
174 lines (155 loc) · 3.85 KB
/
Copy pathDriverLocationChanged.php
File metadata and controls
174 lines (155 loc) · 3.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
<?php
namespace Fleetbase\FleetOps\Events;
use Fleetbase\FleetOps\Models\Driver;
use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Carbon;
class DriverLocationChanged implements ShouldBroadcast
{
use Dispatchable;
use InteractsWithSockets;
use SerializesModels;
/**
* The event id.
*
* @var string
*/
public $eventId;
/**
* The datetime instance the broadcast ws triggered.
*
* @var string
*/
public $sentAt;
/**
* The uuid of the driver.
*
* @var string
*/
public $driverUuid;
/**
* The public id of the driver.
*
* @var string
*/
public $driverId;
/**
* The internal id of the driver.
*
* @var string
*/
public $driverInternalId;
/**
* The name of the driver.
*
* @var string
*/
public $driverName;
/**
* The phone of the driver.
*
* @var string
*/
public $driverPhone;
/**
* The new driver location.
*
* @var string
*/
public $location;
/**
* The driver altitude.
*
* @var string
*/
public $altitude;
/**
* The ndriver heading.
*
* @var string
*/
public $heading;
/**
* The driver speed.
*
* @var string
*/
public $speed;
/**
* Optional, additional data.
*
* @var array
*/
public $additionalData = [];
/**
* Create a new event instance.
*
* @return void
*/
public function __construct(Driver $driver, array $additionalData = [])
{
$this->eventId = uniqid('event_');
$this->sentAt = Carbon::now()->toDateTimeString();
$this->additionalData = $additionalData;
$this->driverUuid = $driver->uuid;
$this->driverId = $driver->public_id;
$this->driverInternalId = $driver->internal_id;
$this->driverName = $driver->name;
$this->driverPhone = $driver->phone;
$this->location = $driver->location;
$this->altitude = $driver->altitude;
$this->heading = $driver->heading;
$this->speed = $driver->speed;
}
/**
* Get the channels the event should broadcast on.
*
* @return Channel|array
*/
public function broadcastOn()
{
return [
new Channel('company.' . session('company')),
new Channel('api.' . session('api_credential')),
new Channel('driver.' . $this->driverId),
new Channel('driver.' . $this->driverUuid),
];
}
/**
* The event's broadcast name.
*
* @return string
*/
public function broadcastAs()
{
return 'driver.location_changed';
}
/**
* Get the data to broadcast.
*
* @return array
*/
public function broadcastWith()
{
return [
'id' => $this->eventId,
'api_version' => config('api.version'),
'event' => $this->broadcastAs(),
'created_at' => $this->sentAt,
'data' => [
'id' => $this->driverId,
'internal_id' => $this->driverInternalId,
'name' => $this->driverName,
'phone' => $this->driverPhone,
'location' => $this->location,
'altitude' => $this->altitude,
'heading' => $this->heading,
'speed' => $this->speed,
'additionalData' => $this->additionalData,
],
];
}
}