Skip to content

Commit

Permalink
try to disable event service for the SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
RingerJK committed Apr 28, 2023
1 parent b4dd046 commit cb08bf8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ object MapboxMetricsReporter : MetricsReporter {
private const val LOG_CATEGORY = "MapboxMetricsReporter"

private val gson = Gson()
private lateinit var eventsManager: EventsServiceInterfacesManager
// private lateinit var eventsManager: EventsServiceInterfacesManager
private lateinit var telemetryService: TelemetryService

@Volatile
Expand Down Expand Up @@ -86,10 +86,10 @@ object MapboxMetricsReporter : MetricsReporter {
userAgent: String
) {
isTelemetryInitialized = true
eventsManager = TelemetryEventsProvider.getOrCreateTelemetryEventsManager(accessToken)
// eventsManager = TelemetryEventsProvider.getOrCreateTelemetryEventsManager(accessToken)
val eventsServerOptions = EventsServerOptions(accessToken, userAgent, null)
telemetryService = TelemetryServiceProvider.provideTelemetryService(eventsServerOptions)
eventsManager.nativeEventsServiceInterface.registerObserver(eventsServiceObserver)
// eventsManager.nativeEventsServiceInterface.registerObserver(eventsServiceObserver)
}

/**
Expand All @@ -111,7 +111,7 @@ object MapboxMetricsReporter : MetricsReporter {
fun disable() {
isTelemetryInitialized = false
removeObserver()
eventsManager.nativeEventsServiceInterface.unregisterObserver(eventsServiceObserver)
// eventsManager.nativeEventsServiceInterface.unregisterObserver(eventsServiceObserver)
ioJobController.job.cancelChildren()
}

Expand All @@ -127,13 +127,13 @@ object MapboxMetricsReporter : MetricsReporter {
)
return
}
eventsManager.nativeEventsServiceInterface.sendEvent(
Event(eventsPriority, metricEvent.toValue(), null)
) {
if (it != null) {
logE("Failed to send event ${metricEvent.metricName}: $it", LOG_CATEGORY)
}
}
// eventsManager.nativeEventsServiceInterface.sendEvent(
// Event(eventsPriority, metricEvent.toValue(), null)
// ) {
// if (it != null) {
// logE("Failed to send event ${metricEvent.metricName}: $it", LOG_CATEGORY)
// }
// }

ioJobController.scope.launch {
metricsObserver?.onMetricUpdated(metricEvent.metricName, metricEvent.toJson(gson))
Expand All @@ -146,11 +146,11 @@ object MapboxMetricsReporter : MetricsReporter {
*/
override fun sendTurnstileEvent(turnstileEvent: TurnstileEvent) {
ifTelemetryIsRunning {
eventsManager.nativeEventsServiceInterface.sendTurnstileEvent(turnstileEvent) {
if (it != null) {
logE("Failed to send Turnstile event: $it", LOG_CATEGORY)
}
}
// eventsManager.nativeEventsServiceInterface.sendTurnstileEvent(turnstileEvent) {
// if (it != null) {
// logE("Failed to send Turnstile event: $it", LOG_CATEGORY)
// }
// }
}
}

Expand All @@ -172,14 +172,14 @@ object MapboxMetricsReporter : MetricsReporter {
* Register [EventsServiceObserver]
*/
fun registerEventsServiceObserver(observer: EventsServiceObserver) {
eventsManager.nativeEventsServiceInterface.registerObserver(observer)
// eventsManager.nativeEventsServiceInterface.registerObserver(observer)
}

/**
* Unregister [EventsServiceObserver]
*/
fun unregisterEventsServiceObserver(observer: EventsServiceObserver) {
eventsManager.nativeEventsServiceInterface.unregisterObserver(observer)
// eventsManager.nativeEventsServiceInterface.unregisterObserver(observer)
}

private inline fun ifTelemetryIsRunning(func: () -> Unit) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.mapbox.common.EventsServerOptions
import com.mapbox.common.EventsService

object TelemetryEventsProvider {
fun getOrCreateTelemetryEventsManager(accessToken: String): EventsServiceInterfacesManager =
fun getOrCreateEventsServiceInterfacesManager(accessToken: String): EventsServiceInterfacesManager =
EventsServiceInterfacesManager(
EventsService.getOrCreate(
EventsServerOptions(accessToken, "MapboxNavigationNative", null)
Expand Down

0 comments on commit cb08bf8

Please sign in to comment.