Skip to content

Commit

Permalink
Merge pull request #16 from kinescope/feature/analytics-custom-url
Browse files Browse the repository at this point in the history
Analytics custom url
  • Loading branch information
pavel-vorobyev authored Apr 9, 2024
2 parents 547784b + 900fd75 commit 7389e97
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 25 deletions.
Binary file modified kotlin-kinescope-player-release.aar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import io.kinescope.sdk.logger.KinescopeLogger
import io.kinescope.sdk.logger.KinescopeLoggerLevel
import io.kinescope.sdk.network.AnalyticsBuilder
import io.kinescope.sdk.utils.currentTimestamp
import io.kinescope.sdk.utils.kinescopeAnalyticsApiEndpoint
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response
Expand All @@ -32,6 +33,9 @@ class KinescopeAnalytics(
private val playerId = analyticsPlayerIdStorage.getPlayerId()
private val viewId = UUID.randomUUID().toString()

var metricUrl: String? = null
get() = field.takeIf { !it.isNullOrEmpty() } ?: kinescopeAnalyticsApiEndpoint

fun sendEvent(
event: Event,
value: Float = 0f,
Expand Down Expand Up @@ -89,7 +93,7 @@ class KinescopeAnalytics(
message = "Analytics event. ${body.toStringData()}"
)

analyticsApi.sendEvent(body = body)
analyticsApi.sendEvent(url = metricUrl as String, body = body)
.enqueue(object : Callback<Void> {
override fun onResponse(call: Call<Void>, response: Response<Void>) =
KinescopeLogger.log(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,10 @@ class KinescopeAnalyticsManager(
args = args,
)

fun sourceChanged(newSource: String) {
source = newSource
fun setSource(source: String, metricUrl: String?) {
this.source = source
analytics.metricUrl = metricUrl

eventPlaybackLastSentSecondsAgo = 0
eventViewLastSentSecondsAgo = 0
eventViewSent = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import io.kinescope.sdk.analytics.proto.Native
import retrofit2.Call
import retrofit2.http.Body
import retrofit2.http.POST
import retrofit2.http.Url

interface KinescopeAnalyticsApi {
@POST("/player-native")
fun sendEvent(@Body body: Native): Call<Void>
@POST
fun sendEvent(@Url url: String, @Body body: Native): Call<Void>
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
package io.kinescope.sdk.api

import io.kinescope.sdk.models.videos.KinescopeVideo
import io.kinescope.sdk.utils.SDK_TYPE
import retrofit2.Call
import retrofit2.http.GET
import retrofit2.http.Path
import retrofit2.http.Query

interface KinescopeFetch {
@GET("{video_id}.json")
fun getVideo(@Path("video_id") videoId:String): Call<KinescopeVideo>
fun getVideo(
@Path("video_id") videoId: String,
@Query("sdk") sdk: String = SDK_TYPE
): Call<KinescopeVideo>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package io.kinescope.sdk.models.videos

import com.squareup.moshi.Json
import com.squareup.moshi.JsonClass

@JsonClass(generateAdapter = true)
data class KinescopeSdk(
@Json(name = "metric_url") val metricUrl: String?
)
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,25 @@ import com.squareup.moshi.JsonClass
import java.io.Serializable

@JsonClass(generateAdapter = true)
data class KinescopeVideo (
@Json(name = "id") val id:String,
@Json(name = "workspace_id") val workspaceId:String,
@Json(name = "project_id") val projectId:String,
@Json(name = "folder_id") val folderId:String?,
@Json(name = "type") val type:String,
@Json(name = "title") val title: String,
@Json(name = "subtitle") val subtitle: String?,
data class KinescopeVideo(
@Json(name = "id") val id: String,
@Json(name = "workspace_id") val workspaceId: String,
@Json(name = "project_id") val projectId: String,
@Json(name = "folder_id") val folderId: String?,
@Json(name = "type") val type: String,
@Json(name = "title") val title: String,
@Json(name = "subtitle") val subtitle: String?,
@Json(name = "description") val description: String,
@Json(name = "chapters") val chapters: KinescopeVideoChapter,
@Json(name = "poster") val poster: KinescopeVideoPoster?,
@Json(name = "attachments") val attachments: List<KinescopeVideoAttachments>,
@Json(name = "subtitles") val subtitles: List<KinescopeVideoSubtitle>,
@Json(name = "duration") val duration: Float,
@Json(name = "live") val live: KinescopeVideoLive?,
@Json(name = "hls_link") val hlsLink:String?,
@Json(name = "dash_link") val dashLink:String?,
): Serializable {
@Json(name = "hls_link") val hlsLink: String?,
@Json(name = "dash_link") val dashLink: String?,
@Json(name = "sdk") val sdk: KinescopeSdk?,
) : Serializable {

val isLive: Boolean
get() = type == TYPE_LIVE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class KinescopeVideoPlayer(
constructor(context: Context) : this(context, KinescopePlayerOptions())

var exoPlayer: ExoPlayer? = null
var onSourceChanged: ((source: String) -> Unit)? = null
var onSourceChanged: ((source: String, metricUrl: String?) -> Unit)? = null

private val USER_AGENT = "KinescopeAndroidVideoKotlin"
private var currentKinescopeVideo: KinescopeVideo? = null
Expand Down Expand Up @@ -116,7 +116,10 @@ class KinescopeVideoPlayer(
}

currentKinescopeVideo = kinescopeVideo
onSourceChanged?.invoke(source)
onSourceChanged?.invoke(
source,
kinescopeVideo.sdk?.metricUrl
)

exoPlayer?.setMediaSource(mediaSource)
exoPlayer?.playWhenReady = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package io.kinescope.sdk.utils

import android.app.Application

const val kinescopeReferer: String = "https://kinescope.io/"
const val kinescopeFetchEndpoint: String = "https://kinescope.io/"
const val kinescopeApiEndpoint: String = "https://api.kinescope.io/"
const val kinescopeReferer = "https://kinescope.io/"
const val kinescopeFetchEndpoint = "https://kinescope.io/"
const val kinescopeApiEndpoint = "https://api.kinescope.io/"
const val kinescopeAnalyticsApiEndpoint = "https://metrics.kinescope.io/"
const val tokenType: String = "Bearer"
const val tokenType = "Bearer"
const val SDK_TYPE = "android"
Original file line number Diff line number Diff line change
Expand Up @@ -406,8 +406,11 @@ class KinescopePlayerView(
}

kinescopePlayer?.exoPlayer?.addListener(componentListener)
kinescopePlayer?.onSourceChanged = { source ->
analyticsManager.sourceChanged(newSource = source)
kinescopePlayer?.onSourceChanged = { source, metricUrl ->
analyticsManager.setSource(
source = source,
metricUrl = metricUrl,
)
}
exoPlayerView?.player = kinescopePlayer?.exoPlayer
applyKinescopePlayerOptions()
Expand Down

0 comments on commit 7389e97

Please sign in to comment.