-
Couldn't load subscription status.
- Fork 176
[sdk] Add MapRecorder support for Flutter SDK #1049
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: public/protheeuz-map-recorder-support
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| package com.mapbox.maps.mapbox_maps | ||
|
|
||
| import com.mapbox.bindgen.DataRef | ||
| import com.mapbox.maps.MapboxExperimental | ||
| import com.mapbox.maps.MapboxMap | ||
| import com.mapbox.maps.MapboxMapRecorder | ||
| import com.mapbox.maps.mapbox_maps.pigeons.MapPlayerOptions | ||
| import com.mapbox.maps.mapbox_maps.pigeons.MapRecorderOptions | ||
| import com.mapbox.maps.mapbox_maps.pigeons._MapRecorderMessenger | ||
| import java.nio.ByteBuffer | ||
|
|
||
| /** | ||
| * Controller for MapRecorder functionality. | ||
| * | ||
| * Provides functions to record and replay API calls of a MapboxMap instance. | ||
| * These recordings can be used to debug issues which require multiple steps to reproduce. | ||
| * Additionally, playbacks can be used for performance testing custom scenarios. | ||
| */ | ||
| @OptIn(MapboxExperimental::class) | ||
| class MapRecorderController( | ||
| private val mapboxMap: MapboxMap | ||
| ) : _MapRecorderMessenger { | ||
|
|
||
| private var recorder: MapboxMapRecorder? = null | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be cleaned up to avoid memory leaks. Please add a fun dispose() {
recorder = null
}And then in override fun dispose() {
if (mapView == null) {
return
}
lifecycleHelper?.dispose()
lifecycleHelper = null
mapView?.setViewTreeLifecycleOwner(null)
mapView = null
mapboxMap = null
methodChannel.setMethodCallHandler(null)
StyleManager.setUp(messenger, null, channelSuffix)
_CameraManager.setUp(messenger, null, channelSuffix)
Projection.setUp(messenger, null, channelSuffix)
_MapInterface.setUp(messenger, null, channelSuffix)
_AnimationManager.setUp(messenger, null, channelSuffix)
annotationController.dispose()
_LocationComponentSettingsInterface.setUp(messenger, null, channelSuffix)
LogoSettingsInterface.setUp(messenger, null, channelSuffix)
GesturesSettingsInterface.setUp(messenger, null, channelSuffix)
CompassSettingsInterface.setUp(messenger, null, channelSuffix)
ScaleBarSettingsInterface.setUp(messenger, null, channelSuffix)
AttributionSettingsInterface.setUp(messenger, null, channelSuffix)
_ViewportMessenger.setUp(messenger, null, channelSuffix)
_PerformanceStatisticsApi.setUp(messenger, null, channelSuffix)
_MapRecorderMessenger.setUp(messenger, null, channelSuffix) // ← ADD THIS
mapRecorderController.dispose() // ← ADD THIS
} |
||
|
|
||
| /** | ||
| * Get or create the recorder instance. | ||
| */ | ||
| private fun getRecorder(): MapboxMapRecorder { | ||
| if (recorder == null) { | ||
| recorder = mapboxMap.createRecorder() | ||
| } | ||
| return recorder!! | ||
| } | ||
|
|
||
| override fun startRecording(options: MapRecorderOptions) { | ||
| val nativeOptions = com.mapbox.maps.MapRecorderOptions.Builder() | ||
| .apply { | ||
| options.timeWindow?.let { timeWindow(it.toLong()) } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this |
||
| loggingEnabled(options.loggingEnabled) | ||
| compressed(options.compressed) | ||
| } | ||
| .build() | ||
|
|
||
| getRecorder().startRecording(nativeOptions) | ||
| } | ||
|
|
||
| override fun stopRecording(callback: (Result<ByteArray>) -> Unit) { | ||
| try { | ||
| val data = getRecorder().stopRecording() | ||
| val bytes = ByteArray(data.remaining()) | ||
| data.get(bytes) | ||
| data.rewind() | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think that this |
||
| callback(Result.success(bytes)) | ||
| } catch (e: Exception) { | ||
| callback(Result.failure(e)) | ||
| } | ||
| } | ||
|
|
||
| override fun replay( | ||
| recordedSequence: ByteArray, | ||
| options: MapPlayerOptions, | ||
| callback: (Result<Unit>) -> Unit | ||
| ) { | ||
| try { | ||
| val nativeOptions = com.mapbox.maps.MapPlayerOptions.Builder() | ||
| .playbackCount(options.playbackCount.toInt()) | ||
| .playbackSpeedMultiplier(options.playbackSpeedMultiplier) | ||
| .avoidPlaybackPauses(options.avoidPlaybackPauses) | ||
| .build() | ||
|
|
||
| val buffer = ByteBuffer.wrap(recordedSequence) | ||
| getRecorder().replay(buffer, nativeOptions) { | ||
| callback(Result.success(Unit)) | ||
| } | ||
| } catch (e: Exception) { | ||
| callback(Result.failure(e)) | ||
| } | ||
| } | ||
|
|
||
| override fun togglePauseReplay() { | ||
| getRecorder().togglePauseReplay() | ||
| } | ||
|
|
||
| override fun getPlaybackState(): String { | ||
| return getRecorder().getPlaybackState() | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this import can be removed