@de./sdk-rn 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +2 -0
  3. package/dist/allend/Access.d.ts +12 -0
  4. package/dist/allend/Access.d.ts.map +1 -0
  5. package/dist/allend/Access.js +43 -0
  6. package/dist/allend/Access.js.map +1 -0
  7. package/dist/allend/DClient/Client.d.ts +11 -0
  8. package/dist/allend/DClient/Client.d.ts.map +1 -0
  9. package/dist/allend/DClient/Client.js +50 -0
  10. package/dist/allend/DClient/Client.js.map +1 -0
  11. package/dist/allend/DClient/Event.d.ts +19 -0
  12. package/dist/allend/DClient/Event.d.ts.map +1 -0
  13. package/dist/allend/DClient/Event.js +74 -0
  14. package/dist/allend/DClient/Event.js.map +1 -0
  15. package/dist/allend/DClient/Order.d.ts +50 -0
  16. package/dist/allend/DClient/Order.d.ts.map +1 -0
  17. package/dist/allend/DClient/Order.js +321 -0
  18. package/dist/allend/DClient/Order.js.map +1 -0
  19. package/dist/allend/MSI/Controls.d.ts +232 -0
  20. package/dist/allend/MSI/Controls.d.ts.map +1 -0
  21. package/dist/allend/MSI/Controls.js +668 -0
  22. package/dist/allend/MSI/Controls.js.map +1 -0
  23. package/dist/allend/MSI/Handles.d.ts +89 -0
  24. package/dist/allend/MSI/Handles.d.ts.map +1 -0
  25. package/dist/allend/MSI/Handles.js +328 -0
  26. package/dist/allend/MSI/Handles.js.map +1 -0
  27. package/dist/allend/MSI/Plugins.d.ts +23 -0
  28. package/dist/allend/MSI/Plugins.d.ts.map +1 -0
  29. package/dist/allend/MSI/Plugins.js +29 -0
  30. package/dist/allend/MSI/Plugins.js.map +1 -0
  31. package/dist/allend/MSI/index.d.ts +38 -0
  32. package/dist/allend/MSI/index.d.ts.map +1 -0
  33. package/dist/allend/MSI/index.js +176 -0
  34. package/dist/allend/MSI/index.js.map +1 -0
  35. package/dist/allend/index.d.ts +16 -0
  36. package/dist/allend/index.d.ts.map +1 -0
  37. package/dist/allend/index.js +12 -0
  38. package/dist/allend/index.js.map +1 -0
  39. package/dist/backend/Auth.d.ts +14 -0
  40. package/dist/backend/Auth.d.ts.map +1 -0
  41. package/dist/backend/Auth.js +84 -0
  42. package/dist/backend/Auth.js.map +1 -0
  43. package/dist/index.d.ts +13 -0
  44. package/dist/index.d.ts.map +1 -0
  45. package/dist/index.js +12 -0
  46. package/dist/index.js.map +1 -0
  47. package/dist/utils/index.d.ts +6 -0
  48. package/dist/utils/index.d.ts.map +1 -0
  49. package/dist/utils/index.js +3 -0
  50. package/dist/utils/index.js.map +1 -0
  51. package/dist/utils/stream.d.ts +21 -0
  52. package/dist/utils/stream.d.ts.map +1 -0
  53. package/dist/utils/stream.js +59 -0
  54. package/dist/utils/stream.js.map +1 -0
  55. package/package.json +81 -0
  56. package/src/allend/Access.ts +58 -0
  57. package/src/allend/DClient/Client.ts +76 -0
  58. package/src/allend/DClient/Event.ts +76 -0
  59. package/src/allend/DClient/Order.ts +452 -0
  60. package/src/allend/MSI/Controls.ts +703 -0
  61. package/src/allend/MSI/Handles.ts +387 -0
  62. package/src/allend/MSI/Plugins.ts +52 -0
  63. package/src/allend/MSI/index.tsx +254 -0
  64. package/src/allend/index.ts +14 -0
  65. package/src/backend/Auth.ts +112 -0
  66. package/src/index.ts +18 -0
  67. package/src/types/access.d.ts +7 -0
  68. package/src/types/auth.d.ts +26 -0
  69. package/src/types/index.d.ts +275 -0
  70. package/src/utils/index.ts +4 -0
  71. package/src/utils/stream.ts +68 -0
