KinesteX

Receiving Data

Each platform delivers every KinesteX event to one handler. An event is a JSON object with a type; the pages in this section list its other fields.


PlatformHandlerWhat you get
Swift (KinesteXAIKit)onMessageReceived: (KinestexMessage) -> VoidAn enum case carrying the whole event as [String: Any]
KotlinonMessageReceived: (WebViewMessage) -> UnitA WebViewMessage subclass; the whole event is in message.data
FlutteronMessageReceived: (WebViewMessage)A WebViewMessage subclass; the whole event is in message.data
React Native, React (kinestex-sdk-react-ts)handleMessage(type, data)The raw type string, and the whole event as data
HTML/JSwindow.addEventListener("message", ...)event.data, a JSON string to parse

You get the whole event. Every SDK hands you the full object, type and timestamp included. Fields the tables show under data are one level down: the calories of workout_overview are in data.data.calories_burned (React Native), message.data["data"] (Kotlin) or json["data"] (Swift), not at the top level.


Every event has `timestamp`: milliseconds since the Unix epoch, taken from the device clock when the event fired. Only the few events an SDK creates on its own (see below) can lack it.


Handle what you know, ignore the rest. KinesteX only adds to its events: new event types, new fields and new values (for example a new kind, state or exit_type) can appear in any release, and existing ones are never renamed or removed. Ignore types, fields and values you do not know, and let your switch fall through to doing nothing, so a new KinesteX release never breaks your integration.


Typed events per SDK. Swift, Kotlin and Flutter give some events a case or class of their own. Every other event arrives as custom_type (Swift) or CustomType (Kotlin, Flutter), with the event's type in its data. React Native, React and HTML/JS have no types: you switch on the raw type string for every event.


EventSwift KinestexMessageKotlin WebViewMessageFlutter WebViewMessage
kinestex_loaded.kinestex_loadedKinestexLoadedKinestexLoaded
kinestex_launched.kinestex_launchedKinestexLaunchedKinestexLaunched
error_occurred.error_occurredErrorOccurredErrorOccurred
exit_kinestex.exit_kinestexExitKinestexExitKinestex
workout_opened.workout_openedWorkoutOpenedWorkoutOpened
workout_started.workout_startedWorkoutStartedWorkoutStarted
exercise_completed.exercise_completedExerciseCompletedExerciseCompleted
successful_repeat.repsRepsReps
mistake.mistakeMistakeMistake
left_camera_frame.left_camera_frameLeftCameraFrameLeftCameraFrame
returned_camera_frame.returned_camera_frameReturnedCameraFrameReturnedCameraFrame
workout_overview.workout_overviewWorkoutOverviewWorkoutOverview
exercise_overview.exercise_overviewExerciseOverviewExerciseOverview
workout_completed.workout_completedWorkoutCompletedWorkoutCompleted
all_resources_loaded.custom_type (see below)AllResourcesLoadedCustomType
workout_exit_request.custom_typeWorkoutExitRequestCustomType
workout_completion_overlay_dismissed.custom_typeWorkoutCompletionOverlayDismissedCustomType
exit_leaderboard.custom_typeCustomTypeExitLeaderboard
workout_session_saved.custom_typeCustomTypeWorkoutSessionSaved
Every other event (workout_progress, action, presence, feedback and the rest).custom_typeCustomTypeCustomType

  • Swift (KinesteXAIKit 1.1.8) declares .all_resources_loaded but never produces it: all_resources_loaded arrives as .custom_type, so match it there.
  • finished_workout and plan_unlocked still have a case or class in the three native SDKs, but KinesteX no longer sends them. For the end of a workout use workout_ended (the run ended) and workout_completed (the user left the results screen).
  • Of the real-time motion events, only successful_repeat, mistake, left_camera_frame and returned_camera_frame are typed. action, presence, feedback and the rest arrive as custom_type / CustomType.
  • Kotlin turns JSON null into an empty string "", so treat both as "no value" (for example hint, body_region or start_position). In Swift a null arrives as NSNull.

Events the SDK creates itself. A few events come from the SDK, not from KinesteX:

  • Kotlin and Flutter send exit_kinestex with only type and timestamp when the user taps back on the SDK's own loading or retry screen (Flutter also on the system back gesture when KinesteX cannot go back).
  • React Native sends exit_kinestex with message: "User pressed back button" on the Android back button when KinesteX cannot go back, and error_occurred with message and errorCode (no severity) when the WebView fails to load. Neither has timestamp.
Platform-Specific Data Handlers
Swift example:
1// onMessageReceived: (KinestexMessage) -> Void
2// Every case carries the whole event as [String: Any]: "type", "timestamp" and every field
3func handle(_ message: KinestexMessage) {
4    switch message {
5    case .kinestex_launched(let json):
6        print("Launched at:", json["data"] ?? "")
7    case .exit_kinestex(let json):
8        print("Exited, time spent:", json["time_spent"] ?? "")
9    case .exercise_completed(let json):
10        let exercise = json["data"] as? [String: Any]
11        print("Exercise done:", exercise?["exercise_title"] ?? "")
12    case .reps(let json): // successful_repeat
13        print("Rep", json["value"] ?? 0, "of", json["exercise"] ?? "")
14    case .workout_overview(let json):
15        let overview = json["data"] as? [String: Any]
16        print("Calories:", overview?["calories_burned"] ?? 0)
17    case .error_occurred(let json):
18        print("Error:", json["severity"] ?? "", json["data"] ?? json["message"] ?? "")
19    case .custom_type(let json):
20        // Every event without a case of its own, including all_resources_loaded
21        switch json["type"] as? String {
22        case "workout_progress":
23            print("Progress:", json["data"] ?? "")
24        case "all_resources_loaded":
25            print("Custom workout ready")
26        default:
27            break // ignore events you don't use
28        }
29    default:
30        break
31    }
32}