Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: replaced deprecated event emitter
Browse files Browse the repository at this point in the history
Arthur Geron committed Aug 28, 2023

Unverified

No user is associated with the committer email.
1 parent 60639ea commit dfc3e83
Showing 1 changed file with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@ import com.facebook.react.bridge.LifecycleEventListener
import com.facebook.react.bridge.ReactContext
import com.facebook.react.bridge.ReadableMap
import com.facebook.react.uimanager.ThemedReactContext
import com.facebook.react.uimanager.events.RCTEventEmitter
import com.facebook.react.uimanager.events.RCTModernEventEmitter
import java.util.*
import java.util.concurrent.TimeUnit
import kotlin.concurrent.timerTask
@@ -123,7 +123,7 @@ class AmazonIvsView(private val context: ThemedReactContext) : FrameLayout(conte
finishedLoading = false
player.load(uri)

reactContext.getJSModule(RCTEventEmitter::class.java).receiveEvent(id, Events.LOAD_START.toString(), Arguments.createMap())
reactContext.getJSModule(RCTModernEventEmitter::class.java).receiveEvent(id, Events.LOAD_START.toString(), Arguments.createMap())
}
}

@@ -215,7 +215,7 @@ class AmazonIvsView(private val context: ThemedReactContext) : FrameLayout(conte
val data = Arguments.createMap()
data.putMap("textCue", textCue)

reactContext.getJSModule(RCTEventEmitter::class.java).receiveEvent(id, Events.CUE.toString(), data)
reactContext.getJSModule(RCTModernEventEmitter::class.java).receiveEvent(id, Events.CUE.toString(), data)
}

