upnp service startup delayed
This commit is contained in:
parent
c3e8bf240d
commit
d9620e2056
5 changed files with 48 additions and 34 deletions
|
@ -1,6 +1,8 @@
|
|||
package net.schowek.nextclouddlna.dlna
|
||||
package net.schowek.nextclouddlna
|
||||
|
||||
import jakarta.annotation.PreDestroy
|
||||
import mu.KLogging
|
||||
import net.schowek.nextclouddlna.dlna.RegistryImplWithOverrides
|
||||
import net.schowek.nextclouddlna.dlna.media.MediaServer
|
||||
import net.schowek.nextclouddlna.dlna.transport.ApacheStreamClient
|
||||
import net.schowek.nextclouddlna.dlna.transport.ApacheStreamClientConfiguration
|
||||
|
@ -20,6 +22,8 @@ import org.jupnp.transport.impl.NetworkAddressFactoryImpl
|
|||
import org.jupnp.transport.spi.NetworkAddressFactory
|
||||
import org.jupnp.transport.spi.StreamClient
|
||||
import org.jupnp.transport.spi.StreamServer
|
||||
import org.springframework.context.event.ContextRefreshedEvent
|
||||
import org.springframework.context.event.EventListener
|
||||
import org.springframework.stereotype.Component
|
||||
import java.net.InetAddress
|
||||
import java.net.NetworkInterface
|
||||
|
@ -27,15 +31,25 @@ import java.net.NetworkInterface
|
|||
|
||||
@Component
|
||||
class DlnaService(
|
||||
private val serverInfoProvider: ServerInfoProvider,
|
||||
private val mediaServer: MediaServer
|
||||
private val mediaServer: MediaServer,
|
||||
serverInfoProvider: ServerInfoProvider,
|
||||
) {
|
||||
// Named this way cos NetworkAddressFactoryImpl has a bindAddresses field.
|
||||
private val addressesToBind: List<InetAddress> = listOf(serverInfoProvider.address!!)
|
||||
var upnpService: UpnpService = MyUpnpService(MyUpnpServiceConfiguration())
|
||||
|
||||
fun start() = MyUpnpService(MyUpnpServiceConfiguration()).also {
|
||||
it.startup()
|
||||
it.registry.addDevice(mediaServer.device)
|
||||
fun start() {
|
||||
upnpService.startup()
|
||||
upnpService.registry.addDevice(mediaServer.device)
|
||||
}
|
||||
|
||||
@EventListener
|
||||
fun handleContextRefresh(event: ContextRefreshedEvent) {
|
||||
start()
|
||||
}
|
||||
|
||||
@PreDestroy
|
||||
fun destroy() {
|
||||
upnpService.shutdown()
|
||||
}
|
||||
|
||||
inner class MyUpnpService(
|
||||
|
@ -79,6 +93,8 @@ class DlnaService(
|
|||
return addressesToBind.contains(address)
|
||||
}
|
||||
}
|
||||
|
||||
companion object : KLogging()
|
||||
}
|
||||
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
package net.schowek.nextclouddlna
|
||||
|
||||
import jakarta.annotation.PreDestroy
|
||||
import net.schowek.nextclouddlna.dlna.DlnaService
|
||||
import org.jupnp.UpnpService
|
||||
import org.springframework.stereotype.Component
|
||||
|
||||
|
||||
@Component
|
||||
class NextcloudDLNA(
|
||||
dlnaService: DlnaService
|
||||
) {
|
||||
val upnpService: UpnpService = dlnaService.start()
|
||||
|
||||
@PreDestroy
|
||||
fun destroy() {
|
||||
upnpService.shutdown()
|
||||
}
|
||||
}
|
||||
|
|
@ -3,16 +3,17 @@ package net.schowek.nextclouddlna.controller
|
|||
import UpnpStreamProcessor
|
||||
import jakarta.servlet.http.HttpServletRequest
|
||||
import mu.KLogging
|
||||
import net.schowek.nextclouddlna.NextcloudDLNA
|
||||
import net.schowek.nextclouddlna.DlnaService
|
||||
import net.schowek.nextclouddlna.dlna.media.MediaServer
|
||||
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.util.MultiValueMap
|
||||
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,7 +22,7 @@ import org.springframework.web.bind.annotation.ResponseBody
|
|||
|
||||
@Controller
|
||||
class DLNAController(
|
||||
private val dlna: NextcloudDLNA,
|
||||
private val dlna: DlnaService,
|
||||
private val streamRequestMapper: StreamRequestMapper
|
||||
) {
|
||||
@RequestMapping(
|
||||
|
@ -77,5 +78,12 @@ class DLNAController(
|
|||
)
|
||||
}
|
||||
|
||||
@GetMapping("/alive")
|
||||
fun sendAlive(): ResponseEntity<String> {
|
||||
logger.info { "STARTING!" }
|
||||
dlna.start();
|
||||
return ResponseEntity(HttpStatus.OK)
|
||||
}
|
||||
|
||||
companion object : KLogging()
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import mu.KLogging
|
||||
import net.schowek.nextclouddlna.NextcloudDLNA
|
||||
import net.schowek.nextclouddlna.DlnaService
|
||||
import org.jupnp.model.message.StreamRequestMessage
|
||||
import org.jupnp.model.message.StreamResponseMessage
|
||||
import org.jupnp.model.message.UpnpResponse
|
||||
|
@ -7,8 +7,8 @@ import org.jupnp.transport.spi.UpnpStream
|
|||
|
||||
|
||||
class UpnpStreamProcessor(
|
||||
dlna: NextcloudDLNA
|
||||
) : UpnpStream(dlna.upnpService.protocolFactory) {
|
||||
dlna: DlnaService
|
||||
) : UpnpStream(dlna.upnpService!!.protocolFactory) {
|
||||
|
||||
fun processMessage(requestMsg: StreamRequestMessage): StreamResponseMessage {
|
||||
logger.debug { "Processing $requestMsg" }
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
package net.schowek.nextclouddlna.dlna
|
||||
|
||||
import mu.KLogging
|
||||
import net.schowek.nextclouddlna.dlna.media.MediaServer
|
||||
import net.schowek.nextclouddlna.dlna.media.MediaServer.Companion.ICON_FILENAME
|
||||
import org.jupnp.UpnpService
|
||||
import org.jupnp.model.resource.IconResource
|
||||
import org.jupnp.model.resource.Resource
|
||||
import org.jupnp.registry.RegistryImpl
|
||||
import org.jupnp.registry.RegistryMaintainer
|
||||
import java.io.IOException
|
||||
import java.net.URI
|
||||
|
||||
|
@ -31,4 +33,12 @@ class RegistryImplWithOverrides(
|
|||
icon
|
||||
} else super.getResource(pathQuery)
|
||||
}
|
||||
}
|
||||
|
||||
fun maintain() {
|
||||
logger.info { "REGISTRY MAINTAIN" }
|
||||
Thread(registryMaintainer).start()
|
||||
logger.info { "REGISTRY MAINTAIN DONE" }
|
||||
}
|
||||
|
||||
companion object : KLogging()
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue