Skip to content
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

Release 1.7.0: Develop to main #1064

Merged
merged 130 commits into from Jun 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
130 commits
Select commit Hold shift + click to select a range
a0649d1
updated package version
ygit May 18, 2023
4018d2b
feat(sdk): :sparkles: added HMS Native Android HLSPlayer
stanwolverine May 22, 2023
235a488
feat(example-app): :sparkles: added 100ms HLSPlayer usage in android app
stanwolverine May 22, 2023
876e4f9
updated packages
ygit May 22, 2023
19245de
Merge branch 'develop' into issue-878-hls-player
ygit May 22, 2023
f887e32
released sample app version 2.1.66 (202) ⚛️
ygit May 22, 2023
0bf99c0
updated Android SDK version to 2.6.5
ygit May 23, 2023
9588eaf
build(deps): bump activesupport in /sample-apps/rn-quickstart-app
dependabot[bot] May 24, 2023
066ce96
Merge pull request #1050 from 100mslive/dependabot/bundler/sample-app…
ygit May 24, 2023
d6767bc
refactor(sdk): :fire: removed `customerDescription` property from HMS…
stanwolverine May 24, 2023
ae68b5d
refactor(sdk): reduced new object creations while updating peers cache
stanwolverine May 24, 2023
b416c54
refactor(sdk): getHmsPeerSubsetForPeerUpdateEvent method code refacto…
stanwolverine May 24, 2023
88d73d7
updated Example app version
ygit May 25, 2023
226048f
updated packages
ygit May 25, 2023
907ed97
removed unnecessary sending of message
ygit May 25, 2023
a9c47ff
improved check for sending peer updates
ygit May 25, 2023
16fe8b1
navigating to Home Screen when destroy succeeds
ygit May 25, 2023
cd6fce6
corrected lint warnings
ygit May 25, 2023
3b4ce3d
updated linter
ygit May 25, 2023
e2f6476
updated Changelog
ygit May 25, 2023
7bb61c6
removed unused update type parsing
ygit May 25, 2023
00431c5
feat(sdk): added reanimated lib as peerDependency
stanwolverine May 25, 2023
3f90d06
feat(rn-quickstart-app): added emojis hls timedata support in example…
stanwolverine May 25, 2023
0964f5e
Merge branch 'reduced-object-creation-changes' of https://github.com/…
stanwolverine May 25, 2023
e25ab4d
feat(sdk): added hls-player-stats support in android sdk
stanwolverine May 29, 2023
5cc1d79
feat(example-app): added hls-player-stats usage in app
stanwolverine May 29, 2023
3ba5370
feat(sdk): added hms hls-player support in rn ios
stanwolverine May 29, 2023
896794f
Merge branch 'issue-878-hls-player' of https://github.com/100mslive/r…
stanwolverine May 29, 2023
0e7d0ba
released sample ios app version 2.1.71 (207) ⚛️
stanwolverine May 29, 2023
e1681f0
fix(sdk): hooks usage inside function
stanwolverine May 30, 2023
1283a87
fix(example-app): :bug: reanimated lib crash due to proguard usage in…
stanwolverine May 30, 2023
98d4c22
Merge branch 'issue-878-hls-player' of https://github.com/100mslive/r…
stanwolverine May 30, 2023
f846fcd
build(example-app): updated android app release build version 2.1.72
stanwolverine May 30, 2023
6836f5f
refactor(sdk): :recycle: android sdk HLS player events changes
stanwolverine Jun 1, 2023
30283c7
refactor(sdk): :recycle: android sdk improvements
stanwolverine Jun 1, 2023
c0ed074
feat(sdk): :sparkles: added HLS playback and stats events support on …
stanwolverine Jun 1, 2023
22c0a51
feat(sdk): :sparkles: added zustand store for HLS player playback and…
stanwolverine Jun 1, 2023
8583dc2
refactor(example-app): :recycle: refactored HLS player implementations
stanwolverine Jun 1, 2023
aa82c42
Merge branch 'issue-878-hls-player' of https://github.com/100mslive/r…
stanwolverine Jun 1, 2023
cb9fca5
Merge branch 'bug/1056-ios-app-crashing-on-rejoin' into release1.7.0-rc
ygit Jun 1, 2023
a6dcf57
released sample app version 2.1.70 (206) ⚛️
ygit Jun 1, 2023
3c71739
updated gems
ygit Jun 1, 2023
8ddcc8b
feat(sdk): :sparkles: added option to enable/disable player controls
stanwolverine Jun 2, 2023
f5df352
feat(sdk): :sparkles: added option to change aspect ratio of HLS player
stanwolverine Jun 2, 2023
e9b5714
feat(example-app): using enableControls and aspect ratio configs of H…
stanwolverine Jun 2, 2023
56f8c1e
Merge branch 'issue-878-hls-player' of https://github.com/100mslive/r…
stanwolverine Jun 2, 2023
50996b9
Merge branch 'release1.7.0-rc' of https://github.com/100mslive/react-…
stanwolverine Jun 2, 2023
8218700
released sample app version 2.1.71 (207) ⚛️
ygit Jun 2, 2023
a5f0448
feat(example-app): :sparkles: added Modal UI to change HLS Player Asp…
stanwolverine Jun 2, 2023
4fc5ca0
Merge branch 'issue-878-hls-player' of https://github.com/100mslive/r…
stanwolverine Jun 2, 2023
c68badc
Merge branch 'release1.7.0-rc' of https://github.com/100mslive/react-…
stanwolverine Jun 2, 2023
a6f3769
refactor(example-app): :fire: removed react-native-video lib and othe…
stanwolverine Jun 2, 2023
2e5c6ea
updated packages
ygit Jun 2, 2023
5298143
ios switch audio output (#1060)
stanwolverine Jun 5, 2023
1075e2e
Android sdk upgrade to 2.6.7 (#1061)
stanwolverine Jun 5, 2023
964e4f2
Ios sdk upgrade to 0.9.5 (#1062)
stanwolverine Jun 5, 2023
80bd24e
Reduced new object creation in HMSPeerCache (#1063)
stanwolverine Jun 5, 2023
71dbe4b
Bug/1056 ios app crashing on rejoin (#1057)
ygit Jun 5, 2023
f5c6da1
Merge branch 'develop' into release1.7.0-rc
ygit Jun 5, 2023
922b7a1
updated from develop
ygit Jun 5, 2023
8a4d374
corrected swift lint warnings
ygit Jun 5, 2023
ea51ef4
Merge branch 'develop' of https://github.com/100mslive/react-native-h…
stanwolverine Jun 5, 2023
3a2bfa9
updated changelog
ygit Jun 5, 2023
aa26bd9
Merge branch 'release1.7.0-rc' into issue-878-hls-player
ygit Jun 5, 2023
d6abdcc
RTMP streaming or recording without meeting url (#1066)
stanwolverine Jun 5, 2023
bc5fba6
fix(sdk): :bug: cacheing HMSPeer name and isLocal property at object …
stanwolverine Jun 6, 2023
c25f171
refactor(sdk): :recycle: informing HMSPeer or HMSRole "not found" on …
stanwolverine Jun 6, 2023
acd16ed
refactor(example-app): :recycle: removed spread op on HMSPeer object …
stanwolverine Jun 6, 2023
30b3b5d
updated packages
ygit Jun 6, 2023
edfe701
Merge branch 'develop' into issue-878-hls-player
ygit Jun 6, 2023
72e6470
setting default value for hardware echo cancellation to false
ygit Jun 6, 2023
474284f
updated Example app changelog
ygit Jun 6, 2023
8b028bc
refactor(sdk): caching more properties at HMSPeer object level
stanwolverine Jun 6, 2023
c8479df
refactor(example-app): minor changes
stanwolverine Jun 6, 2023
3ce6aaf
Merge commit 'c8479df51536b67cfee372bf3bae606c05509cf0' into release1…
ygit Jun 6, 2023
34d11c3
released sample app version 2.1.73 (209) ⚛️
ygit Jun 6, 2023
326c5bf
Fix: When HMSPeer leaves the Room, its properties becomes undefined (…
stanwolverine Jun 7, 2023
b7701d8
updated release shell script
ygit Jun 7, 2023
3a2a1c0
Merge branch 'develop' into issue-878-hls-player
ygit Jun 7, 2023
adff25a
Merge branch 'issue-878-hls-player' into feature/1068-enable-sw-echo-…
ygit Jun 7, 2023
444591c
Merge branch 'feature/1068-enable-sw-echo-cancellation' into release1…
ygit Jun 7, 2023
26b6277
updated packages
ygit Jun 7, 2023
634164a
style(example-app): landscape layout style updates
stanwolverine Jun 7, 2023
b481ee8
fix(sdk): :bug: peer update type ordinal value updated
stanwolverine Jun 7, 2023
753f693
Merge branch 'issue-878-hls-player' into release1.7.0-rc
ygit Jun 7, 2023
0d261ad
refactor(sdk): :fire: removed `react-native-reanimated` dependencies …
stanwolverine Jun 7, 2023
eb7af52
released sample app version 2.1.74 (210) ⚛️
ygit Jun 7, 2023
ee3fa4b
released sample app version () ⚛️
ygit Jun 7, 2023
f83ff89
updated android gradle settings
ygit Jun 7, 2023
1d65615
Merge branch 'issue-878-hls-player' into release1.7.0-rc
ygit Jun 7, 2023
c7158af
released sample app version 2.1.77 (213) ⚛️
ygit Jun 7, 2023
520fce5
updated packages
ygit Jun 8, 2023
d90e453
refactor(sdk): renamed hlsplayer to hmshlsplayer
stanwolverine Jun 8, 2023
dc88929
using renamed hmssdk imports
stanwolverine Jun 8, 2023
ef02383
removed todos
stanwolverine Jun 8, 2023
47c922c
added key prop while creating HMSView
ygit Jun 8, 2023
8332e43
Merge branch 'issue-878-hls-player' into release1.7.0-rc
ygit Jun 8, 2023
b42b89e
Merge branch 'release1.7.0-rc' into feature/1029-add-key-as-videotrackid
ygit Jun 8, 2023
bdb3d4f
changed signature of `useHMSHLSPlayerStats` hook
stanwolverine Jun 8, 2023
221dc8f
Merge branch 'issue-878-hls-player' into release1.7.0-rc
ygit Jun 8, 2023
4f3d770
Merge branch 'release1.7.0-rc' into feature/1029-add-key-as-videotrackid
ygit Jun 8, 2023
5909b55
corrected android build error
ygit Jun 9, 2023
1ec8bd5
released sample app version 2.1.78 (214) ⚛️
ygit Jun 9, 2023
53df282
released sample app version 2.1.79 (215) ⚛️
ygit Jun 9, 2023
e76158c
feat(sdk): :sparkles: exposed native HLS player methods to JS side
stanwolverine Jun 12, 2023
776a504
feat(example-app): :sparkles: added custom HLS player controls
stanwolverine Jun 12, 2023
43fa31a
Removed reanimated package (#1073)
ygit Jun 13, 2023
5906047
Merge branch 'issue-878-hls-player' into release1.7.0-rc
ygit Jun 13, 2023
fcc37bd
Merge branch 'feature/1029-add-key-as-videotrackid' into release1.7.0-rc
ygit Jun 13, 2023
50441a0
released sample app version 2.1.80 (216) ⚛️
ygit Jun 13, 2023
9c3b7d1
build(deps): bump activesupport in /sample-apps/rn-quickstart-app (#1…
dependabot[bot] Jun 14, 2023
b0186c8
updated gems
ygit Jun 14, 2023
b921276
Merge branch 'develop' into release1.7.0-rc
ygit Jun 14, 2023
884089f
updated android Compile & Target SDK versions to 31
ygit Jun 14, 2023
f9a20d7
released sample app version 2.1.81 (217) ⚛️
ygit Jun 14, 2023
a1810cd
updated example app changelog
ygit Jun 14, 2023
92eed27
bumped iOS app version
ygit Jun 14, 2023
062855d
Added HMS HLS player (#1065)
stanwolverine Jun 15, 2023
8732081
updated constraint layout version
ygit Jun 15, 2023
cf30871
Feature/1068: Enabled S/W Echo cancellation (#1069)
ygit Jun 15, 2023
a119c68
Feature/1029 add key as videotrackid (#1072)
ygit Jun 15, 2023
6e427bb
Merge branch 'develop' into release1.7.0-rc
ygit Jun 15, 2023
c61bd38
Merge pull request #1071 from 100mslive/release1.7.0-rc
ygit Jun 15, 2023
d94e8ee
released sample app version 2.1.82 (218) ⚛️
ygit Jun 15, 2023
dc94252
refactor(sdk): removed platform specific hls stats from sdk
stanwolverine Jun 20, 2023
48862ba
refactor(example-app): removed usage of removed hls stats properties
stanwolverine Jun 20, 2023
001a1a7
refactor(sdk): hls player controls are hidden by default
stanwolverine Jun 20, 2023
1011fd4
released sample app version 2.1.83 (219) ⚛️
ygit Jun 20, 2023
3ea56f7
updated trunk linter version
ygit Jun 20, 2023
08772c5
updated trunk linter
ygit Jun 21, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 5 additions & 5 deletions .trunk/trunk.yaml
@@ -1,23 +1,23 @@
version: 0.1
cli:
version: 1.9.1
version: 1.11.0
plugins:
sources:
- id: trunk
ref: v0.0.17
ref: v0.0.18
uri: https://github.com/trunk-io/plugins
lint:
enabled:
- oxipng@8.0.0
- yamllint@1.31.0
- yamllint@1.32.0
- ktlint@0.49.1
- svgo@3.0.2
- prettier@2.8.8
- shfmt@3.5.0
- gitleaks@8.16.3
- gitleaks@8.17.0
- shellcheck@0.9.0
- git-diff-check
- markdownlint@0.34.0
- markdownlint@0.35.0
- buildifier@6.1.2
runtimes:
enabled:
Expand Down
24 changes: 16 additions & 8 deletions android/build.gradle
Expand Up @@ -3,7 +3,9 @@ import groovy.json.JsonSlurper
def sdkVersions = new JsonSlurper().parse file("../sdk-versions.json")

buildscript {
ext.kotlin_version = '1.5.30-RC'
ext.kotlin_version = "1.6.0"
ext.hms_coroutines_version = "1.6.0"
ext.ktx_version = "1.6.0"
if (project == rootProject) {
repositories {
google()
Expand Down Expand Up @@ -31,10 +33,10 @@ def safeExtGet(prop, fallback) {
}

android {
compileSdkVersion safeExtGet('Hmssdk_compileSdkVersion', 30)
compileSdkVersion safeExtGet('Hmssdk_compileSdkVersion', 31)
defaultConfig {
minSdkVersion safeExtGet('Hmssdk_minSdkVersion', 21)
targetSdkVersion safeExtGet('Hmssdk_targetSdkVersion', 30)
targetSdkVersion safeExtGet('Hmssdk_targetSdkVersion', 31)
versionCode 1
versionName "1.0"
}
Expand Down Expand Up @@ -68,10 +70,16 @@ repositories {
dependencies {
//noinspection GradleDynamicVersion
implementation "com.facebook.react:react-native:+"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" // From node_modules
implementation "com.google.code.gson:gson:2.9.0"
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation "androidx.core:core-ktx:$ktx_version"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$hms_coroutines_version"
implementation "androidx.constraintlayout:constraintlayout:2.1.3"
implementation "androidx.appcompat:appcompat:1.3.1"

// 100ms
implementation "live.100ms:android-sdk:${sdkVersions["android"]}"
implementation "live.100ms:video-view:${sdkVersions["android"]}"
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
implementation 'androidx.appcompat:appcompat:1.3.1'
}
implementation "live.100ms:hls-player:${sdkVersions["android"]}"
implementation "live.100ms:hls-player-stats:${sdkVersions["android"]}"
}
29 changes: 14 additions & 15 deletions android/src/main/java/com/reactnativehmssdk/HMSDecoder.kt
Expand Up @@ -130,23 +130,22 @@ object HMSDecoder {
if (hmsPeer != null) {
peer.putString(peerUpdateType.ordinal.toString(), hmsPeer.peerID)

if (peerUpdateType !== null) {
when (peerUpdateType) {
HMSPeerUpdate.NAME_CHANGED -> {
peer.putString("name", hmsPeer.name)
}
HMSPeerUpdate.METADATA_CHANGED -> {
peer.putString("metadata", hmsPeer.metadata)
}
HMSPeerUpdate.ROLE_CHANGED -> {
peer.putMap("role", this.getHmsRole(hmsPeer.hmsRole))
}
HMSPeerUpdate.NETWORK_QUALITY_UPDATED -> {
hmsPeer.networkQuality?.let {
peer.putMap("networkQuality", this.getHmsNetworkQuality(it))
}
when (peerUpdateType) {
HMSPeerUpdate.NAME_CHANGED -> {
peer.putString("name", hmsPeer.name)
}
HMSPeerUpdate.METADATA_CHANGED -> {
peer.putString("metadata", hmsPeer.metadata)
}
HMSPeerUpdate.ROLE_CHANGED -> {
peer.putMap("role", this.getHmsRole(hmsPeer.hmsRole))
}
HMSPeerUpdate.NETWORK_QUALITY_UPDATED -> {
hmsPeer.networkQuality?.let {
peer.putMap("networkQuality", this.getHmsNetworkQuality(it))
}
}
else -> {}
}
}
return peer
Expand Down
248 changes: 248 additions & 0 deletions android/src/main/java/com/reactnativehmssdk/HMSHLSPlayer.kt
@@ -0,0 +1,248 @@
package com.reactnativehmssdk

import android.annotation.SuppressLint
import android.content.Context
import android.view.LayoutInflater
import android.widget.FrameLayout
import androidx.media3.ui.PlayerView
import com.facebook.react.bridge.Arguments
import com.facebook.react.bridge.ReactContext
import com.facebook.react.bridge.WritableMap
import com.facebook.react.uimanager.events.RCTEventEmitter
import live.hms.hls_player.*
import live.hms.stats.PlayerStatsListener
import live.hms.stats.model.PlayerStatsModel
import live.hms.video.error.HMSException
import live.hms.video.sdk.HMSSDK
import java.util.concurrent.TimeUnit

@SuppressLint("ViewConstructor")
class HMSHLSPlayer(context: ReactContext) : FrameLayout(context) {
private var playerView: PlayerView? = null // Exoplayer View
private var hmsHlsPlayer: HmsHlsPlayer? = null // 100ms HLS Player
private var hmssdkInstance: HMSSDK? = null
private var statsMonitorAttached = false
private val hmsHlsPlaybackEventsObject = object : HmsHlsPlaybackEvents {
override fun onCue(cue: HmsHlsCue) {
super.onCue(cue)

val data = Arguments.createMap()
cue.endDate?.let { data.putString("endDate", it.time.toString()) }
cue.id?.let { data.putString("id", it) }
cue.payloadval?.let { data.putString("payloadval", it) }
data.putString("startDate", cue.startDate.time.toString())

sendHLSPlaybackEventToJS(HMSHLSPlayerConstants.ON_PLAYBACK_CUE_EVENT, data)
}

override fun onPlaybackFailure(error: HmsHlsException) {
super.onPlaybackFailure(error)

val data = Arguments.createMap()

// error
val errorData = Arguments.createMap()
errorData.putInt("errorCode", error.error.errorCode)
errorData.putString("errorCodeName", error.error.errorCodeName)
error.error.message?.let {
errorData.putString("message", it)
}

data.putMap("error", errorData)

sendHLSPlaybackEventToJS(HMSHLSPlayerConstants.ON_PLAYBACK_FAILURE_EVENT, data)
}

override fun onPlaybackStateChanged(state: HmsHlsPlaybackState) {
super.onPlaybackStateChanged(state)

val data = Arguments.createMap()
data.putString("state", state.name)
sendHLSPlaybackEventToJS(HMSHLSPlayerConstants.ON_PLAYBACK_STATE_CHANGE_EVENT, data)
}
}
private val hmsHlsPlayerStatsListenerObject = object : PlayerStatsListener {
override fun onError(error: HMSException) {
val data = Arguments.createMap()

data.putString("action", error.action)
data.putInt("code", error.code)
data.putString("description", error.description)
data.putBoolean("isTerminal", error.isTerminal)
data.putString("message", error.message)
data.putString("name", error.name)

sendHLSStatsEventToJS(HMSHLSPlayerConstants.ON_STATS_EVENT_ERROR, data)
}

override fun onEventUpdate(playerStatsModel: PlayerStatsModel) {
val data = Arguments.createMap()

// bandwidth
data.putInt("bandWidthEstimate", playerStatsModel.bandwidth.bandWidthEstimate.toInt())
data.putInt("totalBytesLoaded", playerStatsModel.bandwidth.totalBytesLoaded.toInt())

// bufferedDuration
data.putInt("bufferedDuration", playerStatsModel.bufferedDuration.toInt())

// distanceFromLive
data.putInt("distanceFromLive", playerStatsModel.distanceFromLive.toInt())

// frameInfo
data.putInt("droppedFrameCount", playerStatsModel.frameInfo.droppedFrameCount)

// videoInfo
data.putInt("averageBitrate", playerStatsModel.videoInfo.averageBitrate)
data.putInt("videoHeight", playerStatsModel.videoInfo.videoHeight)
data.putInt("videoWidth", playerStatsModel.videoInfo.videoWidth)

sendHLSStatsEventToJS(HMSHLSPlayerConstants.ON_STATS_EVENT_UPDATE, data)
}
}

init {
val inflater = getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater

// Inflating player_view xml
val view = inflater.inflate(R.layout.player_view, this)

// getting Exoplayer View from above xml
val localPlayerView = view.findViewById<PlayerView>(R.id.hls_view)
playerView = localPlayerView

val hmssdkCollection = context.getNativeModule(HMSManager::class.java)?.getHmsInstance()
hmssdkInstance = hmssdkCollection?.get("12345")?.hmsSDK

// creating 100ms HLS Player
val localHmsHlsPlayer = HmsHlsPlayer(context, hmssdkInstance)
hmsHlsPlayer = localHmsHlsPlayer

// Attaching HLS Player Playback State Events listener
localHmsHlsPlayer.addPlayerEventListener(hmsHlsPlaybackEventsObject)

// setting 100ms HLS Player on Exoplayer
localPlayerView.player = localHmsHlsPlayer.getNativePlayer()
}

fun cleanup() {
hmsHlsPlayer?.stop()
hmsHlsPlayer?.addPlayerEventListener(null)
hmsHlsPlayer?.setStatsMonitor(null)
}

fun play(url: String?) {
if (url !== null && url.isNotEmpty()) {
hmsHlsPlayer?.play(url)
return
}

val hlsStreamingState = this.hmssdkInstance?.getRoom()?.hlsStreamingState

val defaultURL: String? = hlsStreamingState?.let {
if (it.running) {
it.variants?.get(0)?.hlsStreamUrl
} else {
null
}
}

if (defaultURL !== null) {
hmsHlsPlayer?.play(defaultURL)
}
}

fun stop() {
hmsHlsPlayer?.stop()
}

fun pause() {
hmsHlsPlayer?.pause()
}

fun resume() {
hmsHlsPlayer?.resume()
}

fun seekForward(seconds: Double) {
hmsHlsPlayer?.seekForward(seconds.toLong(), TimeUnit.SECONDS)
}

fun seekBackward(seconds: Double) {
hmsHlsPlayer?.seekBackward(seconds.toLong(), TimeUnit.SECONDS)
}

fun seekToLivePosition() {
hmsHlsPlayer?.seekToLivePosition()
}

fun setVolume(level: Int) {
hmsHlsPlayer?.volume = level
}

fun enableStats(enable: Boolean) {
if (enable) {
attachStatsMonitor()
} else {
removeStatsMonitor()
}
}

fun enableControls(show: Boolean) {
playerView?.let {
if (show) {
it.useController = true
it.showController()
} else {
it.hideController()
it.useController = false
}
}
}

private fun attachStatsMonitor() {
if (statsMonitorAttached) return

hmsHlsPlayer?.let {
it.setStatsMonitor(hmsHlsPlayerStatsListenerObject)
statsMonitorAttached = true
}
}

private fun removeStatsMonitor() {
if (!statsMonitorAttached) return

hmsHlsPlayer?.setStatsMonitor(null)
statsMonitorAttached = false
}

private fun sendHLSPlaybackEventToJS(eventName: String, data: WritableMap) {
val event: WritableMap = Arguments.createMap()
event.putString("event", eventName)
event.putMap("data", data)

val reactContext = context as ReactContext
reactContext.getJSModule(RCTEventEmitter::class.java).receiveEvent(id, HMSHLSPlayerConstants.HMS_HLS_PLAYBACK_EVENT, event)
}

private fun sendHLSStatsEventToJS(eventName: String, data: WritableMap) {
val event: WritableMap = Arguments.createMap()
event.putString("event", eventName)
event.putMap("data", data)

val reactContext = context as ReactContext
reactContext.getJSModule(RCTEventEmitter::class.java).receiveEvent(id, HMSHLSPlayerConstants.HMS_HLS_STATS_EVENT, event)
}
}

object HMSHLSPlayerConstants {
// HLS Playback Events
const val HMS_HLS_PLAYBACK_EVENT = "hmsHlsPlaybackEvent"
const val ON_PLAYBACK_CUE_EVENT = "ON_PLAYBACK_CUE_EVENT"
const val ON_PLAYBACK_FAILURE_EVENT = "ON_PLAYBACK_FAILURE_EVENT"
const val ON_PLAYBACK_STATE_CHANGE_EVENT = "ON_PLAYBACK_STATE_CHANGE_EVENT"

// HLS Playback Stats Events
const val HMS_HLS_STATS_EVENT = "hmsHlsStatsEvent"
const val ON_STATS_EVENT_UPDATE = "ON_STATS_EVENT_UPDATE"
const val ON_STATS_EVENT_ERROR = "ON_STATS_EVENT_ERROR"
}