Skip to content

Commit

Permalink
ensure beacon call captures view scope synchronously
Browse files Browse the repository at this point in the history
  • Loading branch information
sugarmanz committed Mar 4, 2024
1 parent 89be4d6 commit d79e32e
Showing 1 changed file with 9 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package com.intuit.playerui.plugins.beacon

import com.intuit.playerui.core.asset.Asset
import com.intuit.playerui.core.bridge.getInvokable
import com.intuit.playerui.core.bridge.runtime
import com.intuit.playerui.core.bridge.runtime.Runtime
import com.intuit.playerui.core.bridge.runtime.ScriptContext
import com.intuit.playerui.core.bridge.runtime.add
Expand All @@ -13,7 +12,6 @@ import com.intuit.playerui.core.plugins.JSScriptPluginWrapper
import com.intuit.playerui.core.plugins.Pluggable
import com.intuit.playerui.core.plugins.findPlugin
import com.intuit.playerui.plugins.settimeout.SetTimeoutPlugin
import kotlinx.coroutines.launch
import kotlinx.serialization.Contextual
import kotlinx.serialization.Serializable
import kotlinx.serialization.json.Json
Expand Down Expand Up @@ -57,18 +55,17 @@ public class BeaconPlugin(override val plugins: List<JSPluginWrapper>) : JSScrip
handlers.add(handler)
}

// TODO: Convert to suspend method to ensure view scope is captured in a non-blocking way
/** Fire a beacon event */
public fun beacon(action: String, element: String, asset: Asset, data: Any? = null) {
runtime.scope.launch {
instance.getInvokable<Any?>("beacon")!!.invoke(
mapOf(
"action" to action,
"element" to element,
"asset" to asset,
"data" to data,
),
)
}
instance.getInvokable<Any?>("beacon")!!.invoke(
mapOf(
"action" to action,
"element" to element,
"asset" to asset,
"data" to data,
),
)
}

private companion object {
Expand Down

0 comments on commit d79e32e

Please sign in to comment.