mirror of
https://github.com/jellyfin/jellyfin-sdk-kotlin.git
synced 2025-03-02 04:57:30 +00:00
improve startup time
This commit is contained in:
parent
e1799204ab
commit
62cb177ebd
22
LICENSE.md
Normal file
22
LICENSE.md
Normal file
@ -0,0 +1,22 @@
|
||||
The MIT License
|
||||
|
||||
Copyright (c) Media Browser http://mediabrowser.tv
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
Binary file not shown.
Binary file not shown.
@ -1139,11 +1139,6 @@ public class ApiClient extends BaseApiClient {
|
||||
}
|
||||
|
||||
Logger.Debug("ReportPlaybackStart: Item {0}", info.getItem());
|
||||
|
||||
/*if (WebSocketConnection != null && WebSocketConnection.IsConnected)
|
||||
{
|
||||
return WebSocketConnection.SendAsync("ReportPlaybackStart", JsonSerializer.SerializeToString(info));
|
||||
}*/
|
||||
|
||||
String url = GetApiUrl("Sessions/Playing");
|
||||
|
||||
@ -1162,11 +1157,6 @@ public class ApiClient extends BaseApiClient {
|
||||
{
|
||||
throw new IllegalArgumentException("info");
|
||||
}
|
||||
|
||||
/*if (WebSocketConnection != null && WebSocketConnection.IsConnected)
|
||||
{
|
||||
return WebSocketConnection.SendAsync("ReportPlaybackProgress", JsonSerializer.SerializeToString(info));
|
||||
}*/
|
||||
|
||||
if (apiWebSocket != null && apiWebSocket.IsWebSocketOpen()){
|
||||
apiWebSocket.SendWebSocketMessage("ReportPlaybackProgress", info, response);
|
||||
@ -1189,11 +1179,6 @@ public class ApiClient extends BaseApiClient {
|
||||
{
|
||||
throw new IllegalArgumentException("info");
|
||||
}
|
||||
|
||||
/*if (WebSocketConnection != null && WebSocketConnection.IsConnected)
|
||||
{
|
||||
return WebSocketConnection.SendAsync("ReportPlaybackStopped", JsonSerializer.SerializeToString(info));
|
||||
}*/
|
||||
|
||||
String url = GetApiUrl("Sessions/Playing/Stopped");
|
||||
|
||||
|
@ -134,18 +134,10 @@ public class ConnectionManager implements IConnectionManager {
|
||||
|
||||
logger.Debug("Entering initial connection workflow");
|
||||
|
||||
GetAvailableServers(new Response<ArrayList<ServerInfo>>(){
|
||||
|
||||
@Override
|
||||
public void onResponse(ArrayList<ServerInfo> servers) {
|
||||
|
||||
logger.Debug("Looping through server list");
|
||||
Connect(servers, response);
|
||||
}
|
||||
});
|
||||
GetAvailableServers(new GetAvailableServersResponse(logger, this, response));
|
||||
}
|
||||
|
||||
private void Connect(ArrayList<ServerInfo> servers, final Response<ConnectionResult> response){
|
||||
void Connect(final ArrayList<ServerInfo> servers, final Response<ConnectionResult> response){
|
||||
|
||||
// Sort by last date accessed, descending
|
||||
Collections.sort(servers, new ServerInfoDateComparator());
|
||||
@ -172,59 +164,26 @@ public class ConnectionManager implements IConnectionManager {
|
||||
return;
|
||||
}
|
||||
|
||||
ConnectToServerAtListIndex(servers, 0, response);
|
||||
}
|
||||
// Check the first server for a saved access token
|
||||
ServerInfo firstServer = servers.get(0);
|
||||
if (tangible.DotNetToJavaStringHelper.isNullOrEmpty(firstServer.getAccessToken()))
|
||||
{
|
||||
OnFailedConnection(response, servers);
|
||||
return;
|
||||
}
|
||||
|
||||
private void ConnectToServerAtListIndex(final ArrayList<ServerInfo> servers,
|
||||
final int index,
|
||||
final Response<ConnectionResult> response){
|
||||
|
||||
Response<ConnectionResult> innerResponse = new Response<ConnectionResult>(){
|
||||
|
||||
private void TryNextServer() {
|
||||
|
||||
int nextIndex = index + 1;
|
||||
if (nextIndex < servers.size()) {
|
||||
|
||||
logger.Debug("Trying next server");
|
||||
ConnectToServerAtListIndex(servers, nextIndex, response);
|
||||
|
||||
} else {
|
||||
|
||||
// No connection is available
|
||||
OnFailedConnection(response, servers);
|
||||
}
|
||||
}
|
||||
Connect(firstServer, new Response<ConnectionResult>() {
|
||||
|
||||
@Override
|
||||
public void onResponse(ConnectionResult result) {
|
||||
|
||||
if (result.getState() == ConnectionState.SignedIn) {
|
||||
logger.Debug("Connected to server");
|
||||
response.onResponse(result);
|
||||
|
||||
} else {
|
||||
TryNextServer();
|
||||
OnFailedConnection(response, servers);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Exception ex) {
|
||||
|
||||
TryNextServer();
|
||||
}
|
||||
};
|
||||
|
||||
ServerInfo server = servers.get(index);
|
||||
|
||||
// Try to connect if there's a saved access token
|
||||
if (!tangible.DotNetToJavaStringHelper.isNullOrEmpty(server.getAccessToken()))
|
||||
{
|
||||
Connect(server, true, innerResponse);
|
||||
}
|
||||
else{
|
||||
innerResponse.onError(null);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -0,0 +1,28 @@
|
||||
package mediabrowser.apiinteraction.connectionmanager;
|
||||
|
||||
import mediabrowser.apiinteraction.ConnectionResult;
|
||||
import mediabrowser.apiinteraction.Response;
|
||||
import mediabrowser.model.apiclient.ServerInfo;
|
||||
import mediabrowser.model.logging.ILogger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class GetAvailableServersResponse extends Response<ArrayList<ServerInfo>> {
|
||||
|
||||
private ILogger logger;
|
||||
private ConnectionManager connectionManager;
|
||||
private Response<ConnectionResult> response;
|
||||
|
||||
public GetAvailableServersResponse(ILogger logger, ConnectionManager connectionManager, Response<ConnectionResult> response) {
|
||||
this.logger = logger;
|
||||
this.connectionManager = connectionManager;
|
||||
this.response = response;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResponse(ArrayList<ServerInfo> servers) {
|
||||
|
||||
logger.Debug("Looping through server list");
|
||||
connectionManager.Connect(servers, response);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user