Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
freyacodes committed Oct 27, 2018
2 parents 8d9e1bd + 21f135d commit a775c01
Show file tree
Hide file tree
Showing 12 changed files with 464 additions and 389 deletions.
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,23 @@
Each release usually includes various fixes and improvements.
The most noteworthy of these, as well as any features and breaking changes, are listed here.

## v3.1.1
* Add equalizer support
* Update lavaplayer to 1.3.10
* Fixed automatic versioning
* Added build config to upload binaries to GitHub releases from CI

Contributors:
[@Devoxin](https://github.com/Devoxin),
[@Frederikam](https://github.com/Frederikam/),
[@calebj](https://github.com/calebj)

## v3.1
* Replaced JDAA with Magma
* Added an event for when the Discord voice WebSocket is closed
* Replaced Tomcat and Java_Websocket with Undertow. WS and REST is now handled by the same
server and port. Port is specified by `server.port`.

## v3.0
* **Breaking:** The minimum required Java version to run the server is now Java 10.
**Please note**: Java 10 will be obsolete
Expand Down
18 changes: 18 additions & 0 deletions IMPLEMENTATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,24 @@ Set player volume. Volume may range from 0 to 1000. 100 is default.
}
```

Using the player equalizer
```json
{
"op": "equalizer",
"guildId": "...",
"bands": [
{
"band": 0,
"gain": 0.2
}
]
}
```
There are 16 bands (0-15) that can be changed.
`gain` is the multiplier for the given band. The default value is 0. Valid values range from -0.25 to 1.0,
where -0.25 means the given band is completely muted, and 0.25 means it is doubled. Modifying the gain could
also change the volume of the output.

Tell the server to potentially disconnect from the voice server and potentially remove the player with all its data.
This is useful if you want to move to a new node for a voice connection. Calling this op does not affect voice state,
and you can send the same VOICE_SERVER_UPDATE to a new node.
Expand Down
14 changes: 14 additions & 0 deletions LavalinkServer/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ apply plugin: 'application'
apply plugin: 'org.springframework.boot'
apply plugin: 'com.gorylenko.gradle-git-properties'
apply plugin: 'org.ajoberstar.grgit'
apply plugin: 'kotlin'
apply plugin: 'kotlin-spring'

description = 'Play audio to discord voice channels'
mainClassName = "lavalink.server.Launcher"
Expand Down Expand Up @@ -39,6 +41,7 @@ dependencies {
compile group: 'space.npstr', name: 'Magma', version: magmaVersion
compile group: 'com.sedmelluq', name: 'lavaplayer', version: lavaplayerVersion
compile group: 'com.sedmelluq', name: 'jda-nas', version: jdaNasVersion
compile group: 'org.jetbrains.kotlin', name: 'kotlin-reflect', version: kotlinVersion

compile group: 'com.github.shredder121', name: 'jda-async-packetprovider', version: jappVersion
//required by japp
Expand Down Expand Up @@ -79,6 +82,17 @@ build {
}
}

compileKotlin {
kotlinOptions {
jvmTarget = "1.8"
}
}
compileTestKotlin {
kotlinOptions {
jvmTarget = "1.8"
}
}

@SuppressWarnings("GrMethodMayBeStatic")
String versionFromTag() {

Expand Down
145 changes: 0 additions & 145 deletions LavalinkServer/src/main/java/lavalink/server/io/SocketContext.java

This file was deleted.

120 changes: 120 additions & 0 deletions LavalinkServer/src/main/java/lavalink/server/io/SocketContext.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
/*
* Copyright (c) 2017 Frederik Ar. Mikkelsen & NoobLance
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package lavalink.server.io

import com.sedmelluq.discord.lavaplayer.player.AudioPlayerManager
import lavalink.server.player.Player
import lavalink.server.util.Ws
import org.json.JSONObject
import org.slf4j.LoggerFactory
import org.springframework.web.socket.WebSocketSession
import space.npstr.magma.MagmaApi
import space.npstr.magma.MagmaMember
import space.npstr.magma.events.api.MagmaEvent
import space.npstr.magma.events.api.WebSocketClosed
import java.util.*
import java.util.concurrent.ConcurrentHashMap
import java.util.concurrent.Executors
import java.util.concurrent.ScheduledExecutorService
import java.util.concurrent.TimeUnit
import java.util.function.Consumer
import java.util.function.Supplier

class SocketContext internal constructor(audioPlayerManagerSupplier: Supplier<AudioPlayerManager>, val session: WebSocketSession,
socketServer: SocketServer, val userId: String) {

val audioPlayerManager: AudioPlayerManager = audioPlayerManagerSupplier.get()
internal val magma: MagmaApi = MagmaApi.of { socketServer.getAudioSendFactory(it) }
//guildId <-> Player
val players = ConcurrentHashMap<String, Player>()
private val statsExecutor: ScheduledExecutorService
val playerUpdateService: ScheduledExecutorService

val playingPlayers: List<Player>
get() {
val newList = LinkedList<Player>()
players.values.forEach { player -> if (player.isPlaying) newList.add(player) }
return newList
}


init {
magma.eventStream.subscribe { this.handleMagmaEvent(it) }

statsExecutor = Executors.newSingleThreadScheduledExecutor()
statsExecutor.scheduleAtFixedRate(StatsTask(this, socketServer), 0, 1, TimeUnit.MINUTES)

playerUpdateService = Executors.newScheduledThreadPool(2) { r ->
val thread = Thread(r)
thread.name = "player-update"
thread.isDaemon = true
thread
}
}

internal fun getPlayer(guildId: String): Player {
return players.computeIfAbsent(guildId
) { _ -> Player(this, guildId, audioPlayerManager) }
}

internal fun getPlayers(): Map<String, Player> {
return players
}

private fun handleMagmaEvent(magmaEvent: MagmaEvent) {
if (magmaEvent is WebSocketClosed) {
val out = JSONObject()
out.put("op", "event")
out.put("type", "WebSocketClosedEvent")
out.put("guildId", magmaEvent.member.guildId)
out.put("reason", magmaEvent.reason)
out.put("code", magmaEvent.closeCode)
out.put("byRemote", magmaEvent.isByRemote)

Ws.send(session, out)
}
}

internal fun shutdown() {
log.info("Shutting down " + playingPlayers.size + " playing players.")
statsExecutor.shutdown()
audioPlayerManager.shutdown()
playerUpdateService.shutdown()
players.keys.forEach { guildId ->
val member = MagmaMember.builder()
.userId(userId)
.guildId(guildId)
.build()
magma.removeSendHandler(member)
magma.closeConnection(member)
}

players.values.forEach(Consumer<Player> { it.stop() })
magma.shutdown()
}

companion object {

private val log = LoggerFactory.getLogger(SocketContext::class.java)
}
}
Loading

0 comments on commit a775c01

Please sign in to comment.