UpnpService as bean
This commit is contained in:
parent
742686d55f
commit
70ed4185fd
6 changed files with 54 additions and 66 deletions
|
@ -32,7 +32,7 @@ import java.net.NetworkInterface
|
|||
@Component
|
||||
class DlnaService(
|
||||
private val mediaServer: MediaServer,
|
||||
serverInfoProvider: ServerInfoProvider,
|
||||
private val serverInfoProvider: ServerInfoProvider,
|
||||
) {
|
||||
private val addressesToBind: List<InetAddress> = listOf(serverInfoProvider.address!!)
|
||||
var upnpService: UpnpService = MyUpnpService(MyUpnpServiceConfiguration())
|
||||
|
@ -55,16 +55,16 @@ class DlnaService(
|
|||
inner class MyUpnpService(
|
||||
configuration: UpnpServiceConfiguration
|
||||
) : UpnpServiceImpl(configuration) {
|
||||
init {
|
||||
protocolFactory = createProtocolFactory()
|
||||
}
|
||||
|
||||
override fun createRegistry(pf: ProtocolFactory): Registry {
|
||||
return RegistryImplWithOverrides(this)
|
||||
}
|
||||
|
||||
override fun createProtocolFactory(): ProtocolFactory? {
|
||||
return MyProtocolFactory(this)
|
||||
}
|
||||
}
|
||||
|
||||
private inner class MyUpnpServiceConfiguration : DefaultUpnpServiceConfiguration(8080) {
|
||||
private inner class MyUpnpServiceConfiguration : DefaultUpnpServiceConfiguration(serverInfoProvider.port) {
|
||||
override fun createStreamClient(): StreamClient<*> {
|
||||
return ApacheStreamClient(
|
||||
ApacheStreamClientConfiguration(syncProtocolExecutorService)
|
||||
|
@ -96,15 +96,3 @@ class DlnaService(
|
|||
|
||||
companion object : KLogging()
|
||||
}
|
||||
|
||||
|
||||
class MyProtocolFactory(
|
||||
upnpService: UpnpService
|
||||
) : ProtocolFactoryImpl(upnpService) {
|
||||
override fun createSendingNotificationAlive(localDevice: LocalDevice): SendingNotificationAlive {
|
||||
logger.info { "SENDING ALIVE $localDevice" }
|
||||
return SendingNotificationAlive(upnpService, localDevice)
|
||||
}
|
||||
|
||||
companion object : KLogging()
|
||||
}
|
|
@ -1,19 +1,17 @@
|
|||
package net.schowek.nextclouddlna.controller
|
||||
|
||||
import UpnpStreamProcessor
|
||||
import jakarta.servlet.http.HttpServletRequest
|
||||
import mu.KLogging
|
||||
import net.schowek.nextclouddlna.DlnaService
|
||||
import net.schowek.nextclouddlna.dlna.media.MediaServer
|
||||
import net.schowek.nextclouddlna.upnp.StreamRequestMapper
|
||||
import net.schowek.nextclouddlna.upnp.UpnpStreamProcessor
|
||||
import org.springframework.core.io.InputStreamResource
|
||||
import org.springframework.core.io.Resource
|
||||
import org.springframework.http.HttpHeaders
|
||||
import org.springframework.http.HttpStatus
|
||||
import org.springframework.http.HttpStatusCode
|
||||
import org.springframework.http.MediaType.APPLICATION_OCTET_STREAM_VALUE
|
||||
import org.springframework.http.ResponseEntity
|
||||
import org.springframework.stereotype.Controller
|
||||
import org.springframework.web.bind.annotation.GetMapping
|
||||
import org.springframework.web.bind.annotation.PathVariable
|
||||
import org.springframework.web.bind.annotation.RequestMapping
|
||||
import org.springframework.web.bind.annotation.RequestMethod.*
|
||||
|
@ -21,9 +19,9 @@ import org.springframework.web.bind.annotation.ResponseBody
|
|||
|
||||
|
||||
@Controller
|
||||
class DLNAController(
|
||||
private val dlna: DlnaService,
|
||||
private val streamRequestMapper: StreamRequestMapper
|
||||
class UpnpController(
|
||||
private val streamRequestMapper: StreamRequestMapper,
|
||||
private val upnpStreamProcessor: UpnpStreamProcessor
|
||||
) {
|
||||
@RequestMapping(
|
||||
method = [GET, HEAD], value = ["/dev/{uid}/icon.png"],
|
||||
|
@ -51,7 +49,7 @@ class DLNAController(
|
|||
request: HttpServletRequest
|
||||
): ResponseEntity<Any> {
|
||||
logger.info { "GET request from ${request.remoteAddr}: ${request.requestURI}" }
|
||||
val r = UpnpStreamProcessor(dlna).processMessage(streamRequestMapper.map(request))
|
||||
val r = upnpStreamProcessor.processMessage(streamRequestMapper.map(request))
|
||||
return ResponseEntity(
|
||||
r.body,
|
||||
HttpHeaders().also { h -> r.headers.entries.forEach { h.add(it.key, it.value.joinToString { it }) } },
|
||||
|
@ -70,7 +68,7 @@ class DLNAController(
|
|||
request: HttpServletRequest
|
||||
): ResponseEntity<Any> {
|
||||
logger.info { "POST request from ${request.remoteAddr}: ${request.requestURI}" }
|
||||
val r = UpnpStreamProcessor(dlna).processMessage(streamRequestMapper.map(request))
|
||||
val r = upnpStreamProcessor.processMessage(streamRequestMapper.map(request))
|
||||
return ResponseEntity(
|
||||
r.body,
|
||||
HttpHeaders().also { h -> r.headers.entries.forEach { h.add(it.key, it.value.joinToString { it }) } },
|
||||
|
@ -78,12 +76,5 @@ class DLNAController(
|
|||
)
|
||||
}
|
||||
|
||||
@GetMapping("/alive")
|
||||
fun sendAlive(): ResponseEntity<String> {
|
||||
logger.info { "STARTING!" }
|
||||
dlna.start();
|
||||
return ResponseEntity(HttpStatus.OK)
|
||||
}
|
||||
|
||||
companion object : KLogging()
|
||||
}
|
|
@ -1,26 +0,0 @@
|
|||
import mu.KLogging
|
||||
import net.schowek.nextclouddlna.DlnaService
|
||||
import org.jupnp.model.message.StreamRequestMessage
|
||||
import org.jupnp.model.message.StreamResponseMessage
|
||||
import org.jupnp.model.message.UpnpResponse
|
||||
import org.jupnp.transport.spi.UpnpStream
|
||||
|
||||
|
||||
class UpnpStreamProcessor(
|
||||
dlna: DlnaService
|
||||
) : UpnpStream(dlna.upnpService!!.protocolFactory) {
|
||||
|
||||
fun processMessage(requestMsg: StreamRequestMessage): StreamResponseMessage {
|
||||
logger.debug { "Processing $requestMsg" }
|
||||
var response = super.process(requestMsg)
|
||||
if (response == null) {
|
||||
response = StreamResponseMessage(UpnpResponse.Status.NOT_FOUND)
|
||||
}
|
||||
return response
|
||||
}
|
||||
|
||||
override fun run() {
|
||||
}
|
||||
|
||||
companion object : KLogging()
|
||||
}
|
|
@ -16,11 +16,6 @@ class ContentTreeProvider(
|
|||
private var tree = buildContentTree()
|
||||
private var lastMTime = 0L
|
||||
|
||||
init {
|
||||
rebuildTree()
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
@Scheduled(fixedDelay = 1000 * 60, initialDelay = 1000 * 60)
|
||||
final fun rebuildTree() {
|
||||
val maxMtime: Long = mediaDB.maxMtime()
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package net.schowek.nextclouddlna.controller
|
||||
package net.schowek.nextclouddlna.upnp
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest
|
||||
import mu.KLogging
|
|
@ -0,0 +1,40 @@
|
|||
package net.schowek.nextclouddlna.upnp
|
||||
|
||||
import mu.KLogging
|
||||
import net.schowek.nextclouddlna.DlnaService
|
||||
import org.jupnp.model.message.StreamRequestMessage
|
||||
import org.jupnp.model.message.StreamResponseMessage
|
||||
import org.jupnp.model.message.UpnpResponse
|
||||
import org.jupnp.protocol.ProtocolFactory
|
||||
import org.jupnp.transport.spi.UpnpStream
|
||||
import org.springframework.stereotype.Component
|
||||
|
||||
@Component
|
||||
class UpnpStreamProcessor(
|
||||
private val dlna: DlnaService
|
||||
) {
|
||||
private var upnpStream: UpnpStreamImpl? = null
|
||||
|
||||
fun processMessage(requestMsg: StreamRequestMessage): StreamResponseMessage {
|
||||
logger.debug { "Processing $requestMsg" }
|
||||
var response = getUpnpStream().process(requestMsg)
|
||||
if (response == null) {
|
||||
response = StreamResponseMessage(UpnpResponse.Status.NOT_FOUND)
|
||||
}
|
||||
return response
|
||||
}
|
||||
|
||||
private fun getUpnpStream(): UpnpStreamImpl {
|
||||
if (upnpStream == null) {
|
||||
upnpStream = UpnpStreamImpl(dlna.upnpService.protocolFactory)
|
||||
}
|
||||
return upnpStream!!
|
||||
}
|
||||
|
||||
inner class UpnpStreamImpl(protocolFactory: ProtocolFactory) : UpnpStream(protocolFactory) {
|
||||
override fun run() {
|
||||
}
|
||||
}
|
||||
|
||||
companion object : KLogging()
|
||||
}
|
Loading…
Reference in a new issue