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.
| Platform | Handler | What you get |
Swift (KinesteXAIKit) | onMessageReceived: (KinestexMessage) -> Void | An enum case carrying the whole event as [String: Any] |
| Kotlin | onMessageReceived: (WebViewMessage) -> Unit | A WebViewMessage subclass; the whole event is in message.data |
| Flutter | onMessageReceived: (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/JS | window.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.
| Event | Swift KinestexMessage | Kotlin WebViewMessage | Flutter WebViewMessage |
| kinestex_loaded | .kinestex_loaded | KinestexLoaded | KinestexLoaded |
| kinestex_launched | .kinestex_launched | KinestexLaunched | KinestexLaunched |
| error_occurred | .error_occurred | ErrorOccurred | ErrorOccurred |
| exit_kinestex | .exit_kinestex | ExitKinestex | ExitKinestex |
| workout_opened | .workout_opened | WorkoutOpened | WorkoutOpened |
| workout_started | .workout_started | WorkoutStarted | WorkoutStarted |
| exercise_completed | .exercise_completed | ExerciseCompleted | ExerciseCompleted |
| successful_repeat | .reps | Reps | Reps |
| mistake | .mistake | Mistake | Mistake |
| left_camera_frame | .left_camera_frame | LeftCameraFrame | LeftCameraFrame |
| returned_camera_frame | .returned_camera_frame | ReturnedCameraFrame | ReturnedCameraFrame |
| workout_overview | .workout_overview | WorkoutOverview | WorkoutOverview |
| exercise_overview | .exercise_overview | ExerciseOverview | ExerciseOverview |
| workout_completed | .workout_completed | WorkoutCompleted | WorkoutCompleted |
| all_resources_loaded | .custom_type (see below) | AllResourcesLoaded | CustomType |
| workout_exit_request | .custom_type | WorkoutExitRequest | CustomType |
| workout_completion_overlay_dismissed | .custom_type | WorkoutCompletionOverlayDismissed | CustomType |
| exit_leaderboard | .custom_type | CustomType | ExitLeaderboard |
| workout_session_saved | .custom_type | CustomType | WorkoutSessionSaved |
Every other event (workout_progress, action, presence, feedback and the rest) | .custom_type | CustomType | CustomType |
- Swift (
KinesteXAIKit1.1.8) declares.all_resources_loadedbut never produces it:all_resources_loadedarrives as.custom_type, so match it there. finished_workoutandplan_unlockedstill have a case or class in the three native SDKs, but KinesteX no longer sends them. For the end of a workout useworkout_ended(the run ended) andworkout_completed(the user left the results screen).- Of the real-time motion events, only
successful_repeat,mistake,left_camera_frameandreturned_camera_frameare typed.action,presence,feedbackand the rest arrive ascustom_type/CustomType. - Kotlin turns JSON
nullinto an empty string"", so treat both as "no value" (for examplehint,body_regionorstart_position). In Swift anullarrives asNSNull.
Events the SDK creates itself. A few events come from the SDK, not from KinesteX:
- Kotlin and Flutter send
exit_kinestexwith onlytypeandtimestampwhen 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_kinestexwithmessage: "User pressed back button"on the Android back button when KinesteX cannot go back, anderror_occurredwithmessageanderrorCode(noseverity) when the WebView fails to load. Neither hastimestamp.
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}