-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
62 changed files
with
2,779 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
object AndroidConfig { | ||
const val minSdkVersion = 21 | ||
const val compileSdkVersion = 33 | ||
const val targetSdkVersion = 33 | ||
const val compileSdkVersion = 34 | ||
const val targetSdkVersion = 34 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,8 @@ kotlin { | |
browser() | ||
} | ||
|
||
jvm() | ||
|
||
sourceSets { | ||
getByName("commonTest") { | ||
dependencies { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import org.jetbrains.compose.desktop.application.dsl.TargetFormat | ||
|
||
plugins { | ||
kotlin("multiplatform") | ||
id("org.jetbrains.compose") | ||
} | ||
|
||
kotlin { | ||
jvm { | ||
compilations.all { | ||
kotlinOptions.jvmTarget = "17" | ||
} | ||
withJava() | ||
} | ||
sourceSets { | ||
val jvmMain by getting { | ||
dependencies { | ||
implementation(project(":sample:shared")) | ||
implementation(compose.material) | ||
implementation(compose.desktop.currentOs) | ||
implementation(deps.decompose.kmp) | ||
implementation(deps.kotlin.coroutines.swing) | ||
} | ||
} | ||
val jvmTest by getting | ||
} | ||
} | ||
|
||
compose.desktop { | ||
application { | ||
mainClass = "com.shepeliev.webrtckmp.MainKt" | ||
nativeDistributions { | ||
targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb) | ||
packageName = "KMPTemplate" | ||
packageVersion = "1.0.0" | ||
} | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
sample/app-jvm/src/jvmMain/kotlin/com/shepeliev/webrtckmp/App.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.shepeliev.webrtckmp | ||
|
||
import androidx.compose.animation.Crossfade | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.material.CircularProgressIndicator | ||
import androidx.compose.material.Scaffold | ||
import androidx.compose.material.Text | ||
import androidx.compose.material.TopAppBar | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.LaunchedEffect | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.ui.Modifier | ||
import com.arkivanov.decompose.extensions.compose.jetbrains.subscribeAsState | ||
import com.shepeliev.webrtckmp.sample.shared.Room | ||
|
||
@Composable | ||
fun App(room: Room) { | ||
val roomModel by room.model.subscribeAsState() | ||
|
||
Crossfade(targetState = roomModel) { model -> | ||
when (model.localStream) { | ||
null -> SelectMicrophoneCameraScreen(room) | ||
else -> VideoScreen(room) | ||
} | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
sample/app-jvm/src/jvmMain/kotlin/com/shepeliev/webrtckmp/JoinRoomButton.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package com.shepeliev.webrtckmp | ||
|
||
import androidx.compose.material.AlertDialog | ||
import androidx.compose.material.Button | ||
import androidx.compose.material.ExperimentalMaterialApi | ||
import androidx.compose.material.OutlinedTextField | ||
import androidx.compose.material.Text | ||
import androidx.compose.material.TextButton | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.runtime.setValue | ||
|
||
@OptIn(ExperimentalMaterialApi::class) | ||
@Composable | ||
fun JoinRoomButton(onJoin: (String) -> Unit, enabled: Boolean) { | ||
var isJoinDialogVisible by remember { mutableStateOf(false) } | ||
|
||
if (isJoinDialogVisible) { | ||
var roomId by remember { mutableStateOf("") } | ||
|
||
AlertDialog( | ||
onDismissRequest = { isJoinDialogVisible = false }, | ||
|
||
confirmButton = { | ||
TextButton( | ||
onClick = { | ||
onJoin(roomId) | ||
isJoinDialogVisible = false | ||
}, | ||
enabled = roomId.isNotBlank() | ||
) { | ||
Text("Join") | ||
} | ||
}, | ||
|
||
dismissButton = { | ||
TextButton(onClick = { isJoinDialogVisible = false }) { | ||
Text("Cancel") | ||
} | ||
}, | ||
|
||
title = { Text("Join into room") }, | ||
|
||
text = { | ||
OutlinedTextField( | ||
value = roomId, | ||
onValueChange = { roomId = it }, | ||
placeholder = { Text("Room ID") } | ||
) | ||
} | ||
) | ||
} | ||
|
||
Button(onClick = { isJoinDialogVisible = true }, enabled = enabled) { | ||
Text("Join") | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
sample/app-jvm/src/jvmMain/kotlin/com/shepeliev/webrtckmp/Main.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package com.shepeliev.webrtckmp | ||
|
||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.material.Text | ||
import androidx.compose.runtime.CompositionLocalProvider | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.setValue | ||
import androidx.compose.ui.ExperimentalComposeUiApi | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.unit.Dp | ||
import androidx.compose.ui.unit.dp | ||
import androidx.compose.ui.window.LocalWindowExceptionHandlerFactory | ||
import androidx.compose.ui.window.Window | ||
import androidx.compose.ui.window.WindowExceptionHandler | ||
import androidx.compose.ui.window.WindowExceptionHandlerFactory | ||
import androidx.compose.ui.window.WindowState | ||
import androidx.compose.ui.window.application | ||
import androidx.compose.ui.window.singleWindowApplication | ||
import com.arkivanov.decompose.DefaultComponentContext | ||
import com.arkivanov.essenty.lifecycle.LifecycleRegistry | ||
import com.shepeliev.webrtckmp.sample.shared.RoomComponent | ||
import dev.onvoid.webrtc.logging.Logging | ||
import kotlinx.coroutines.CoroutineName | ||
import kotlinx.coroutines.CoroutineScope | ||
import java.awt.event.WindowEvent | ||
import kotlin.coroutines.EmptyCoroutineContext | ||
import kotlin.system.exitProcess | ||
|
||
|
||
@OptIn(ExperimentalComposeUiApi::class) | ||
fun main() { | ||
var lastError: Throwable? by mutableStateOf(null) | ||
|
||
WebRtc.configureBuilder { | ||
loggingSeverity = Logging.Severity.INFO | ||
} | ||
|
||
application(exitProcessOnExit = false) { | ||
System.setProperty("compose.interop.blending", "true") | ||
|
||
val lifecycle = LifecycleRegistry() | ||
|
||
val room = RoomComponent( | ||
componentContext = DefaultComponentContext(lifecycle), | ||
scope = CoroutineScope(EmptyCoroutineContext + CoroutineName("App")), | ||
) | ||
|
||
CompositionLocalProvider( | ||
LocalWindowExceptionHandlerFactory provides WindowExceptionHandlerFactory { window -> | ||
WindowExceptionHandler { | ||
lastError = it | ||
window.dispatchEvent(WindowEvent(window, WindowEvent.WINDOW_CLOSING)) | ||
} | ||
} | ||
) { | ||
Window(onCloseRequest = ::exitApplication) { | ||
App(room) | ||
} | ||
} | ||
} | ||
|
||
if (lastError != null) { | ||
lastError?.printStackTrace() | ||
singleWindowApplication( | ||
state = WindowState(width = 200.dp, height = Dp.Unspecified), | ||
exitProcessOnExit = false | ||
) { | ||
Text(lastError?.message ?: "Unknown error", Modifier.padding(8.dp)) | ||
} | ||
|
||
exitProcess(1) | ||
} else { | ||
exitProcess(0) | ||
} | ||
} |
Oops, something went wrong.