Jump to content

Locating Server with Java API


kingargyle

Recommended Posts

kingargyle

I have seen some posts on using a UDP broadcast message to have any servers on the network send back a response, but I was wondering if there is a way to do this through the API natively.   I have tried the following with Kotlin on Android, but the onResponse never seems to get called.

    val logger: ILogger = NullLogger()
    val jsonSerializer: IJsonSerializer = GsonJsonSerializer()
    val device: IDevice = AndroidDevice(context)
    val capabilities: ClientCapabilities = ClientCapabilities()
    val apiListener: ApiEventListener = ApiEventListener()
    val httpClient: IAsyncHttpClient = VolleyHttpClient(logger, context)

    val connectionManager: IConnectionManager = AndroidConnectionManager(context, jsonSerializer, logger, httpClient,
        "Serenity for Android", "2.x", device, capabilities, apiListener)

    connectionManager.GetAvailableServers(object : Response<ArrayList<ServerInfo>>() {

      override fun onResponse(response: ArrayList<ServerInfo>) {
        response.forEach { serverInfo: ServerInfo ->
          val embyServer: EmbyServer = EmbyServer()
          embyServer.serverName = serverInfo.name
          embyServer.ipAddress = serverInfo.remoteAddress

          eventBus.post(embyServer)
        }
      }
    })

My Emby server is up and running as the Web app works as well as the official Emby app for Android.  Is the UDP method the preferred way to get any servers on the network?

 

 

Link to comment
Share on other sites

kingargyle

Stepping through the code it looks like the foundServers arraylist does get populated, but the tempCredentials access toke returns null, so nothing gets returned.  So it looks like it can be done but unless there is another way, I'll have to cobble something together myself with my own ConnectionManager that extends the AndroidConnectionManager.

Link to comment
Share on other sites

Thanks for stepping into it. Can you elaborate a little bit more? It's not assumed at that point that you would have an access token so that shouldn't be a problem.

Link to comment
Share on other sites

kingargyle

Thanks for stepping into it. Can you elaborate a little bit more? It's not assumed at that point that you would have an access token so that shouldn't be a problem.

 

@@ebr The problem seems to be in the ConnectionManager.  In particular around line 542.  It checks to see if the tempCredentials.getConnectAccessToken() is not Null.   At this point since I haven't connected with an actual user, I would expect the token to be null.  Because of this, it moves onto the error condition.  It appears to only be expecting to return the list of severs if there is a valid user logged in.

 

https://github.com/MediaBrowser/Emby.ApiClient.Java/blob/master/android/src/main/java/mediabrowser/apiinteraction/connectionmanager/ConnectionManager.java#L542

 

I ended up creating a new method, that does everything GetAvailableServers does up to the point that it checks for the credentials, and just return a List of ServerInfo objects it found earlier, this at least lets me get the list.   The Response<ArrayList<ServerInfo>> almost seems unnecessary but I haven't tried passing in a no op version of this or just the default to see if it ever gets called anywhere.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...