Skip to content

Commit

Permalink
Add stubs for Windows
Browse files Browse the repository at this point in the history
Relates-to: #929
  • Loading branch information
DRSchlaubi committed Apr 12, 2024
1 parent d0e9511 commit 38d8fec
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 13 deletions.
6 changes: 1 addition & 5 deletions buildSrc/src/main/kotlin/Targets.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
import org.jetbrains.kotlin.gradle.kpm.external.ExternalVariantApi
import org.jetbrains.kotlin.gradle.kpm.external.project
import org.jetbrains.kotlin.konan.target.HostManager

@OptIn(ExternalVariantApi::class)
Expand All @@ -14,10 +13,7 @@ fun KotlinMultiplatformExtension.targets() {

jvm()

if (project.name != "voice" && project.name != "core-voice") {
// https://youtrack.jetbrains.com/issue/KTOR-4080
mingwX64()
}
mingwX64()

js {
nodejs {
Expand Down
19 changes: 18 additions & 1 deletion voice/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,9 +1,26 @@
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi

plugins {
`kord-multiplatform-module`
`kord-publishing`
}

@OptIn(ExperimentalKotlinGradlePluginApi::class)
kotlin {
applyDefaultHierarchyTemplate {
common {
group("ktor") {
withJvm()
withApple()
withLinux()
}

group("nonKtor") {
withJs()
withMingw()
}
}
}
jvm {
withJava()
}
Expand All @@ -18,7 +35,7 @@ kotlin {
compileOnly(projects.kspAnnotations)
}

nonJsMain.dependencies {
named("ktorMain").dependencies {
api(libs.ktor.network)
}

Expand Down
10 changes: 10 additions & 0 deletions voice/src/commonMain/kotlin/VoiceConnectionBuilder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,23 @@ import kotlinx.coroutines.flow.first
import kotlin.time.Duration
import kotlin.time.Duration.Companion.milliseconds

internal expect val isSupported: Boolean

@KordVoice
public class VoiceConnectionBuilder(
public var gateway: Gateway,
public var selfId: Snowflake,
public var channelId: Snowflake,
public var guildId: Snowflake
) {
init {
if(!isSupported) {
throw UnsupportedOperationException("""
Voice is currently not supported on Windows, if you're developing on Windows we recommend using
WSL: https://aka.ms/wsl
""".trimIndent())
}
}
/**
* The amount in milliseconds to wait for the events required to create a [VoiceConnection]. Default is 5000, or 5 seconds.
*/
Expand Down
3 changes: 3 additions & 0 deletions voice/src/jsMain/kotlin/VoiceConnectionBuilder.js.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package dev.kord.voice

internal actual val isSupported: Boolean = true
7 changes: 0 additions & 7 deletions voice/src/jsMain/kotlin/udp/VoiceUdpSocket.js.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package dev.kord.voice.udp

import dev.kord.common.annotation.KordVoice
import dev.kord.voice.io.ByteArrayView
import io.ktor.utils.io.core.*
import js.typedarrays.toUint8Array
Expand All @@ -16,12 +15,6 @@ import kotlin.coroutines.resume
import kotlin.coroutines.resumeWithException
import kotlin.coroutines.suspendCoroutine

@KordVoice
public actual data class SocketAddress actual constructor(
public actual val hostname: String,
public actual val port: Int,
)

public actual val GlobalVoiceUdpSocket: VoiceUdpSocket = object : VoiceUdpSocket {
private val socketScope =
CoroutineScope(Dispatchers.Default + SupervisorJob() + CoroutineName("kord-voice-global-socket"))
Expand Down
3 changes: 3 additions & 0 deletions voice/src/ktorMain/kotlin/VoiceConnectionBuilder.ktor.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package dev.kord.voice

internal actual val isSupported: Boolean = true
3 changes: 3 additions & 0 deletions voice/src/mingwMain/kotlin/VoiceConnectionBuilder.mingw.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package dev.kord.voice

internal actual val isSupported: Boolean = false
18 changes: 18 additions & 0 deletions voice/src/mingwMain/kotlin/udp/VoiceUdpSocket.nonJs.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package dev.kord.voice.udp

import dev.kord.common.annotation.KordVoice
import dev.kord.voice.io.ByteArrayView
import io.ktor.utils.io.core.*
import kotlinx.coroutines.flow.Flow

@KordVoice
public actual val GlobalVoiceUdpSocket: VoiceUdpSocket = object : VoiceUdpSocket {
override fun all(address: SocketAddress): Flow<ByteReadPacket> = unsupported()

override suspend fun send(address: SocketAddress, packet: ByteArrayView) = unsupported()

override suspend fun stop() = unsupported()
}

private fun unsupported(): Nothing = TODO("Voice is not supported on windows")

9 changes: 9 additions & 0 deletions voice/src/nonKtorMain/kotlin/VoiceUdpSocket.js.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package dev.kord.voice.udp

import dev.kord.common.annotation.KordVoice

@KordVoice
public actual data class SocketAddress actual constructor(
public actual val hostname: String,
public actual val port: Int,
)

0 comments on commit 38d8fec

Please sign in to comment.