linxio-js
SDK Reference

Realtime

Socket.IO connections for live vehicle positions and Linxio notifications.

Realtime methods use the https://track.linxio.com Socket.IO host by default. Authenticate first or hydrate the client with an existing token before opening a socket.

realtime.connect()

Connect to a realtime namespace

linxio.realtime.connect(namespace, token)

Opens or reuses a Socket.IO connection for the coordinates or notifications namespace.

Input

namespace
coordinates | notifications
required
Realtime namespace to connect to.
token
string
optional
Optional JWT token. Defaults to the token stored on the parent client.

Returns

data
Socket
optional
Socket.IO client instance for the namespace.
throws
LinxioRealtimeError
optional
Thrown when no token is available.

realtime.subscribe()

Subscribe to realtime vehicles

linxio.realtime.subscribe(vehicleIds, namespace)

Emits Linxio's realtime subscribe event for one or more vehicle IDs.

Input

vehicleIds
readonly LinxioId[]
required
Vehicles to subscribe to. Values are converted to numbers before sending.
namespace
coordinates | notifications
optional
Namespace to subscribe through.
Default: coordinates

Returns

data
Promise<LinxioRealtimeSubscribeAck>
optional
Acknowledgement from Linxio's subscribe event.
throws
LinxioRealtimeError
optional
Thrown when no token is available.

realtime.onPosition()

Listen for live vehicle positions

linxio.realtime.onPosition(vehicleIds, handler)

Subscribes to live coordinate events and returns an unsubscribe function.

Input

vehicleIds
readonly LinxioId[]
required
Vehicles to subscribe to.
handler
(position: LinxioTrackingPosition) => void
required
Function called for each coordinate payload.

Returns

data
RealtimeUnsubscribe
optional
Function that removes listeners for this subscription.
payload.vehicleId
LinxioId
optional
Vehicle identifier in each position payload.
payload.lat / payload.lng
number
optional
Current coordinates.
payload.speed
number | null
optional
Speed when supplied by Linxio.

realtime.onNotification()

Listen for notifications

linxio.realtime.onNotification(handler)

Listens for notification events emitted by Linxio.

Input

handler
(notification: LinxioNotification) => void
required
Function called for each notification payload.

Returns

data
RealtimeUnsubscribe
optional
Function that removes notification listeners.
payload.type
string
optional
Notification type when supplied.
payload.message
string
optional
Notification message when supplied.

realtime.onNotificationType()

Listen for a notification type

linxio.realtime.onNotificationType(type, handler)

Listens for a custom notification event type emitted by Linxio.

Input

type
string
required
Socket event name to listen for.
handler
(payload: TPayload) => void
required
Function called for each matching event payload.

Returns

data
RealtimeUnsubscribe
optional
Function that removes the custom event listener.

realtime.disconnect()

Disconnect realtime sockets

linxio.realtime.disconnect(namespace)

Disconnects one namespace or every active realtime socket.

Input

namespace
coordinates | notifications
optional
Namespace to disconnect. Omit to disconnect all active sockets.

Returns

data
void
optional
disconnect() does not return a value.

On this page