All Projects β†’ ohmae β†’ mmupnp

ohmae / mmupnp

Licence: MIT license
Universal Plug and Play (UPnP) ControlPoint library for Java/Kotlin

Programming Languages

kotlin
9241 projects

Projects that are alternatives of or similar to mmupnp

Airconnect Synology
AirConnect package for Synology NAS and Synology Router
Stars: ✭ 102 (+161.54%)
Mutual labels:  upnp
Netdisco
πŸ”Ž Python library to scan local network for services and devices.
Stars: ✭ 240 (+515.38%)
Mutual labels:  upnp
dslrbrowser-ios
DSLR Browser iOS app to discover and connect to your Wi-Fi and DLNA enabled (Canon) camera
Stars: ✭ 17 (-56.41%)
Mutual labels:  upnp
Droidupnp
DroidUPnP is an upnp control point application for android.
Stars: ✭ 122 (+212.82%)
Mutual labels:  upnp
Internet Hosting Tool
Enable Moonlight streaming from your PC over the Internet with no configuration required
Stars: ✭ 205 (+425.64%)
Mutual labels:  upnp
docker-airconnect
This is a dockerized version of AirConnect (https://github.com/philippe44/AirConnect) which bridges AirPlay with Sonos and the Google Cast protocol.
Stars: ✭ 24 (-38.46%)
Mutual labels:  upnp
Weupnp
A tiny UPnP (Universal Plug and Play) client library written in Java
Stars: ✭ 88 (+125.64%)
Mutual labels:  upnp
LMS-to-uPnP
Integrate UPnP players with LogitechMediaServer
Stars: ✭ 78 (+100%)
Mutual labels:  upnp
Rssdp
Really Simple Service Discovery Protocol - a 100% .Net implementation of the SSDP protocol for publishing custom/basic devices, and discovering all device types on a network.
Stars: ✭ 216 (+453.85%)
Mutual labels:  upnp
Jupii
Play audio, video and images on UPnP/DLNA devices
Stars: ✭ 27 (-30.77%)
Mutual labels:  upnp
Killcast
Manipulate Chromecast Devices in your Network
Stars: ✭ 133 (+241.03%)
Mutual labels:  upnp
Smartthingspublic
SmartThings open-source DeviceTypeHandlers and SmartApps code
Stars: ✭ 2,201 (+5543.59%)
Mutual labels:  upnp
UPnP Generic
A simple library that implements port mappings to router using UPnP SSDP for Arduino boards, running on nRF52, SAMD21/SAMD51, STM32F/L/H/G/WB/MP1, Teensy, RP2040-based boards, WT32_ETH01, Portenta_H7, etc. besides ESP8266/ESP32, using ESP WiFi, WiFiNINA, Ethernet W5x00, ESP8266/ESP32 AT-command WiFi, Portenta_H7 Murata WiFi or Vision-shield Ethe…
Stars: ✭ 14 (-64.1%)
Mutual labels:  upnp
Upnpclient
uPnP client library for Python 3.
Stars: ✭ 115 (+194.87%)
Mutual labels:  upnp
upnpy
Lightweight UPnP client library for Python.
Stars: ✭ 46 (+17.95%)
Mutual labels:  upnp
Universalmediaserver
A DLNA, UPnP and HTTP(S) Media Server.
Stars: ✭ 1,339 (+3333.33%)
Mutual labels:  upnp
nano-dlna
A minimal UPnP/DLNA media streamer
Stars: ✭ 146 (+274.36%)
Mutual labels:  upnp
Macast
Macast is a cross-platform application which using mpv as DLNA Media Renderer.
Stars: ✭ 3,786 (+9607.69%)
Mutual labels:  upnp
AirConnect-Synology
Updated AirConnect packages for Synology NAS and Synology Router
Stars: ✭ 200 (+412.82%)
Mutual labels:  upnp
Beacon
A simple UPnP Assistant that is capable of opening arbitrary ports.
Stars: ✭ 34 (-12.82%)
Mutual labels:  upnp

mmupnp

license GitHub release GitHub issues GitHub closed issues GitHub Actions codecov Maven Central

Universal Plug and Play (UPnP) ControlPoint library for Java / Kotlin.

Feature

  • Pure Kotlin implementation.
  • Available in both Java/Kotlin application and Android apps.
  • Easy to use
  • High response

Requirements

  • kotlin 1.3 or later
  • Java 7 or later

Restrictions

  • This library only provides ControlPoint. There is no way to make Device. If you need it, please select another library.

About the next version

Plan for the next version.

  • Full support for Kotlin coroutines
  • Support for ControlPoint and Device
  • Multi-module for selectable feature

Example of use

Android App

Sample App

screenshot screenshot

API Documents

I described Javadoc/KDoc comments. Please refer to it for more information.

How to use

jCenter will close in May. In 3.1.3 moved to mavenCentral from jcenter.
Please note that the groupID has changed

Download from mavenCentral. Maven Central

dependencies {
    implementation 'net.mm2d.mmupnp:mmupnp:3.1.3'
}

Versions below 3.1.3 were distributed with jCenter. However, jCenter will close and old versions are not migrated to mavenCentral. If you need an older version, please use the Github Pages repository.

repositories {
    maven { url = URI("https://ohmae.github.com/maven") }
}
dependencies {
    implementation 'net.mm2d.mmupnp:mmupnp:3.1.2'
}

Create instance

To create instance with default parameter.

val cp = ControlPointFactory.create()

ControlPointFactory.create() has many initialization parameters.

In addition, Builder is also available. Please use them according to your preference. It is convenient when using from Java.

val cp = ControlPointFactory.builder()
    .setInterfaces(interfaces)
    .setCallbackHandler { handler.post(it) }
    ....
    .build()

Initialize parameter

To specify the network interface,

val cp = ControlPointFactory.create(
    interfaces = listOf(NetworkInterface.getByName("eth0"))
)

By default, ControlPoint will work with the dual stack of IPv4 and IPv6. To operate with IPv4 only, specify the protocol,

val cp = ControlPointFactory.create(
    protocol = IP_V4_ONLY
)

You can change the callback thread. For example in Android, you may want to run callbacks with MainThread.

val cp = ControlPointFactory.create(
    callbackHandler = { handler.post(it) }
)

Or If use executor,

val cp = ControlPointFactory.create(
    callbackExecutor = object : TaskExecutor{
        private val executor = Executors.newSingleThreadExecutor()
        override fun execute(task: Runnable): Boolean {
            executor.execute(task)
        }

        override fun terminate() {
            executor.shutdownNow()
        }
    }
)

If EventSubscription is not required,

val cp = ControlPointFactory.create(
    subscriptionEnabled = false
)

The server thread for receiving events does not start and resources can be reduced.

If you want to receive multicast events,

val cp = ControlPointFactory.create(
    multicastEventingEnabled = true
)

This feature is experimental. Compatibility cannot be confirmed because no other implementation has been found.

Initialize and Start

val cp = ControlPointFactory.create().also {
    // adding listener if necessary.
    it.addDiscoveryListener(...)
    it.addNotifyEventListener(...)
    it.initialize()
    it.start()
}
...

M-SEARCH

Call ControlPoint#search() or ControlPoint#search(String).

cp.search()                  // Default ST is ssdp:all
cp.search("upnp:rootdevice") // To use specific ST. In this case "upnp:rootdevice"

These methods send one M-SEARCH packet to all interfaces.

Invoke Action

For example, to invoke "Browse" (ContentDirectory) action...

val mediaServer = cp.getDevice(UDN)           // get device by UDN
val browse = mediaServer.findAction("Browse") // find "Browse" action
browse?.invoke(
    mapOf(
        "ObjectID" to "0",
        "BrowseFlag" to "BrowseDirectChildren",
        "Filter" to "*",
        "StartingIndex" to "0",
        "RequestedCount" to "0",
        "SortCriteria" to ""
    ),
    onResult = {
        val resultXml = it.get("Result")// get result
        ...
    },
    onError = {
        // on error
        ...
    }
)

Event Subscription

For example, to subscribe ContentDirectory's events...

// add listener to receive event
addEventListener( eventListener { service, seq, properties ->
    properties.forEach {
        eventArea.text = "${eventArea.text}${service.serviceType} : $seq : ${it.first} : ${it.second}\n"
    }
})
val mediaServer = cp.getDevice(UDN)          // get device by UDN
val cds = mediaServer.findServiceById(
  "urn:upnp-org:serviceId:ContentDirectory") // find Service by ID
cds.subscribe()                              // Start subscribe
...
cds.unsubscribe()                            // End subscribe

Of course, this will not work if disabled at initialization.

Stop and Terminate

cp.stop()
cp.terminate()

It is not possible to re-initialize. When you want to reset, try again from the constructor call.

Debug log output

This library use log library,

To enable debug log.

Logger.setLogLevel(Logger.VERBOSE)
Logger.setSender(Senders.create())

In this case output to System.out

To send log to a library, eg. Simply change the output method.

Logger.setSender(DefaultSender.create({ level, tag, message ->
    message.split('\n').forEach {
        android.util.Log.println(level, tag, it)
    }
}))

eg. To handle exception

Logger.setSender { level, message, throwable ->
    if (level >= Log.DEBUG) {
        SomeLogger.send(...)
    }
}

Please see log library for more details

Log leveling

  • ERROR
    • Log indicating the possibility of a problem occurring.
  • WARN
    • Log indicating the possibility of a problem occurring, but also often output in normal operation.
  • INFO
    • Logs that may help analyze the problem, but may be output in large amounts.
  • DEBUG
    • Logs that output in normal operation for debugging.
  • VERBOSE
    • More detail logs that output in normal operation for debugging.

Dependent OSS

  • Kotlin
    • org.jetbrains.kotlin:kotlin-stdlib-jdk7
  • log
    • net.mm2d.log:log

Special thanks

This project is being developed with IntelliJ IDEA Ultimate, thanks to be approved to Jetbrains Free Open Source Licenses.

jetbrans logo

Author

倧前 θ‰―δ»‹ (OHMAE Ryosuke) http://www.mm2d.net/

License

MIT License

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].