Skip to content

Commit

Permalink
✨ add the final filters, finish the track related endpoints.
Browse files Browse the repository at this point in the history
  • Loading branch information
MeLike2D committed Feb 26, 2021
1 parent 48b11d9 commit 21d6f08
Show file tree
Hide file tree
Showing 18 changed files with 441 additions and 87 deletions.
16 changes: 10 additions & 6 deletions Server/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,20 @@ dependencies {

/* ktor */

// metrics
// Serialization
implementation "io.ktor:ktor-serialization:$ktorVersion"

// Metrics
implementation "io.ktor:ktor-metrics-micrometer:$ktorVersion"
implementation "io.micrometer:micrometer-registry-prometheus:latest.release"

// server shit
// Server
implementation "io.ktor:ktor-server-core:$ktorVersion"
implementation "io.ktor:ktor-websockets:$ktorVersion"
implementation "io.ktor:ktor-server-cio:$ktorVersion"
implementation "io.ktor:ktor-locations:$ktorVersion"

// client shit
// Client
implementation "io.ktor:ktor-client-core:$ktorVersion"
implementation "io.ktor:ktor-client-websockets:$ktorVersion"
implementation "io.ktor:ktor-client-okhttp:$ktorVersion"
Expand All @@ -79,13 +82,14 @@ jar {
compileJava.options.encoding = "UTF-8"

compileKotlin {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
sourceCompatibility = JavaVersion.VERSION_13
targetCompatibility = JavaVersion.VERSION_13

kotlinOptions {
jvmTarget = "11"
jvmTarget = "13"
freeCompilerArgs += "-Xopt-in=kotlin.ExperimentalStdlibApi"
freeCompilerArgs += "-Xopt-in=kotlinx.coroutines.ObsoleteCoroutinesApi"
freeCompilerArgs += "-Xopt-in=io.ktor.locations.KtorExperimentalLocationsAPI"
freeCompilerArgs += "-Xinline-classes"
}
}
Expand Down
13 changes: 12 additions & 1 deletion Server/src/main/kotlin/obsidian/server/Obsidian.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ import ch.qos.logback.core.rolling.TimeBasedRollingPolicy
import com.uchuhimo.konf.Config
import com.uchuhimo.konf.source.yaml
import io.ktor.application.*
import io.ktor.features.*
import io.ktor.locations.*
import io.ktor.metrics.micrometer.*
import io.ktor.routing.*
import io.ktor.serialization.*
import io.ktor.server.cio.*
import io.ktor.server.engine.*
import io.ktor.websocket.*
Expand Down Expand Up @@ -78,8 +80,17 @@ object Obsidian {

val server = embeddedServer(CIO, host = config[ObsidianConfig.Host], port = config[ObsidianConfig.Port]) {
install(Locations)

install(WebSockets)
install(MicrometerMetrics) { registry = metricRegistry }

install(MicrometerMetrics) {
registry = metricRegistry
}

@Suppress()
install(ContentNegotiation) {
json()
}

routing {
magma.use(this)
Expand Down
2 changes: 1 addition & 1 deletion Server/src/main/kotlin/obsidian/server/io/Dispatch.kt
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ data class CurrentTrack(

@Serializable
data class Frames(
val nulled: Int,
val lost: Int,
val sent: Int
)

Expand Down
5 changes: 5 additions & 0 deletions Server/src/main/kotlin/obsidian/server/io/MagmaClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ class MagmaClient(
link.seekTo(position)
}

on<Destroy> {
links[guildId]?.player?.stopTrack()
bedrock.destroyConnection(guildId)
}

on<StopTrack> {
val link = links.computeIfAbsent(guildId) {
Link(this@MagmaClient, guildId)
Expand Down
3 changes: 2 additions & 1 deletion Server/src/main/kotlin/obsidian/server/io/Op.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ enum class Op(val code: Int) {
StopTrack(5),
Pause(6),
Filters(7),
Seek(8);
Seek(8),
Destroy(9);

companion object Serializer : KSerializer<Op> {
/**
Expand Down
26 changes: 12 additions & 14 deletions Server/src/main/kotlin/obsidian/server/io/Operation.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,14 @@
package obsidian.server.io

import kotlinx.serialization.*
import kotlinx.serialization.builtins.LongAsStringSerializer
import kotlinx.serialization.builtins.nullable
import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.descriptors.buildClassSerialDescriptor
import kotlinx.serialization.encoding.CompositeDecoder
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.json.JsonElement
import kotlinx.serialization.json.JsonObject
import obsidian.server.player.filter.impl.EqualizerFilter
import obsidian.server.player.filter.impl.TimescaleFilter
import obsidian.server.player.filter.impl.TremoloFilter
import obsidian.server.player.filter.impl.*

sealed class Operation {
companion object : DeserializationStrategy<Operation?> {
Expand Down Expand Up @@ -63,6 +60,7 @@ sealed class Operation {
Op.Pause -> decode(Pause.serializer())
Op.Filters -> decode(Filters.serializer())
Op.Seek -> decode(Seek.serializer())
Op.Destroy -> decode(Destroy.serializer())

else -> if (data == null) {
val element = decodeNullableSerializableElement(descriptor, idx, JsonElement.serializer().nullable)
Expand All @@ -86,7 +84,6 @@ sealed class Operation {
data class PlayTrack(
val track: String,

@Serializable(with = LongAsStringSerializer::class)
@SerialName("guild_id")
val guildId: Long,

Expand All @@ -101,18 +98,13 @@ data class PlayTrack(
) : Operation()

@Serializable
data class StopTrack(
@Serializable(with = LongAsStringSerializer::class)
val guildId: Long

) : Operation()
data class StopTrack(@SerialName("guild_id") val guildId: Long) : Operation()

@Serializable
data class SubmitVoiceUpdate(
val endpoint: String,
val token: String,

@Serializable(with = LongAsStringSerializer::class)
@SerialName("guild_id")
val guildId: Long,

Expand All @@ -122,22 +114,25 @@ data class SubmitVoiceUpdate(

@Serializable
data class Pause(
@Serializable(with = LongAsStringSerializer::class)
@SerialName("guild_id")
val guildId: Long,
val state: Boolean = true
) : Operation()

@Serializable
data class Filters(
@Serializable(with = LongAsStringSerializer::class)
@SerialName("guild_id")
val guildId: Long,

val volume: Float? = null,
val tremolo: TremoloFilter? = null,
val equalizer: EqualizerFilter? = null,
val timescale: TimescaleFilter? = null
val timescale: TimescaleFilter? = null,
val karaoke: KaraokeFilter? = null,
val channelMix: ChannelMixFilter? = null,
val vibrato: VibratoFilter? = null,
val rotation: RotationFilter? = null,
val lowPass: LowPassFilter? = null
) : Operation()

@Serializable
Expand All @@ -146,3 +141,6 @@ data class Seek(
val guildId: Long,
val position: Long
) : Operation()

@Serializable
data class Destroy(@SerialName("guild_id") val guildId: Long) : Operation()
Loading

0 comments on commit 21d6f08

Please sign in to comment.