-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
7 changed files
with
92 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package dev.kord.voice | ||
|
||
internal actual val isSupported: Boolean = true |
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,3 @@ | ||
package dev.kord.voice | ||
|
||
internal actual val isSupported: Boolean = true |
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,46 @@ | ||
package dev.kord.voice.udp | ||
|
||
import dev.kord.common.annotation.KordVoice | ||
import dev.kord.voice.io.ByteArrayView | ||
import io.ktor.network.sockets.* | ||
import io.ktor.network.selector.* | ||
import io.ktor.network.sockets.Datagram | ||
import io.ktor.utils.io.core.* | ||
import kotlinx.coroutines.* | ||
import kotlinx.coroutines.flow.* | ||
import io.ktor.network.sockets.Datagram as KtorDatagram | ||
|
||
@KordVoice | ||
public actual typealias SocketAddress = InetSocketAddress | ||
|
||
@KordVoice | ||
public actual val GlobalVoiceUdpSocket: VoiceUdpSocket = object : VoiceUdpSocket { | ||
private val socketScope = | ||
CoroutineScope(Dispatchers.Default + SupervisorJob() + CoroutineName("kord-voice-global-socket")) | ||
|
||
private val socket = aSocket(SelectorManager(socketScope.coroutineContext)).udp().bind() | ||
|
||
private val incoming: MutableSharedFlow<Datagram> = MutableSharedFlow() | ||
|
||
init { | ||
socket.incoming | ||
.consumeAsFlow() | ||
.onEach { incoming.emit(it) } | ||
.launchIn(socketScope) | ||
} | ||
|
||
override fun all(address: SocketAddress): Flow<ByteReadPacket> { | ||
return incoming | ||
.filter { it.address == address } | ||
.map { it.packet } | ||
} | ||
|
||
override suspend fun send(address: SocketAddress, packet: ByteArrayView) { | ||
val brp = ByteReadPacket(packet.data, packet.dataStart, packet.viewSize) | ||
socket.send(KtorDatagram(brp, address)) | ||
} | ||
|
||
override suspend fun stop() { | ||
} | ||
} | ||
|
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,3 @@ | ||
package dev.kord.voice | ||
|
||
internal actual val isSupported: Boolean = false |
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,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") | ||
|
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,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, | ||
) |