fun setMaxBitrate(bitrate: Double) {
@@ -239,7 +239,7 @@ class AmazonIvsView(private val context: ThemedReactContext) : FrameLayout(conte
val data = Arguments.createMap()
data.putMap("textMetadataCue", textMetadataCue)

reactContext.getJSModule(RCTEventEmitter::class.java).receiveEvent(id, Events.METADATA_CUE.toString(), data)
reactContext.getJSModule(RCTModernEventEmitter::class.java).receiveEvent(id, Events.METADATA_CUE.toString(), data)
}

fun onDurationChange(duration: Long) {
@@ -248,29 +248,29 @@ class AmazonIvsView(private val context: ThemedReactContext) : FrameLayout(conte
val parsedDuration = getDuration(duration);
data.putDouble("duration", parsedDuration)

reactContext.getJSModule(RCTEventEmitter::class.java).receiveEvent(id, Events.DURATION_CHANGED.toString(), data)
reactContext.getJSModule(RCTModernEventEmitter::class.java).receiveEvent(id, Events.DURATION_CHANGED.toString(), data)
}

fun onError(error: String) {
val reactContext = context as ReactContext
val data = Arguments.createMap()
data.putString("error", error)

reactContext.getJSModule(RCTEventEmitter::class.java).receiveEvent(id, Events.ERROR.toString(), data)
reactContext.getJSModule(RCTModernEventEmitter::class.java).receiveEvent(id, Events.ERROR.toString(), data)
}

fun onSeek(position: Long) {
val reactContext = context as ReactContext
val data = Arguments.createMap()
data.putDouble("position", convertMilliSecondsToSeconds(position))
reactContext.getJSModule(RCTEventEmitter::class.java).receiveEvent(id, Events.SEEK.toString(), data)
reactContext.getJSModule(RCTModernEventEmitter::class.java).receiveEvent(id, Events.SEEK.toString(), data)
}

fun onProgress(position: Long) {
val reactContext = context as ReactContext
val data = Arguments.createMap()
data.putDouble("position", convertMilliSecondsToSeconds(position))
reactContext.getJSModule(RCTEventEmitter::class.java).receiveEvent(id, Events.PROGRESS.toString(), data)
reactContext.getJSModule(RCTModernEventEmitter::class.java).receiveEvent(id, Events.PROGRESS.toString(), data)
}

private fun convertMilliSecondsToSeconds (milliSeconds: Long): Double {
@@ -314,7 +314,7 @@ class AmazonIvsView(private val context: ThemedReactContext) : FrameLayout(conte

finishedLoading = true

reactContext.getJSModule(RCTEventEmitter::class.java).receiveEvent(id, Events.LOAD.toString(), onLoadData)
reactContext.getJSModule(RCTModernEventEmitter::class.java).receiveEvent(id, Events.LOAD.toString(), onLoadData)
}
}
READY -> {
@@ -337,7 +337,7 @@ class AmazonIvsView(private val context: ThemedReactContext) : FrameLayout(conte
playerData.putArray("qualities", qualities)
data.putMap("playerData", playerData)

reactContext.getJSModule(RCTEventEmitter::class.java).receiveEvent(id, Events.DATA.toString(), data)
reactContext.getJSModule(RCTModernEventEmitter::class.java).receiveEvent(id, Events.DATA.toString(), data)
};
BUFFERING -> {} // The following empty statements are intentional and avoid Kotlin’s "expression must be exhaustive" error.
IDLE -> {}
@@ -346,7 +346,7 @@ class AmazonIvsView(private val context: ThemedReactContext) : FrameLayout(conte

val onStateChangeData = Arguments.createMap()
onStateChangeData.putString("state", mapPlayerState(state))
reactContext.getJSModule(RCTEventEmitter::class.java).receiveEvent(id, Events.STATE_CHANGED.toString(), onStateChangeData)
reactContext.getJSModule(RCTModernEventEmitter::class.java).receiveEvent(id, Events.STATE_CHANGED.toString(), onStateChangeData)
}

fun onQualityChange(quality: Quality) {
@@ -363,12 +363,12 @@ class AmazonIvsView(private val context: ThemedReactContext) : FrameLayout(conte
val data = Arguments.createMap()
data.putMap("quality", newQuality)

reactContext.getJSModule(RCTEventEmitter::class.java).receiveEvent(id, Events.QUALITY_CHANGED.toString(), data)
reactContext.getJSModule(RCTModernEventEmitter::class.java).receiveEvent(id, Events.QUALITY_CHANGED.toString(), data)
}

fun onPlayerRebuffering() {
val reactContext = context as ReactContext
reactContext.getJSModule(RCTEventEmitter::class.java).receiveEvent(id, Events.REBUFFERING.toString(), Arguments.createMap())
reactContext.getJSModule(RCTModernEventEmitter::class.java).receiveEvent(id, Events.REBUFFERING.toString(), Arguments.createMap())
}

private fun intervalHandler() {
@@ -382,7 +382,7 @@ class AmazonIvsView(private val context: ThemedReactContext) : FrameLayout(conte
} ?: run {
liveLatencyData.putNull("liveLatency")
}
reactContext.getJSModule(RCTEventEmitter::class.java).receiveEvent(id, Events.LIVE_LATENCY_CHANGED.toString(), liveLatencyData)
reactContext.getJSModule(RCTModernEventEmitter::class.java).receiveEvent(id, Events.LIVE_LATENCY_CHANGED.toString(), liveLatencyData)

lastLiveLatency = player?.liveLatency
}
@@ -406,7 +406,7 @@ class AmazonIvsView(private val context: ThemedReactContext) : FrameLayout(conte
}

onVideoData.putMap("videoData", videoData)
reactContext.getJSModule(RCTEventEmitter::class.java).receiveEvent(id, Events.VIDEO_STATISTICS.toString(), onVideoData)
reactContext.getJSModule(RCTModernEventEmitter::class.java).receiveEvent(id, Events.VIDEO_STATISTICS.toString(), onVideoData)

lastBitrate = player?.averageBitrate
lastDuration = player?.duration

0 comments on commit dfc3e83

Please sign in to comment.