Skip to content

Commit

Permalink
👍accept "ill-behaved" devices
Browse files Browse the repository at this point in the history
  • Loading branch information
ohmae committed Apr 21, 2022
1 parent 26c7e6e commit 29df3aa
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ import javax.xml.parsers.ParserConfigurationException
* @author [大前良介 (OHMAE Ryosuke)](mailto:ryo@mm2d.net)
*/
internal object ServiceParser {
private val deviceTypesThatAllowIoException = setOf(
// Some DIAL devices return XML, so try the download.
// But some DIAL devices return 404, so allow it.
"urn:dial-multiscreen-org:device:dial:1",
// Basic devices are allowed to have no Service.
// However, some devices have a Service but return 404, so allow it.
"urn:schemas-upnp-org:device:Basic:1",
)

/**
* Download Description from SCPDURL and parse it.
*
Expand All @@ -49,11 +58,10 @@ internal object ServiceParser {
val description = try {
client.downloadString(url)
} catch (e: IOException) {
if (deviceBuilder.getDeviceType() != "urn:dial-multiscreen-org:device:dial:1") {
if (deviceTypesThatAllowIoException.contains(deviceBuilder.getDeviceType())) {
throw e
}
// Some DIAL devices return XML, so try the download.
// But some DIAL devices return 404, so ignore them.
// Allow certain "ill-behaved" devices
""
}
if (description.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class DeviceHolderTest {
holder.run()
}

@Test(timeout = 20000L)
@Test(timeout = 30000L)
fun expireDevice_時間経過後に削除される() {
val expireListener: (Device) -> Unit = mockk(relaxed = true)
val holder = DeviceHolder(taskExecutors, expireListener)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ class SubscribeServiceHolderTest {
subscribeHolder.stop()
}

@Test(timeout = 10000L)
@Test(timeout = 30000L)
fun renew_失敗したら削除される() {
val id = "id"
val service: Service = mockk(relaxed = true)
Expand Down

0 comments on commit 29df3aa

Please sign in to comment.