Jump to content

ApiClient changes


Luke

Recommended Posts

@@7illusions

@@Aphid

@@Armand

@

@@ScottIsAFool

@@jitterjames

 

Documentation:

 

https://github.com/MediaBrowser/MediaBrowser.ApiClient

 

 

In order to prepare for multi-server connectivity, I've updated ApiClient with a new ConnectionManager class. Before we get to that, you can upgrade the library with full compatibility by making the following changes:

 

  1. Adjust constructor params (see github wiki. fewer params now).
  2. Change HttpResponseReceived event to RemoteLoggedOut. This is a friendlier overload to indicate your session was logged out remotely by the server.

Everyone should do this just to start with. jitterjames, and nullpointer, this is possibly all you will need to do.

 

 

Connection Manager

 

Instead of creating an ApiClient instance at your application's entry point, you will instead want to create a ConnectionManager. I've written it all up on the wiki so I'm not going to rehash it all here, but suffice to say, all you need to do is call ConnectionManager.Connect, and that will create your ApiClient instance for you. It will also return a State value indicidating the result:

 

  • Unavailable (user has to enter connection info manually)
  • ServerSignIn (connected to server but user needs to login)
  • SignedIn (connected, signed in, and ready to browse using previously saved credentials)

 

Connection Manager Features:

 

  • Automatic opening & closing of web sockets at appropriate times
  • Automatic saving and validation of credentials
  • Server discovery
  • Wake on lan
  • Automatic LAN/WAN fallback (this will need testing)

 

Note: The model has interfaces - IApiClient, IConnectionManager, and others in case you want to shield these dependencies from certain areas of your apps.

Link to comment
Share on other sites

Aphid - I have handled this for MBT, but I imagine you'll have to do it separately for your branch as well.

Link to comment
Share on other sites

Aphid

The logic for showing the login screen might differ a little, but otherwise I expect whatever you implement will apply to both branches.

Link to comment
Share on other sites

Definitely. But if you look at the last paragraph on the wiki page, that is the hard part. It's not a requirement that every app do that just yet, so you can certainly wait if you need to. But I figured I'd move ahead with MBT so that I can hash it out.

Link to comment
Share on other sites

Armand

for some reason i'm getting the following error, after implementing the connection manager logic.

Right after I call ConnectionManager.Connect(CancellationToken.None). 

[10-08 01:01:26,419] [21          ] [DEBUG] GET http://192.168.0.1:8096/mediabrowser/system/info/public?format=json
[10-08 01:01:26,555] [21          ] [DEBUG] Received 200 status code after 132.0067 ms from GET: http://192.168.0.1:8096/mediabrowser/system/info/public?format=json
[10-08 01:01:26,614] [21          ] [ERROR] System.NullReferenceException: Object reference not set to an instance of an object.
   at MediaBrowser.ApiInteraction.ConnectionManager.<TryConnect>d__33.MoveNext()
[10-08 01:01:26,619] [21          ] [ERROR] Error getting response from http://192.168.0.1:8096/mediabrowser/system/info/public?format=json

I'm currently tracking down the issue but myabe you have an idea of what is going wrong.

Link to comment
Share on other sites

make sure you're on the latest version of the package because 7 spotted a similar issue that was fixed. if you are then let me know and i'll look again.

Link to comment
Share on other sites

Armand

after the update the problem shifted to my code.. probably some async issue now on my side ;)

Link to comment
Share on other sites

Armand

Looks like ConnectionResult.ServerInfo is null when ConnectionResult.State = ConnectionState.ServerSignIn

Link to comment
Share on other sites

Based on some feedback from 7, there's a minor adjustment:

 

The State property now has ServerSelection, which means multiple servers are available and the user should be given a selection. The ServerInfo property has been changed to a list. For all the other state values it will either have 1 or 0 entries.

Link to comment
Share on other sites

There's another update up.

 

There's a new ICryptographyProvider that you have to supply as a dependency. An implementation is included for the full .net 4.5 version, but those using the PCL version will have to implement it.

 

The sample on the github wiki has been updated.

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...