@@ -0,0 +1,703 @@
1
+ import type {
2
+ GPSLocation,
3
+ Coordinates,
4
+ MapLayerStyle,
5
+ Caption,
6
+ MapOptions,
7
+ SearchPlace,
8
+ EntitySpecs,
9
+ ActivePosition,
10
+ UserLocationOptions,
11
+ DragPickContentType,
12
+ DragPickContent,
13
+ MapWaypoint,
14
+ Journey,
15
+ RouteOptions,
16
+ ActiveDirection
17
+ } from '../../types'
18
+ import WIO from 'webview.io'
19
+
20
+ const
21
+ FUNCTION_EVENT_TIMEOUT = 12000,
22
+ FUNCTION_EVENT_TIMEOUT_MESSAGE = 'Event timeout'
23
+
24
+ export default class Controls {
25
+ private options: MapOptions
26
+ private chn: WIO
27
+
28
+ constructor( chn: WIO, options: MapOptions ){
29
+ this.chn = chn
30
+ this.options = options
31
+ }
32
+
33
+ /**
34
+ * Refresh access token to remove server
35
+ *
36
+ * @param token - Latest access token
37
+ */
38
+ refreshToken( token: string ){
39
+ if( !token ) return
40
+ this.options.accessToken = token
41
+ }
42
+
43
+ /**
44
+ * Update map style
45
+ *
46
+ * @param style - Map style ID
47
+ */
48
+ setMapStyle( style: MapLayerStyle ): Promise<void> {
49
+ return new Promise( ( resolve, reject ) => {
50
+ // Set timeout
51
+ const timeout = setTimeout( () => reject( FUNCTION_EVENT_TIMEOUT_MESSAGE ), FUNCTION_EVENT_TIMEOUT )
52
+ // Set style
53
+ this.chn.emit('set:map:style', style, ( error: string | boolean ) => {
54
+ if( error ) return reject( error )
55
+
56
+ clearTimeout( timeout )
57
+ resolve()
58
+ } )
59
+ })
60
+ }
61
+
62
+ /**
63
+ * @return - User's current GPS location
64
+ */
65
+ getCurrentLocation(): Promise<GPSLocation | null> {
66
+ return new Promise( ( resolve, reject ) => {
67
+ // Set timeout
68
+ const timeout = setTimeout( () => reject( FUNCTION_EVENT_TIMEOUT_MESSAGE ), FUNCTION_EVENT_TIMEOUT )
69
+ // Get current location
70
+ this.chn.emit('get:current:location', ( error: string | boolean, location: GPSLocation ) => {
71
+ if( error ) return reject( error )
72
+
73
+ clearTimeout( timeout )
74
+ resolve( location )
75
+ } )
76
+ } )
77
+ }
78
+ /**
79
+ * Pin user's current location on the current active map
80
+ *
81
+ * @return - User's current GPS location coordinates or `null` when it failed
82
+ */
83
+ pinCurrentLocation(): Promise<Coordinates | null> {
84
+ return new Promise( ( resolve, reject ) => {
85
+ // Set timeout
86
+ const timeout = setTimeout( () => reject( FUNCTION_EVENT_TIMEOUT_MESSAGE ), FUNCTION_EVENT_TIMEOUT )
87
+ // Pin user's current location on the map
88
+ this.chn.emit('pin:current:location', ( error: string | boolean, location: Coordinates | null ) => {
89
+ if( error ) return reject( error )
90
+
91
+ clearTimeout( timeout )
92
+ resolve( location )
93
+ } )
94
+ } )
95
+ }
96
+
97
+ /**
98
+ * Set live location tracking options
99
+ *
100
+ * @param options - User location tracking options
101
+ */
102
+ setLiveLocationOptions( options: UserLocationOptions ): Promise<void> {
103
+ return new Promise( ( resolve, reject ) => {
104
+ // Set timeout
105
+ const timeout = setTimeout( () => reject( FUNCTION_EVENT_TIMEOUT_MESSAGE ), FUNCTION_EVENT_TIMEOUT )
106
+ // Set live location options
107
+ this.chn.emit('set:live:options', options, ( error: string | boolean ) => {
108
+ if( error ) return reject( error )
109
+
110
+ clearTimeout( timeout )
111
+ resolve()
112
+ } )
113
+ } )
114
+ }
115
+ /**
116
+ * Start tracking user's live location
117
+ */
118
+ trackLiveLocation(): Promise<void> {
119
+ return new Promise( ( resolve, reject ) => {
120
+ // Set timeout
121
+ const timeout = setTimeout( () => reject( FUNCTION_EVENT_TIMEOUT_MESSAGE ), FUNCTION_EVENT_TIMEOUT )
122
+ // Start live location tracking
123
+ this.chn.emit('track:live:location', ( error: string | boolean ) => {
124
+ if( error ) return reject( error )
125
+
126
+ clearTimeout( timeout )
127
+ resolve()
128
+ } )
129
+ } )
130
+ }
131
+ /**
132
+ * Stop tracking user's live location
133
+ */
134
+ untrackLiveLocation(): Promise<void> {
135
+ return new Promise( ( resolve, reject ) => {
136
+ // Set timeout
137
+ const timeout = setTimeout( () => reject( FUNCTION_EVENT_TIMEOUT_MESSAGE ), FUNCTION_EVENT_TIMEOUT )
138
+ // Stop live location tracking
139
+ this.chn.emit('untrack:live:location', ( error: string | boolean ) => {
140
+ if( error ) return reject( error )
141
+
142
+ clearTimeout( timeout )
143
+ resolve()
144
+ } )
145
+ } )
146
+ }
147
+
148
+ /**
149
+ * Enable drag pick functionality
150
+ *
151
+ * @param location - (Optional) Initial location for drag pick
152
+ */
153
+ enableDragPickLocation( location?: Coordinates ): Promise<void> {
154
+ return new Promise( ( resolve, reject ) => {
155
+ // Set timeout
156
+ const timeout = setTimeout( () => reject( FUNCTION_EVENT_TIMEOUT_MESSAGE ), FUNCTION_EVENT_TIMEOUT )
157
+ // Enable drag pick
158
+ this.chn.emit('enable:dragpick:location', location, ( error: string | boolean ) => {
159
+ if( error ) return reject( error )
160
+
161
+ clearTimeout( timeout )
162
+ resolve()
163
+ } )
164
+ } )
165
+ }
166
+ /**
167
+ * Disable drag pick functionality
168
+ */
169
+ disableDragPickLocation(): Promise<void> {
170
+ return new Promise( ( resolve, reject ) => {
171
+ // Set timeout
172
+ const timeout = setTimeout( () => reject( FUNCTION_EVENT_TIMEOUT_MESSAGE ), FUNCTION_EVENT_TIMEOUT )
173
+ // Disable drag pick
174
+ this.chn.emit('disable:dragpick:location', ( error: string | boolean ) => {
175
+ if( error ) return reject( error )
176
+
177
+ clearTimeout( timeout )
178
+ resolve()
179
+ } )
180
+ } )
181
+ }
182
+ /**
183
+ * Set drag pick content
184
+ *
185
+ * @param type - Content type for drag pick
186
+ * @param content - Content data for drag pick
187
+ */
188
+ setDragPickContent( type: DragPickContentType, content: DragPickContent ): Promise<void> {
189
+ return new Promise( ( resolve, reject ) => {
190
+ // Set timeout
191
+ const timeout = setTimeout( () => reject( FUNCTION_EVENT_TIMEOUT_MESSAGE ), FUNCTION_EVENT_TIMEOUT )
192
+ // Set drag pick content
193
+ this.chn.emit('set:dragpick:content', { type, content }, ( error: string | boolean ) => {
194
+ if( error ) return reject( error )
195
+
196
+ clearTimeout( timeout )
197
+ resolve()
198
+ } )
199
+ } )
200
+ }
201
+
202
+ /**
203
+ * Get a location coordinates of placed that matched this name
204
+ *
205
+ * @param name - Place name to resolve
206
+ * @return - Array list of coordinates
207
+ */
208
+ resolvePlace( name: string ): Promise<Coordinates | null> {
209
+ return new Promise( ( resolve, reject ) => {
210
+ // Set timeout
211
+ const timeout = setTimeout( () => reject( FUNCTION_EVENT_TIMEOUT_MESSAGE ), FUNCTION_EVENT_TIMEOUT )
212
+ // Get location coordinates from place name
213
+ this.chn.emit('resolve:place', name, ( error: string | boolean, data: any ) => {
214
+ if( error ) return reject( error )
215
+
216
+ clearTimeout( timeout )
217
+ resolve( data )
218
+ } )
219
+ } )
220
+ }
221
+ /**
222
+ * Get a location details of placed that matched this coordinates
223
+ *
224
+ * @param coords - Coordinates
225
+ * @return - Array list of geocoding data
226
+ */
227
+ resolveCoordinates( coords: Coordinates | string ): Promise<Coordinates | null> {
228
+ return new Promise( ( resolve, reject ) => {
229
+ // Set timeout
230
+ const timeout = setTimeout( () => reject( FUNCTION_EVENT_TIMEOUT_MESSAGE ), FUNCTION_EVENT_TIMEOUT )
231
+ // Get location place from coordinates
232
+ this.chn.emit('resolve:coordinates', coords, ( error: string | boolean, data: any ) => {
233
+ if( error ) return reject( error )
234
+
235
+ clearTimeout( timeout )
236
+ resolve( data )
237
+ } )
238
+ } )
239
+ }
240
+
241
+ /**
242
+ * Search a location or places
243
+ *
244
+ * @param input - Place in string
245
+ * @return - Autocompletion list matched places
246
+ */
247
+ searchQuery( input: string ): Promise<string[]> {
248
+ return new Promise( ( resolve, reject ) => {
249
+ // Set timeout
250
+ const timeout = setTimeout( () => reject( FUNCTION_EVENT_TIMEOUT_MESSAGE ), FUNCTION_EVENT_TIMEOUT )
251
+ // Launch search query
252
+ this.chn.emit('search:query', input, ( error: string | boolean, data: any ) => {
253
+ if( error ) return reject( error )
254
+
255
+ clearTimeout( timeout )
256
+ resolve( data )
257
+ } )
258
+ } )
259
+ }
260
+ /**
261
+ * Select a suggested place by the search
262
+ *
263
+ * @param index - Index of place in suggested list
264
+ * @return - More details of selected place
265
+ */
266
+ searchSelect( index: number ): Promise<SearchPlace | null> {
267
+ return new Promise( ( resolve, reject ) => {
268
+ // Set timeout
269
+ const timeout = setTimeout( () => reject( FUNCTION_EVENT_TIMEOUT_MESSAGE ), FUNCTION_EVENT_TIMEOUT )
270
+ // Get place's details
271
+ this.chn.emit('search:select', index, ( error: string | boolean, data: SearchPlace | null ) => {
272
+ if( error ) return reject( error )
273
+
274
+ clearTimeout( timeout )
275
+ resolve( data )
276
+ } )
277
+ } )
278
+ }
279
+
280
+ /**
281
+ * Show nearby entities around coordinates
282
+ *
283
+ * @param list - Array of entity specifications
284
+ */
285
+ showNearby( list: EntitySpecs[] ): Promise<void> {
286
+ return new Promise( ( resolve, reject ) => {
287
+ // Set timeout
288
+ const timeout = setTimeout( () => reject( FUNCTION_EVENT_TIMEOUT_MESSAGE ), FUNCTION_EVENT_TIMEOUT )
289
+ // Show nearby entities
290
+ this.chn.emit('show:nearby', list, ( error: string | boolean ) => {
291
+ if( error ) return reject( error )
292
+
293
+ clearTimeout( timeout )
294
+ resolve()
295
+ } )
296
+ } )
297
+ }
298
+ /**
299
+ * Remove all displaying nearby entities
300
+ */
301
+ removeNearby(): Promise<void> {
302
+ return new Promise( ( resolve, reject ) => {
303
+ // Set timeout
304
+ const timeout = setTimeout( () => reject( FUNCTION_EVENT_TIMEOUT_MESSAGE ), FUNCTION_EVENT_TIMEOUT )
305
+ // Remove nearby entities
306
+ this.chn.emit('remove:nearby', ( error: string | boolean ) => {
307
+ if( error ) return reject( error )
308
+
309
+ clearTimeout( timeout )
310
+ resolve()
311
+ } )
312
+ } )
313
+ }
314
+ /**
315
+ * Add a new nearby entity
316
+ *
317
+ * @param entity - Entity specification
318
+ */
319
+ addNearbyEntity( entity: EntitySpecs ): Promise<void> {
320
+ return new Promise( ( resolve, reject ) => {
321
+ // Set timeout
322
+ const timeout = setTimeout( () => reject( FUNCTION_EVENT_TIMEOUT_MESSAGE ), FUNCTION_EVENT_TIMEOUT )
323
+ // Add nearby entity
324
+ this.chn.emit('add:nearby:entity', entity, ( error: string | boolean ) => {
325
+ if( error ) return reject( error )
326
+
327
+ clearTimeout( timeout )
328
+ resolve()
329
+ } )
330
+ } )
331
+ }
332
+ /**
333
+ * Update a nearby entity position
334
+ *
335
+ * @param activePosition - Entity ID and new position
336
+ */
337
+ moveNearbyEntity( activePosition: ActivePosition ): Promise<void> {
338
+ return new Promise( ( resolve, reject ) => {
339
+ // Set timeout
340
+ const timeout = setTimeout( () => reject( FUNCTION_EVENT_TIMEOUT_MESSAGE ), FUNCTION_EVENT_TIMEOUT )
341
+ // Move nearby entity
342
+ this.chn.emit('move:nearby:entity', activePosition, ( error: string | boolean ) => {
343
+ if( error ) return reject( error )
344
+
345
+ clearTimeout( timeout )
346
+ resolve()
347
+ } )
348
+ } )
349
+ }
350
+ /**
351
+ * Remove a nearby entity
352
+ *
353
+ * @param id - Entity ID to remove
354
+ */
355
+ removeNearbyEntity( id: string ): Promise<void> {
356
+ return new Promise( ( resolve, reject ) => {
357
+ // Set timeout
358
+ const timeout = setTimeout( () => reject( FUNCTION_EVENT_TIMEOUT_MESSAGE ), FUNCTION_EVENT_TIMEOUT )
359
+ // Remove nearby entity
360
+ this.chn.emit('remove:nearby:entity', id, ( error: string | boolean ) => {
361
+ if( error ) return reject( error )
362
+
363
+ clearTimeout( timeout )
364
+ resolve()
365
+ } )
366
+ } )
367
+ }
368
+
369
+ /**
370
+ * Set complete route with journey specifications
371
+ *
372
+ * @param journey - Journey specifications including route ID, origin, destination, waypoints, and options
373
+ */
374
+ setRoute( journey: Journey ): Promise<void> {
375
+ return new Promise( ( resolve, reject ) => {
376
+ // Set timeout
377
+ const timeout = setTimeout( () => reject( FUNCTION_EVENT_TIMEOUT_MESSAGE ), FUNCTION_EVENT_TIMEOUT )
378
+ // Set route
379
+ this.chn.emit('set:route', journey, ( error: string | boolean ) => {
380
+ if( error ) return reject( error )
381
+
382
+ clearTimeout( timeout )
383
+ resolve()
384
+ } )
385
+ } )
386
+ }
387
+ /**
388
+ * Set route origin
389
+ *
390
+ * @param routeId - Route identifier
391
+ * @param point - Waypoint specification for origin
392
+ */
393
+ setRouteOrigin( routeId: string, point: MapWaypoint ): Promise<void> {
394
+ return new Promise( ( resolve, reject ) => {
395
+ // Set timeout
396
+ const timeout = setTimeout( () => reject( FUNCTION_EVENT_TIMEOUT_MESSAGE ), FUNCTION_EVENT_TIMEOUT )
397
+ // Set route origin
398
+ this.chn.emit('set:route:origin', { routeId, point }, ( error: string | boolean ) => {
399
+ if( error ) return reject( error )
400
+
401
+ clearTimeout( timeout )
402
+ resolve()
403
+ } )
404
+ } )
405
+ }
406
+ /**
407
+ * Remove route origin
408
+ *
409
+ * @param routeId - Route identifier
410
+ */
411
+ removeRouteOrigin( routeId: string ): Promise<void> {
412
+ return new Promise( ( resolve, reject ) => {
413
+ // Set timeout
414
+ const timeout = setTimeout( () => reject( FUNCTION_EVENT_TIMEOUT_MESSAGE ), FUNCTION_EVENT_TIMEOUT )
415
+ // Remove route origin
416
+ this.chn.emit('remove:route:origin', { routeId }, ( error: string | boolean ) => {
417
+ if( error ) return reject( error )
418
+
419
+ clearTimeout( timeout )
420
+ resolve()
421
+ } )
422
+ } )
423
+ }
424
+ /**
425
+ * Set route destination
426
+ *
427
+ * @param routeId - Route identifier
428
+ * @param point - Waypoint specification for destination
429
+ */
430
+ setRouteDestination( routeId: string, point: MapWaypoint ): Promise<void> {
431
+ return new Promise( ( resolve, reject ) => {
432
+ // Set timeout
433
+ const timeout = setTimeout( () => reject( FUNCTION_EVENT_TIMEOUT_MESSAGE ), FUNCTION_EVENT_TIMEOUT )
434
+ // Set route destination
435
+ this.chn.emit('set:route:destination', { routeId, point }, ( error: string | boolean ) => {
436
+ if( error ) return reject( error )
437
+
438
+ clearTimeout( timeout )
439
+ resolve()
440
+ } )
441
+ } )
442
+ }
443
+ /**
444
+ * Remove route destination
445
+ *
446
+ * @param routeId - Route identifier
447
+ */
448
+ removeRouteDestination( routeId: string ): Promise<void> {
449
+ return new Promise( ( resolve, reject ) => {
450
+ // Set timeout
451
+ const timeout = setTimeout( () => reject( FUNCTION_EVENT_TIMEOUT_MESSAGE ), FUNCTION_EVENT_TIMEOUT )
452
+ // Remove route destination
453
+ this.chn.emit('remove:route:destination', { routeId }, ( error: string | boolean ) => {
454
+ if( error ) return reject( error )
455
+
456
+ clearTimeout( timeout )
457
+ resolve()
458
+ } )
459
+ } )
460
+ }
461
+ /**
462
+ * Add a route waypoint
463
+ *
464
+ * @param routeId - Route identifier
465
+ * @param point - Waypoint specification
466
+ */
467
+ addRouteWaypoint( routeId: string, point: MapWaypoint ): Promise<void> {
468
+ return new Promise( ( resolve, reject ) => {
469
+ // Set timeout
470
+ const timeout = setTimeout( () => reject( FUNCTION_EVENT_TIMEOUT_MESSAGE ), FUNCTION_EVENT_TIMEOUT )
471
+ // Add route waypoint
472
+ this.chn.emit('add:route:waypoint', { routeId, point }, ( error: string | boolean ) => {
473
+ if( error ) return reject( error )
474
+
475
+ clearTimeout( timeout )
476
+ resolve()
477
+ } )
478
+ } )
479
+ }
480
+ /**
481
+ * Update a route waypoint
482
+ *
483
+ * @param routeId - Route identifier
484
+ * @param point - Waypoint specification with index
485
+ */
486
+ updateRouteWaypoint( routeId: string, point: MapWaypoint ): Promise<void> {
487
+ return new Promise( ( resolve, reject ) => {
488
+ // Set timeout
489
+ const timeout = setTimeout( () => reject( FUNCTION_EVENT_TIMEOUT_MESSAGE ), FUNCTION_EVENT_TIMEOUT )
490
+ // Update route waypoint
491
+ this.chn.emit('update:route:waypoint', { routeId, point }, ( error: string | boolean ) => {
492
+ if( error ) return reject( error )
493
+
494
+ clearTimeout( timeout )
495
+ resolve()
496
+ } )
497
+ } )
498
+ }
499
+ /**
500
+ * Remove a route waypoint
501
+ *
502
+ * @param routeId - Route identifier
503
+ * @param index - Waypoint index to remove
504
+ */
505
+ removeRouteWaypoint( routeId: string, index: number ): Promise<void> {
506
+ return new Promise( ( resolve, reject ) => {
507
+ // Set timeout
508
+ const timeout = setTimeout( () => reject( FUNCTION_EVENT_TIMEOUT_MESSAGE ), FUNCTION_EVENT_TIMEOUT )
509
+ // Remove route waypoint
510
+ this.chn.emit('remove:route:waypoint', { routeId, index }, ( error: string | boolean ) => {
511
+ if( error ) return reject( error )
512
+
513
+ clearTimeout( timeout )
514
+ resolve()
515
+ } )
516
+ } )
517
+ }
518
+
519
+ /**
520
+ * Set waypoint caption
521
+ *
522
+ * @param routeId - Route identifier
523
+ * @param id - Waypoint identifier (string or number)
524
+ * @param caption - Caption information to set
525
+ */
526
+ setWaypointCaption( routeId: string, id: string | number, caption: Caption ): Promise<void> {
527
+ return new Promise( ( resolve, reject ) => {
528
+ // Set timeout
529
+ const timeout = setTimeout( () => reject( FUNCTION_EVENT_TIMEOUT_MESSAGE ), FUNCTION_EVENT_TIMEOUT )
530
+ // Set waypoint caption
531
+ this.chn.emit('set:waypoint:caption', { routeId, id, caption }, ( error: string | boolean ) => {
532
+ if( error ) return reject( error )
533
+
534
+ clearTimeout( timeout )
535
+ resolve()
536
+ } )
537
+ } )
538
+ }
539
+ /**
540
+ * Update waypoint caption
541
+ *
542
+ * @param routeId - Route identifier
543
+ * @param id - Waypoint identifier (string or number)
544
+ * @param caption - Caption information to update
545
+ */
546
+ updateWaypointCaption( routeId: string, id: string | number, caption: Caption ): Promise<void> {
547
+ return new Promise( ( resolve, reject ) => {
548
+ // Set timeout
549
+ const timeout = setTimeout( () => reject( FUNCTION_EVENT_TIMEOUT_MESSAGE ), FUNCTION_EVENT_TIMEOUT )
550
+ // Update waypoint caption
551
+ this.chn.emit('update:waypoint:caption', { routeId, id, caption }, ( error: string | boolean ) => {
552
+ if( error ) return reject( error )
553
+
554
+ clearTimeout( timeout )
555
+ resolve()
556
+ } )
557
+ } )
558
+ }
559
+ /**
560
+ * Remove waypoint caption
561
+ *
562
+ * @param routeId - Route identifier
563
+ * @param id - Waypoint identifier (string or number)
564
+ */
565
+ removeWaypointCaption( routeId: string, id: string | number ): Promise<void> {
566
+ return new Promise( ( resolve, reject ) => {
567
+ // Set timeout
568
+ const timeout = setTimeout( () => reject( FUNCTION_EVENT_TIMEOUT_MESSAGE ), FUNCTION_EVENT_TIMEOUT )
569
+ // Remove waypoint caption
570
+ this.chn.emit('remove:waypoint:caption', { routeId, id }, ( error: string | boolean ) => {
571
+ if( error ) return reject( error )
572
+
573
+ clearTimeout( timeout )
574
+ resolve()
575
+ } )
576
+ } )
577
+ }
578
+
579
+ /**
580
+ * Mount navigation route
581
+ *
582
+ * @param routeId - Route identifier for navigation
583
+ */
584
+ mountNavigation( routeId: string | number ): Promise<void> {
585
+ return new Promise( ( resolve, reject ) => {
586
+ // Set timeout
587
+ const timeout = setTimeout( () => reject( FUNCTION_EVENT_TIMEOUT_MESSAGE ), FUNCTION_EVENT_TIMEOUT )
588
+ // Mount navigation
589
+ this.chn.emit('mount:navigation', routeId, ( error: string | boolean ) => {
590
+ if( error ) return reject( error )
591
+
592
+ clearTimeout( timeout )
593
+ resolve()
594
+ } )
595
+ } )
596
+ }
597
+ /**
598
+ * Unmount navigation route
599
+ */
600
+ unmountNavigation(): Promise<void> {
601
+ return new Promise( ( resolve, reject ) => {
602
+ // Set timeout
603
+ const timeout = setTimeout( () => reject( FUNCTION_EVENT_TIMEOUT_MESSAGE ), FUNCTION_EVENT_TIMEOUT )
604
+ // Unmount navigation
605
+ this.chn.emit('unmount:navigation', ( error: string | boolean ) => {
606
+ if( error ) return reject( error )
607
+
608
+ clearTimeout( timeout )
609
+ resolve()
610
+ } )
611
+ } )
612
+ }
613
+ /**
614
+ * Load navigation direction
615
+ */
616
+ loadNavigation(): Promise<void> {
617
+ return new Promise( ( resolve, reject ) => {
618
+ // Set timeout
619
+ const timeout = setTimeout( () => reject( FUNCTION_EVENT_TIMEOUT_MESSAGE ), FUNCTION_EVENT_TIMEOUT )
620
+ // Load navigation
621
+ this.chn.emit('load:navigation', ( error: string | boolean ) => {
622
+ if( error ) return reject( error )
623
+
624
+ clearTimeout( timeout )
625
+ resolve()
626
+ } )
627
+ } )
628
+ }
629
+ /**
630
+ * Set initial navigation position
631
+ *
632
+ * @param position - Initial GPS location for navigation
633
+ */
634
+ setInitialNavigationPosition( position: GPSLocation ): Promise<void> {
635
+ return new Promise( ( resolve, reject ) => {
636
+ // Set timeout
637
+ const timeout = setTimeout( () => reject( FUNCTION_EVENT_TIMEOUT_MESSAGE ), FUNCTION_EVENT_TIMEOUT )
638
+ // Set initial navigation position
639
+ this.chn.emit('initial:navigation:position', position, ( error: string | boolean ) => {
640
+ if( error ) return reject( error )
641
+
642
+ clearTimeout( timeout )
643
+ resolve()
644
+ } )
645
+ } )
646
+ }
647
+ /**
648
+ * Navigate to new position
649
+ *
650
+ * @param position - Current GPS location for navigation update
651
+ */
652
+ navigate( position: GPSLocation ): Promise<void> {
653
+ return new Promise( ( resolve, reject ) => {
654
+ // Set timeout
655
+ const timeout = setTimeout( () => reject( FUNCTION_EVENT_TIMEOUT_MESSAGE ), FUNCTION_EVENT_TIMEOUT )
656
+ // Navigate
657
+ this.chn.emit('navigate:navigation:direction', position, ( error: string | boolean ) => {
658
+ if( error ) return reject( error )
659
+
660
+ clearTimeout( timeout )
661
+ resolve()
662
+ } )
663
+ } )
664
+ }
665
+ /**
666
+ * Upsert navigation direction data
667
+ *
668
+ * @param routeId - Route identifier for navigation
669
+ * @param direction - Direction data
670
+ * @param position - (Optional) Current GPS position
671
+ * @params options - Route options
672
+ */
673
+ casting( routeId: string | number, direction: any, position?: GPSLocation, options?: RouteOptions ): Promise<void> {
674
+ return new Promise( ( resolve, reject ) => {
675
+
676
+ // Set timeout
677
+ const timeout = setTimeout( () => reject( FUNCTION_EVENT_TIMEOUT_MESSAGE ), FUNCTION_EVENT_TIMEOUT )
678
+ // Casting navigation direction
679
+ this.chn.emit('casting:navigation:direction', { routeId, direction, position, options }, ( error: string | boolean ) => {
680
+ if( error ) return reject( error )
681
+
682
+ clearTimeout( timeout )
683
+ resolve()
684
+ } )
685
+ } )
686
+ }
687
+ /**
688
+ * Dismiss navigation
689
+ */
690
+ dismissNavigation(): Promise<void> {
691
+ return new Promise( ( resolve, reject ) => {
692
+ // Set timeout
693
+ const timeout = setTimeout( () => reject( FUNCTION_EVENT_TIMEOUT_MESSAGE ), FUNCTION_EVENT_TIMEOUT )
694
+ // Dismiss navigation
695
+ this.chn.emit('dismiss:navigation', ( error: string | boolean ) => {
696
+ if( error ) return reject( error )
697
+
698
+ clearTimeout( timeout )
699
+ resolve()
700
+ } )
701
+ } )
702
+ }
703
+ }