interface SentianceEventTimeline {
    sentianceFeedback: SentianceFeedback;
    addTimelineUpdateListener(onTimelineUpdated: ((event: Event) => void), includeProvisionalEvents?: boolean): Promise<EmitterSubscription>;
    getTimelineEvent(eventId: string): Promise<null | Event>;
    getTimelineEvents(fromEpochTimeMs: number, toEpochTimeMs: number, includeProvisionalEvents?: boolean): Promise<Event[]>;
    getTimelineUpdates(afterEpochTimeMs: number, includeProvisionalEvents?: boolean): Promise<Event[]>;
    setTransportTags(tags: TransportTags): Promise<void>;
    startReceivingTripLocationUpdates(intervalInSeconds: number, onLocationReceived: ((location: TripLocation) => void)): Promise<TripLocationUpdatesStartResult>;
    stopReceivingTripLocationUpdates(): Promise<void>;
}

Properties

sentianceFeedback: SentianceFeedback

Methods

  • Sets a listener that is invoked when the event timeline is updated. The listener receives the updated events. An update can be triggered by the start of a new event, and the update or end of an existing one. Every invocation of the listener will deliver an event that has a last update time that is equal to or greater than the previously delivered event's last update time.

    Parameters

    • onTimelineUpdated: ((event: Event) => void)

      The callback to receive event timeline updates.

        • (event): void
        • Parameters

          Returns void

    • OptionalincludeProvisionalEvents: boolean

      Optional parameter. Set to true if you want to include provisional events. Default is false.

    Returns Promise<EmitterSubscription>

    A Promise that resolves with a subscription object that you can use to remove the set listener.

    You can use this function along with getTimelineUpdates to stay up to date with the latest events in the timeline. For example, to make sure you don't miss out on timeline updates, you can first set an update listener using this method, then follow up by calling getTimelineUpdates to query for potential updates since the last update you received.

    import timeline from "@sentiance-react-native/event-timeline";

    // Set a timeline updater listener for non-provisional updates
    const subscription = await timeline.addTimelineUpdateListener(
    (event) => console.log(event)
    );

    // Remove the listener
    await subscription.remove();
  • Returns the timeline event with the specified ID.

    Parameters

    • eventId: string

      The ID of the event to query.

    Returns Promise<null | Event>

    A Promise that resolves with a matching Event object, or null if no such event exists.

    import eventTimeline from "@sentiance-react-native/event-timeline";
    const event: Event | null = await eventTimeline.getTimelineEvent("some_event_id");
  • Returns timeline events, such as transport and stationary events, that were captured during the specified time range. The events are ordered from oldest to newest.

    Parameters

    • fromEpochTimeMs: number

      The start timestamp (in milliseconds, inclusive) of the time range.

    • toEpochTimeMs: number

      The end timestamp (in milliseconds, inclusive) of the time range.

    • OptionalincludeProvisionalEvents: boolean

      Optional parameter. Set to true if you want to include provisional events. Default is false.

    Returns Promise<Event[]>

    A Promise that resolves with an array of Event objects that occurred in the specified time range. If no events are found, an empty array is returned.

    Events that were captured outside the specified date range are not returned, even if they were updated during this date range. To get all updates, regardless of when an event was captured, use the getTimelineUpdates function instead.

    import eventTimeline from "@sentiance-react-native/event-timeline";

    // Get all timeline events including provisional ones
    const events = await eventTimeline.getTimelineEvents(0, Date.now(), true);
  • Returns all updated events in the event timeline after the specified date, sorted by the last update time.

    Parameters

    • afterEpochTimeMs: number

      The timestamp (in milliseconds) to retrieve updates from. The specified timestamp is exclusive.

    • OptionalincludeProvisionalEvents: boolean

      Optional parameter. Set to true if you want to include provisional events. Default is false.

    Returns Promise<Event[]>

    A Promise that resolves with an array of Event objects that occurred in the specified time range. If no events are found, an empty array is returned.

    This method returns all events that started after afterEpochTimeMs, but it may also return events that started before afterEpochTimeMs, if they were updated afterward. The returned result is not necessarily the complete list of events that were captured by the SDK from the result's first event until the last, because events that were not updated will be excluded. To get a complete and ordered list of events for a given date range, use getTimelineEvents instead.

    You can use this method along with addTimelineUpdateListener to stay up to date with the latest events in the timeline. For example, to make sure you don't miss out on timeline updates, you can first set an update listener, then follow up by using this method to query for potential updates since the last update you received.

    import timeline from "@sentiance-react-native/event-timeline";

    // Get timeline updates including provisional events from one hour ago
    const oneHourAgo = Date.now() - (60 * 60 * 1000);
    const events = await timeline.getTimelineUpdates(oneHourAgo, true);
  • Sets the tags that will be assigned to a detected transport.

    Parameters

    Returns Promise<void>

    The provided tags will be assigned to a transport at the moment the transport ends. When you receive an Event representing the ended transport, it will include these tags.

    The supplied tags are persisted and applied to future transports, even after the app is restarted. By calling this method again, you will replace the tags that will be assigned to future transports.

    You can include up to 6 tags (key-value pairs), and each tag component (key or value) must be at most 256 characters.

    try {
    await SentianceEventTimeline.setTransportTags({
    key1: "value1",
    key2: "value2"
    });
    console.log('Transport tags have been set.');
    } catch (error) {
    if (error instanceof TransportTagsError) {
    console.error(`Failed to set transport tags: ${error.message}`);
    } else {
    console.error(`Error: ${error.message}`);
    }
    }

    TransportTaggingError if the supplied tags count is more than 6, or if one of the tag components exceeds the 256 characters limit.

  • Starts delivering periodic trip location updates to the provided listener. To stop the updates, call stopReceivingTripLocationUpdates.

    Parameters

    • intervalInSeconds: number

      The desired time interval, in seconds, between successive location updates. Must be at least 1 second. The actual delivery cadence may vary depending on system conditions.

    • onLocationReceived: ((location: TripLocation) => void)

      A listener that is invoked with the user's current location during a trip.

        • (location): void
        • Parameters

          Returns void

    Returns Promise<TripLocationUpdatesStartResult>

    A Promise that resolves with a TripLocationUpdatesStartResult describing whether updates were started successfully or the reason they could not be started. If the result is not SUCCESS, any previously registered listener is left unchanged.

    • If this method returns SUCCESS, the provided listener becomes the active listener. A previously registered listener will no longer receive trip location updates.
    • If this method returns any value other than SUCCESS, no changes will be made to the previously registered listener. It remains active and continues receiving location updates.
    import SentianceEventTimeline from "@sentiance-react-native/event-timeline";

    const intervalInSeconds = 10;
    const result = await SentianceEventTimeline.startReceivingTripLocationUpdates(
    intervalInSeconds,
    (tripLocation) => console.log(tripLocation),
    );

    if (result === "SUCCESS") {
    console.log("Trip location updates started successfully");
    }
  • Stops delivering trip location updates.

    Returns Promise<void>

    Call this method to stop delivery of location updates to the listener that you previously supplied to startReceivingTripLocationUpdates.