Skip to content

Commit

Permalink
jackson serialization (#12)
Browse files Browse the repository at this point in the history
* WIP jackson serialisation

* Expose even less protocol items

* Un-deprecate items

* Build a custom track for better use with jackson

* Add jackson custom json request

* Clean track update builder

* Update documentation
  • Loading branch information
duncte123 authored Dec 13, 2023
1 parent d4ecf36 commit e064ea6
Show file tree
Hide file tree
Showing 20 changed files with 438 additions and 158 deletions.
5 changes: 3 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@ repositories {
dependencies {
// package libraries
api(kotlin("stdlib"))
api(libs.kotlin)
// api(libs.kotlin)
api(libs.lavalink.protocol)
api(libs.okhttp)
api(libs.jackson)
api(libs.bundles.reactor)
api(libs.logger.api)

Expand Down Expand Up @@ -106,7 +107,7 @@ tasks.test {
}

tasks.wrapper {
gradleVersion = "8.1.1"
gradleVersion = "8.5"
distributionType = Wrapper.DistributionType.BIN
}

Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
3 changes: 2 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
25 changes: 18 additions & 7 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
Expand All @@ -80,13 +80,10 @@ do
esac
done

APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit

APP_NAME="Gradle"
# This is normally unused
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down Expand Up @@ -143,12 +140,16 @@ fi
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
Expand Down Expand Up @@ -193,6 +194,10 @@ if "$cygwin" || "$msys" ; then
done
fi


# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
Expand All @@ -205,6 +210,12 @@ set -- \
org.gradle.wrapper.GradleWrapperMain \
"$@"

# Stop when "xargs" is not available.
if ! command -v xargs >/dev/null 2>&1
then
die "xargs is not available"
fi

# Use "xargs" to parse quoted args.
#
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
Expand Down
15 changes: 9 additions & 6 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
@rem limitations under the License.
@rem

@if "%DEBUG%" == "" @echo off
@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
Expand All @@ -25,7 +25,8 @@
if "%OS%"=="Windows_NT" setlocal

set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
if "%DIRNAME%"=="" set DIRNAME=.
@rem This is normally unused
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%

Expand All @@ -40,7 +41,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome

set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto execute
if %ERRORLEVEL% equ 0 goto execute

echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Expand Down Expand Up @@ -75,13 +76,15 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar

:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
if %ERRORLEVEL% equ 0 goto mainEnd

:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
set EXIT_CODE=%ERRORLEVEL%
if %EXIT_CODE% equ 0 set EXIT_CODE=1
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
exit /b %EXIT_CODE%

:mainEnd
if "%OS%"=="Windows_NT" endlocal
Expand Down
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ fun VersionCatalogBuilder.versionRefs() {

fun VersionCatalogBuilder.common() {
library("kotlin", "org.jetbrains.kotlin", "kotlin-stdlib").versionRef("kotlin")
library("jackson", "com.fasterxml.jackson.core", "jackson-core").version("2.16.0")
library("lavalink-protocol", "dev.arbjerg.lavalink", "protocol").version("4.0.0")
library("okhttp", "com.squareup.okhttp3", "okhttp").version("4.10.0")
library("reactor-core", "io.projectreactor", "reactor-core").version("3.5.6")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
package dev.arbjerg.lavalink.client

import dev.arbjerg.lavalink.protocol.v4.LoadResult
import dev.arbjerg.lavalink.client.protocol.*
import java.util.function.Consumer

abstract class AbstractAudioLoadResultHandler : Consumer<LoadResult> {
override fun accept(loadResult: LoadResult) {
abstract class AbstractAudioLoadResultHandler : Consumer<LavalinkLoadResult> {
override fun accept(loadResult: LavalinkLoadResult) {
when (loadResult) {
is LoadResult.TrackLoaded -> {
is TrackLoaded -> {
this.ontrackLoaded(loadResult)
}

is LoadResult.PlaylistLoaded -> {
is PlaylistLoaded -> {
this.onPlaylistLoaded(loadResult)
}

is LoadResult.SearchResult -> {
is SearchResult -> {
this.onSearchResultLoaded(loadResult)
}

is LoadResult.NoMatches -> {
is NoMatches -> {
this.noMatches()
}

is LoadResult.LoadFailed -> {
is LoadFailed -> {
this.loadFailed(loadResult)
}
}
}

abstract fun ontrackLoaded(result: LoadResult.TrackLoaded)
abstract fun onPlaylistLoaded(result: LoadResult.PlaylistLoaded)
abstract fun onSearchResultLoaded(result: LoadResult.SearchResult)
abstract fun ontrackLoaded(result: TrackLoaded)
abstract fun onPlaylistLoaded(result: PlaylistLoaded)
abstract fun onSearchResultLoaded(result: SearchResult)
abstract fun noMatches()
abstract fun loadFailed(result: LoadResult.LoadFailed)
abstract fun loadFailed(result: LoadFailed)
}
65 changes: 64 additions & 1 deletion src/main/kotlin/dev/arbjerg/lavalink/client/IUpdatablePlayer.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package dev.arbjerg.lavalink.client

import dev.arbjerg.lavalink.client.protocol.Track
import dev.arbjerg.lavalink.protocol.v4.Filters
import dev.arbjerg.lavalink.protocol.v4.Track
import dev.arbjerg.lavalink.protocol.v4.VoiceState

interface IUpdatablePlayer {
Expand All @@ -14,6 +14,11 @@ interface IUpdatablePlayer {
*/
fun setTrack(track: Track?): PlayerUpdateBuilder

/**
* @deprecated Use [setTrack] instead.
*
* @return The updated builder, useful for chaining
*/
@Deprecated(
message = "Use setTrack instead",
replaceWith = ReplaceWith("setTrack(track)")
Expand All @@ -24,42 +29,100 @@ interface IUpdatablePlayer {

/**
* Shortcut for setting the encoded track to {@code null}. This will also clear the user data.
*
* @return The updated builder, useful for chaining
*/
fun stopTrack(): PlayerUpdateBuilder

/**
* Sets the encoded track to be played.
* This will override the identifier and track user data if they were previously set.
*
* @param encodedTrack The encoded track to be played. Set it to {@code null} to make the player stop playing.
*
* @return The updated builder, useful for chaining
*/
fun setEncodedTrack(encodedTrack: String?): PlayerUpdateBuilder

/**
* Omits the encoded track field from being sent to the node during updates.
*
* @return The updated builder, useful for chaining
*/
fun omitEncodedTrack(): PlayerUpdateBuilder

/**
* Set the identifier on the player.
* This will override the encoded track and user data if they were previously set.
*
*
* @param identifier the identifier to be played
*
* @return The updated builder, useful for chaining
*/
fun setIdentifier(identifier: String?): PlayerUpdateBuilder

/**
* Update the position of the player.
*
* @param position The new position of the player. Set it to `null` to exclude this field from being sent with an update.
*
* @return The updated builder, useful for chaining
*/
fun setPosition(position: Long?): PlayerUpdateBuilder

/**
* Update the end time of the track.
*
* @param endTime The new end time of the track. Set it to `null` to exclude this field from being sent with an update.
*
* @return The updated builder, useful for chaining
*/
fun setEndTime(endTime: Long?): PlayerUpdateBuilder

/**
* Omits the end time from being sent to the node during updates.
*
* @return The updated builder, useful for chaining
*/
fun omitEndTime(): PlayerUpdateBuilder

/**
* Update the volume of the player.
* While you could use the filters to set volume as well, do note that that is float based (1.0f is 100% volume)
* and takes the time of your buffer size to apply. This method updates the volume instantly after the update is sent out.
*
* @param volume The new player volume, value is between 0 and 1000 where 100 is 100% (default) volume.
*
* @return The updated builder, useful for chaining
*/
fun setVolume(volume: Int): PlayerUpdateBuilder

/**
* Update the paused state of the player.
*
* @param paused Whether the player should be paused or not.
*
* @return The updated builder, useful for chaining
*/
fun setPaused(paused: Boolean): PlayerUpdateBuilder

/**
* Update the filters for the player.
* Please use [setVolume] to update the player's volume instead. Setting the volume via filters is
* float based (1.0f is 100% volume) and takes the time of your buffer size to apply.
*
* @param filters The new filters to apply to the player.
*
* @return The updated builder, useful for chaining
*/
fun setFilters(filters: Filters): PlayerUpdateBuilder

/**
* Update the voice state for the player.<br>
* <strong>IMPORTANT:</strong> Only ever use [Link.onVoiceServerUpdate] to update the voice server as this sets the state of the link to [LinkState.CONNECTING]
*
* @return The updated builder, useful for chaining
*/
fun setVoiceState(state: VoiceState): PlayerUpdateBuilder
}
Loading

0 comments on commit e064ea6

Please sign in to comment.