Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/big-symbols-hear.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@theoplayer/react-native-analytics-agama': patch
---

Fixed an issue where the measuring network interceptor would cause ABR to break and make the player stall during play-out.
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,11 @@ class ReactTHEOplayerAgamaModule(private val reactContext: ReactApplicationConte
view?.player?.let { player ->
interceptor = object : AgamaInterceptor() {
override suspend fun onResponse(response: InterceptableHTTPResponse) {
if (response.request.type == RequestType.SEGMENT) {
onSegmentResponse(response)
} else if (response.request.type == RequestType.MANIFEST) {
onManifestResponse(response)
when (response.request.type) {
RequestType.SEGMENT -> onSegmentResponse(response)
RequestType.MANIFEST -> onManifestResponse(response)
else -> { /*ignore*/
}
}
}
}.also {
Expand Down Expand Up @@ -85,25 +86,26 @@ class ReactTHEOplayerAgamaModule(private val reactContext: ReactApplicationConte
}

fun onSegmentResponse(response: InterceptableHTTPResponse) {
response.onBody { body ->
val mediaType = mediaTypeToString(response.request.mediaType)
val contentLength = body.size.toDouble()
if (debug) {
Log.d(
TAG, "onSegmentResponse - " +
"url(${response.url}) " +
"mediaType($mediaType) " +
"status(${response.status}) " +
"bytes(${contentLength.toLong()}) "
)
}
sendEvent(reactContext, EVENT_SEGMENT_RESPONSE, Arguments.createMap().apply {
putInt(PROP_STATUS, response.status)
putString(PROP_MEDIA_TYPE, mediaType)
putDouble(PROP_TOTAL_BYTES_LOADED, contentLength)
})
body
val mediaType = mediaTypeToString(response.request.mediaType)
val contentLength = response.headers.entries.firstOrNull {
it.key.equals("Content-Length", ignoreCase = true)
}?.value?.toDoubleOrNull() ?: 0.0

if (debug) {
Log.d(
TAG, "onSegmentResponse - " +
"url(${response.url}) " +
"mediaType($mediaType) " +
"status(${response.status}) " +
"bytes(${contentLength.toLong()}) "
)
}
sendEvent(reactContext, EVENT_SEGMENT_RESPONSE, Arguments.createMap().apply {
putInt(PROP_STATUS, response.status)
putString(PROP_MEDIA_TYPE, mediaType)
putDouble(PROP_TOTAL_BYTES_LOADED, contentLength)
})

}

private fun mediaTypeToString(mediaType: RequestMediaType): String {
Expand Down
Loading