Verified Commit 3f489848 authored by Jonas L.'s avatar Jonas L.

Add dummy content server detection for the emulator

parent 95d00966
......@@ -62,6 +62,34 @@ object ServerDiscovery {
client = SsdpClient.create()
fun handleServer(newServer: DiscoveredLocalNetworkServer) {
if (BuildConfig.DEBUG) {
Log.d(LOG_TAG, "onServiceDiscovered($newServer)")
}
val currentData = value
val newData = ArrayList<DiscoveredLocalNetworkServer>()
var hadReplaced = false
if (currentData != null) {
for (entry in currentData) {
if (TextUtils.equals(entry.location, newServer.location)) {
hadReplaced = true
newData.add(newServer)
} else {
newData.add(entry)
}
}
}
if (!hadReplaced) {
newData.add(newServer)
}
value = Collections.unmodifiableList(newData)
}
client!!.discoverServices(
SsdpRequest.discover()
.serviceType("urn:determapp-de:service:ViewerServer")
......@@ -69,36 +97,12 @@ object ServerDiscovery {
object : DiscoveryListener {
override fun onServiceDiscovered(service: SsdpService) {
handler.post {
val newServer = DiscoveredLocalNetworkServer(
service.location,
now()
handleServer(
DiscoveredLocalNetworkServer(
service.location,
now()
)
)
if (BuildConfig.DEBUG) {
Log.d(LOG_TAG, "onServiceDiscovered($newServer)")
}
val currentData = value
val newData = ArrayList<DiscoveredLocalNetworkServer>()
var hadReplaced = false
if (currentData != null) {
for (entry in currentData) {
if (TextUtils.equals(entry.location, newServer.location)) {
hadReplaced = true
newData.add(newServer)
} else {
newData.add(entry)
}
}
}
if (!hadReplaced) {
newData.add(newServer)
}
value = Collections.unmodifiableList(newData)
}
}
......@@ -116,6 +120,19 @@ object ServerDiscovery {
}
)
// "discovery" for the Android Emulator
// tries to use port 8081 on the host
if (BuildConfig.DEBUG) {
handler.post {
handleServer(
DiscoveredLocalNetworkServer(
"http://10.0.2.2:8081",
now()
)
)
}
}
handler.postDelayed(this, QUERY_INTERVAL.toLong())
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment