Skip to content

Commit

Permalink
[PBE-6015] Add extra info to request client header (#1178)
Browse files Browse the repository at this point in the history
* Add app name

* Do not add header when creating socket (duplicated)

* Use package name when app name is not provided
  • Loading branch information
liviu-timar authored Sep 16, 2024
1 parent fa44c8d commit 0cac26c
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ object StreamVideoInitHelper {
)
authData.token
},
appName = "Stream Video Demo App",
).build()
}
}
3 changes: 2 additions & 1 deletion stream-video-android-core/api/stream-video-android-core.api
Original file line number Diff line number Diff line change
Expand Up @@ -823,7 +823,8 @@ public final class io/getstream/video/android/core/StreamVideoBuilder {
public fun <init> (Landroid/content/Context;Ljava/lang/String;Lio/getstream/video/android/core/GEO;Lio/getstream/video/android/model/User;Ljava/lang/String;Lkotlin/jvm/functions/Function2;Lio/getstream/video/android/core/logging/LoggingLevel;Lio/getstream/video/android/core/notifications/NotificationConfig;Lkotlin/jvm/functions/Function1;JZLjava/lang/String;ZLio/getstream/video/android/core/notifications/internal/service/CallServiceConfig;Ljava/lang/String;Lio/getstream/video/android/core/sounds/Sounds;Z)V
public fun <init> (Landroid/content/Context;Ljava/lang/String;Lio/getstream/video/android/core/GEO;Lio/getstream/video/android/model/User;Ljava/lang/String;Lkotlin/jvm/functions/Function2;Lio/getstream/video/android/core/logging/LoggingLevel;Lio/getstream/video/android/core/notifications/NotificationConfig;Lkotlin/jvm/functions/Function1;JZLjava/lang/String;ZLio/getstream/video/android/core/notifications/internal/service/CallServiceConfig;Ljava/lang/String;Lio/getstream/video/android/core/sounds/Sounds;ZLio/getstream/video/android/core/permission/android/StreamPermissionCheck;)V
public fun <init> (Landroid/content/Context;Ljava/lang/String;Lio/getstream/video/android/core/GEO;Lio/getstream/video/android/model/User;Ljava/lang/String;Lkotlin/jvm/functions/Function2;Lio/getstream/video/android/core/logging/LoggingLevel;Lio/getstream/video/android/core/notifications/NotificationConfig;Lkotlin/jvm/functions/Function1;JZLjava/lang/String;ZLio/getstream/video/android/core/notifications/internal/service/CallServiceConfig;Ljava/lang/String;Lio/getstream/video/android/core/sounds/Sounds;ZLio/getstream/video/android/core/permission/android/StreamPermissionCheck;I)V
public synthetic fun <init> (Landroid/content/Context;Ljava/lang/String;Lio/getstream/video/android/core/GEO;Lio/getstream/video/android/model/User;Ljava/lang/String;Lkotlin/jvm/functions/Function2;Lio/getstream/video/android/core/logging/LoggingLevel;Lio/getstream/video/android/core/notifications/NotificationConfig;Lkotlin/jvm/functions/Function1;JZLjava/lang/String;ZLio/getstream/video/android/core/notifications/internal/service/CallServiceConfig;Ljava/lang/String;Lio/getstream/video/android/core/sounds/Sounds;ZLio/getstream/video/android/core/permission/android/StreamPermissionCheck;IILkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun <init> (Landroid/content/Context;Ljava/lang/String;Lio/getstream/video/android/core/GEO;Lio/getstream/video/android/model/User;Ljava/lang/String;Lkotlin/jvm/functions/Function2;Lio/getstream/video/android/core/logging/LoggingLevel;Lio/getstream/video/android/core/notifications/NotificationConfig;Lkotlin/jvm/functions/Function1;JZLjava/lang/String;ZLio/getstream/video/android/core/notifications/internal/service/CallServiceConfig;Ljava/lang/String;Lio/getstream/video/android/core/sounds/Sounds;ZLio/getstream/video/android/core/permission/android/StreamPermissionCheck;ILjava/lang/String;)V
public synthetic fun <init> (Landroid/content/Context;Ljava/lang/String;Lio/getstream/video/android/core/GEO;Lio/getstream/video/android/model/User;Ljava/lang/String;Lkotlin/jvm/functions/Function2;Lio/getstream/video/android/core/logging/LoggingLevel;Lio/getstream/video/android/core/notifications/NotificationConfig;Lkotlin/jvm/functions/Function1;JZLjava/lang/String;ZLio/getstream/video/android/core/notifications/internal/service/CallServiceConfig;Ljava/lang/String;Lio/getstream/video/android/core/sounds/Sounds;ZLio/getstream/video/android/core/permission/android/StreamPermissionCheck;ILjava/lang/String;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public final fun build ()Lio/getstream/video/android/core/StreamVideo;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,26 +203,26 @@ public interface StreamVideo : NotificationHandler {
}

/**
* Builds a detailed header of information we track around the SDK, Android OS, API Level, device name and
* vendor and more.
* Builds the client information header (X-Stream-Client) that will be added to requests.
*
* @return String formatted header that contains all the information.
* @return Header value as a string.
*/
internal fun buildSdkTrackingHeaders(): String {
val clientInformation = "stream-video-android-${BuildConfig.STREAM_VIDEO_VERSION}"

val buildModel = Build.MODEL
val deviceManufacturer = Build.MANUFACTURER
val apiLevel = Build.VERSION.SDK_INT
val osName = "Android ${Build.VERSION.RELEASE}"

return clientInformation +
"|os=$osName" +
"|api_version=$apiLevel" +
"|device_vendor=$deviceManufacturer" +
"|device_model=$buildModel"
val streamVideoVersion = "stream-video-android-${BuildConfig.STREAM_VIDEO_VERSION}"
val os = "|os=Android ${Build.VERSION.RELEASE}"
val apiVersion = "|api_version=${Build.VERSION.SDK_INT}"
val deviceVendor = "|device_vendor=${Build.MANUFACTURER}"
val deviceModel = "|device_model=${Build.MODEL}"
val appName = buildAppName()

return streamVideoVersion + os + apiVersion + deviceVendor + deviceModel + appName
}

private fun buildAppName(): String =
(internalStreamVideo as? StreamVideoImpl)?.let { streamVideoImpl ->
"|app_name=" + (streamVideoImpl.appName ?: streamVideoImpl.context.packageName)
} ?: ""

/**
* Uninstall a previous [StreamVideo] instance.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ import java.net.ConnectException
* @property permissionCheck Used to check for system permission based on call capabilities. See [StreamPermissionCheck].
* @property crashOnMissingPermission Throw an exception or just log an error if [permissionCheck] fails.
* @property audioUsage Used to signal to the system how to treat the audio tracks (voip or media).
* @property appName Optional name for the application that is using the Stream Video SDK. Used for logging and debugging purposes.
*
* @see build
* @see ClientState.connection
Expand All @@ -102,6 +103,7 @@ public class StreamVideoBuilder @JvmOverloads constructor(
private val crashOnMissingPermission: Boolean = false,
private val permissionCheck: StreamPermissionCheck = DefaultStreamPermissionCheck(),
private val audioUsage: Int = defaultAudioUsage,
private val appName: String? = null,
) {
private val context: Context = context.applicationContext
private val scope = CoroutineScope(DispatcherProvider.IO)
Expand Down Expand Up @@ -199,6 +201,7 @@ public class StreamVideoBuilder @JvmOverloads constructor(
permissionCheck = permissionCheck,
crashOnMissingPermission = crashOnMissingPermission,
audioUsage = audioUsage,
appName = appName,
)

if (user.type == UserType.Guest) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ internal class StreamVideoImpl internal constructor(
internal val permissionCheck: StreamPermissionCheck = DefaultStreamPermissionCheck(),
internal val crashOnMissingPermission: Boolean = false,
internal val audioUsage: Int = defaultAudioUsage,
internal val appName: String? = null,
) : StreamVideo, NotificationHandler by streamNotificationManager {

private var locationJob: Deferred<Result<String>>? = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package io.getstream.video.android.core.socket

import io.getstream.log.taggedLogger
import io.getstream.video.android.core.StreamVideo
import io.getstream.video.android.core.dispatchers.DispatcherProvider
import io.getstream.video.android.core.errors.VideoErrorCode
import io.getstream.video.android.core.internal.network.NetworkStateProvider
Expand Down Expand Up @@ -277,7 +276,6 @@ public open class PersistentSocket<T>(
.url(url)
.addHeader("Connection", "Upgrade")
.addHeader("Upgrade", "websocket")
.addHeader("X-Stream-Client", StreamVideo.buildSdkTrackingHeaders())
.build()

return httpClient.newWebSocket(request, this)
Expand Down

0 comments on commit 0cac26c

Please sign in to comment.