Skip to content

Commit

Permalink
Deps update
Browse files Browse the repository at this point in the history
  • Loading branch information
dkrivoruchko committed Oct 20, 2024
1 parent 4e3b327 commit 70fd680
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 44 deletions.
3 changes: 2 additions & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ android {
namespace = "info.dvkr.screenstream"
compileSdk = rootProject.extra["compileSdkVersion"] as Int
buildToolsVersion = rootProject.extra["buildToolsVersion"] as String
ndkVersion = "27.1.12297006"
ndkVersion = "27.2.12479018"

defaultConfig {
applicationId = "info.dvkr.screenstream"
Expand Down Expand Up @@ -105,6 +105,7 @@ dependencies {
coreLibraryDesugaring(libs.android.tools.desugar)

ksp(libs.koin.ksp)
// implementation(libs.koin.startup)

implementation(projects.common)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package info.dvkr.screenstream

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.result.contract.ActivityResultContracts
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.app.AppCompatDelegate
import androidx.core.content.edit
import androidx.lifecycle.lifecycleScope
Expand All @@ -23,7 +23,7 @@ import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import org.koin.android.ext.android.inject

public abstract class AppUpdateActivity : AppCompatActivity() {
public abstract class AppUpdateActivity : ComponentActivity() {

private companion object {
private const val APP_UPDATE_REQUEST_TIMEOUT = 8 * 60 * 60 * 1000L // 8 hours. Don't need exact time frame
Expand Down
2 changes: 2 additions & 0 deletions common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ android {
}

dependencies {
api(libs.kotlinStdlibJdk8)
api(libs.kotlinReflect)
api(libs.kotlinx.coroutines.android)

api(libs.androidx.core.ktx)
Expand Down
31 changes: 17 additions & 14 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
[versions]
agp = "8.6.1"
kotlin = "2.0.20"
ksp = "2.0.20-1.0.25"
agp = "8.7.1"
kotlin = "2.0.21"
ksp = "2.0.21-1.0.25"
android-tools-r8 = "8.5.35"
android-tools-desugar = "2.1.2"

koin-android-compose = "3.5.6"
koin-android = "4.0.0"
koin-ksp = "1.3.1"

kotlinx-coroutines = "1.9.0"

androidx-core-ktx = "1.13.1"
androidx-core-splashscreen = "1.2.0-alpha02"
androidx-activity-compose = "1.9.2"
androidx-fragment = "1.8.3"
androidx-activity-compose = "1.9.3"
androidx-fragment = "1.8.4"
androidx-appcompat = "1.7.0"
androidx-lifecycle = "2.8.6"
androidx-window = "1.3.0"
androidx-datastore-preferences = "1.1.1"

compose-bom = "2024.09.02"
compose-bom = "2024.10.00"

process-phoenix = "3.0.0"
xlog = "1.11.1"

#MJPEG
ktor = "2.3.12"
ktor = "3.0.0"

#PlayStore-WebRTC
play-services-tasks = "18.2.0"
Expand All @@ -36,19 +36,22 @@ okhttp = "4.12.0"

#PlayStore-App
play-app-update = "2.1.0"
play-app-review = "2.0.1"
play-services-ads = "23.3.0"
webkit = "1.12.0"
firebase-analytics = "22.1.0"
firebase-crashlytics = "19.1.0"
play-app-review = "2.0.2"
play-services-ads = "23.4.0"
webkit = "1.12.1"
firebase-analytics = "22.1.2"
firebase-crashlytics = "19.2.0"
google-services = "4.4.2"
crashlytics-gradle = "3.0.2"

[libraries]
android-tools-r8 = { module = "com.android.tools:r8", version.ref = "android-tools-r8" }
android-tools-desugar = { module = "com.android.tools:desugar_jdk_libs", version.ref = "android-tools-desugar" }
kotlinStdlibJdk8 = { module = "org.jetbrains.kotlin:kotlin-stdlib-jdk8", version.ref = "kotlin" }
kotlinReflect = { module = "org.jetbrains.kotlin:kotlin-reflect", version.ref = "kotlin" }

koin-android-compose = { module = "io.insert-koin:koin-androidx-compose", version.ref = "koin-android-compose" }
koin-android-compose = { module = "io.insert-koin:koin-androidx-compose", version.ref = "koin-android" }
koin-startup = { module = "io.insert-koin:koin-androidx-startup", version.ref = "koin-android" }
koin-annotations = { module = "io.insert-koin:koin-annotations", version.ref = "koin-ksp" }
koin-ksp = { module = "io.insert-koin:koin-ksp-compiler", version.ref = "koin-ksp" }

Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@ import io.ktor.http.content.OutgoingContent
import io.ktor.server.application.Application
import io.ktor.server.application.ApplicationStarted
import io.ktor.server.application.ApplicationStopped
import io.ktor.server.application.call
import io.ktor.server.application.install
import io.ktor.server.application.serverConfig
import io.ktor.server.cio.CIO
import io.ktor.server.cio.CIOApplicationEngine
import io.ktor.server.engine.applicationEngineEnvironment
import io.ktor.server.engine.EmbeddedServer
import io.ktor.server.engine.connector
import io.ktor.server.engine.embeddedServer
import io.ktor.server.plugins.cachingheaders.CachingHeaders
Expand All @@ -43,6 +42,7 @@ import io.ktor.server.routing.routing
import io.ktor.server.websocket.WebSockets
import io.ktor.server.websocket.webSocket
import io.ktor.utils.io.ByteWriteChannel
import io.ktor.utils.io.writeFully
import io.ktor.websocket.DefaultWebSocketSession
import io.ktor.websocket.Frame
import io.ktor.websocket.readText
Expand Down Expand Up @@ -83,6 +83,7 @@ import java.io.IOException
import java.net.BindException
import java.net.SocketException
import java.nio.charset.StandardCharsets
import java.util.concurrent.TimeUnit
import java.util.concurrent.atomic.AtomicLong
import java.util.concurrent.atomic.AtomicReference

Expand Down Expand Up @@ -110,7 +111,7 @@ internal class HttpServer(
private val indexHtml: AtomicReference<String> = AtomicReference("")
private val lastJPEG: AtomicReference<ByteArray> = AtomicReference(ByteArray(0))
private val serverData: HttpServerData = HttpServerData(sendEvent)
private val ktorServer: AtomicReference<Pair<CIOApplicationEngine, CompletableDeferred<Unit>>> = AtomicReference(null)
private val ktorServer: AtomicReference<Pair<EmbeddedServer<*, *>, CompletableDeferred<Unit>>> = AtomicReference(null)

init {
XLog.d(getLog("init"))
Expand Down Expand Up @@ -172,30 +173,36 @@ internal class HttpServer(
.shareIn(coroutineScope, SharingStarted.Eagerly, 1)

val serverPort = mjpegSettings.data.value.serverPort
val server = embeddedServer(CIO, applicationEngineEnvironment {
parentCoroutineContext = CoroutineExceptionHandler { _, throwable ->
XLog.e(this@HttpServer.getLog("parentCoroutineContext", "coroutineExceptionHandler: $throwable"), throwable)
}
module { appModule(mjpegSharedFlow) }
serverAddresses.forEach { netInterface ->
connector {
host = netInterface.address.hostAddress!!
port = serverPort
val server = embeddedServer(CIO,
rootConfig = serverConfig {
parentCoroutineContext = CoroutineExceptionHandler { _, throwable ->
if (throwable is BindException) return@CoroutineExceptionHandler
if (throwable is SocketException) return@CoroutineExceptionHandler
XLog.i(this@HttpServer.getLog("parentCoroutineContext", "coroutineExceptionHandler: $throwable"), throwable)
}
module { appModule(mjpegSharedFlow) }
},
configure = {
connectionIdleTimeoutSeconds = 10
reuseAddress = true
shutdownGracePeriod = 0
shutdownTimeout = 500
serverAddresses.forEach { netInterface ->
connector {
host = netInterface.address.hostAddress!!
port = serverPort
}
}
}
}) {
connectionIdleTimeoutSeconds = 10
shutdownGracePeriod = 0
shutdownTimeout = 500
}
)

ktorServer.set(server to CompletableDeferred())

server.environment.monitor.subscribe(ApplicationStarted) {
server.monitor.subscribe(ApplicationStarted) {
XLog.i(getLog("monitor", "KtorStarted: ${it.hashCode()}"))
}

server.environment.monitor.subscribe(ApplicationStopped) {
server.monitor.subscribe(ApplicationStopped) {
XLog.i(getLog("monitor", "KtorStopped: ${it.hashCode()}"))
coroutineScope.cancel()
serverData.clear()
Expand All @@ -219,7 +226,7 @@ internal class HttpServer(
XLog.e(getLog("startServer.Throwable"), cause)
sendEvent(MjpegStreamingService.InternalEvent.Error(MjpegError.HttpServerException))
}
XLog.d(getLog("startServer", "Done. Ktor: ${server.appHashCode()} "))
XLog.d(getLog("startServer", "Done. Ktor: ${server.hashCode()} "))
}

internal suspend fun stop(reloadClients: Boolean) = coroutineScope {
Expand All @@ -228,9 +235,9 @@ internal class HttpServer(
ktorServer.getAndSet(null)?.let { (server, stopJob) ->
if (stopJob.isActive) {
if (reloadClients) serverData.notifyClients("RELOAD", timeout = 250)
val hashCode = server.appHashCode()
val hashCode = server.hashCode()
XLog.i(this@HttpServer.getLog("stopServer", "Ktor: $hashCode"))
server.stop(250, 500)
server.stop(250, 500, TimeUnit.MILLISECONDS)
XLog.i(this@HttpServer.getLog("stopServer", "Done. Ktor: $hashCode"))
}
}
Expand All @@ -244,8 +251,6 @@ internal class HttpServer(
stop(false)
}

private fun CIOApplicationEngine.appHashCode(): Int = runCatching { application.hashCode() }.getOrDefault(0)

private suspend fun DefaultWebSocketSession.send(type: String, data: Any?) {
if (isActive) send(JSONObject().put("type", type).apply { if (data != null) put("data", data) }.toString())
}
Expand Down Expand Up @@ -394,6 +399,7 @@ internal class HttpServer(
channel.writeFully(jpeg, 0, jpeg.size)
channel.writeFully(crlf, 0, crlf.size)
channel.writeFully(jpegBoundary, 0, jpegBoundary.size)
channel.flush()
// Write MJPEG frame

val size = jpegBaseHeader.size + jpegSizeText.size + crlf.size * 3 + jpeg.size + jpegBoundary.size
Expand Down
2 changes: 1 addition & 1 deletion webrtc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ android {
namespace = "info.dvkr.screenstream.webrtc"
compileSdk = rootProject.extra["compileSdkVersion"] as Int
buildToolsVersion = rootProject.extra["buildToolsVersion"] as String
ndkVersion = "27.0.12077973"
ndkVersion = "27.2.12479018"

defaultConfig {
minSdk = rootProject.extra["minSdkVersion"] as Int
Expand Down

0 comments on commit 70fd680

Please sign in to comment.