mirror of
https://gitlab.futo.org/videostreaming/grayjay.git
synced 2025-09-08 18:46:08 +00:00
Fix for throttled networks (airplane wifi) freezing app opening downloaded content.
This commit is contained in:
parent
1aa9adc899
commit
1ecd1f5e04
5 changed files with 31 additions and 18 deletions
|
@ -14,14 +14,16 @@ class PlatformClientPool {
|
||||||
private var _poolCounter = 0;
|
private var _poolCounter = 0;
|
||||||
private val _poolName: String?;
|
private val _poolName: String?;
|
||||||
private val _privatePool: Boolean;
|
private val _privatePool: Boolean;
|
||||||
|
private val _isolatedInitialization: Boolean
|
||||||
|
|
||||||
var isDead: Boolean = false
|
var isDead: Boolean = false
|
||||||
private set;
|
private set;
|
||||||
val onDead = Event2<JSClient, PlatformClientPool>();
|
val onDead = Event2<JSClient, PlatformClientPool>();
|
||||||
|
|
||||||
constructor(parentClient: IPlatformClient, name: String? = null, privatePool: Boolean = false) {
|
constructor(parentClient: IPlatformClient, name: String? = null, privatePool: Boolean = false, isolatedInitialization: Boolean = false) {
|
||||||
_poolName = name;
|
_poolName = name;
|
||||||
_privatePool = privatePool;
|
_privatePool = privatePool;
|
||||||
|
_isolatedInitialization = isolatedInitialization
|
||||||
if(parentClient !is JSClient)
|
if(parentClient !is JSClient)
|
||||||
throw IllegalArgumentException("Pooling only supported for JSClients right now");
|
throw IllegalArgumentException("Pooling only supported for JSClients right now");
|
||||||
Logger.i(TAG, "Pool for ${parentClient.name} was started");
|
Logger.i(TAG, "Pool for ${parentClient.name} was started");
|
||||||
|
@ -53,7 +55,7 @@ class PlatformClientPool {
|
||||||
reserved = _pool.keys.find { !it.isBusy };
|
reserved = _pool.keys.find { !it.isBusy };
|
||||||
if(reserved == null && _pool.size < capacity) {
|
if(reserved == null && _pool.size < capacity) {
|
||||||
Logger.i(TAG, "Started additional [${_parent.name}] client in pool [${_poolName}] (${_pool.size + 1}/${capacity})");
|
Logger.i(TAG, "Started additional [${_parent.name}] client in pool [${_poolName}] (${_pool.size + 1}/${capacity})");
|
||||||
reserved = _parent.getCopy(_privatePool);
|
reserved = _parent.getCopy(_privatePool, _isolatedInitialization);
|
||||||
|
|
||||||
reserved?.onCaptchaException?.subscribe { client, ex ->
|
reserved?.onCaptchaException?.subscribe { client, ex ->
|
||||||
StateApp.instance.handleCaptchaException(client, ex);
|
StateApp.instance.handleCaptchaException(client, ex);
|
||||||
|
|
|
@ -7,13 +7,15 @@ class PlatformMultiClientPool {
|
||||||
|
|
||||||
private var _isFake = false;
|
private var _isFake = false;
|
||||||
private var _privatePool = false;
|
private var _privatePool = false;
|
||||||
|
private val _isolatedInitialization: Boolean
|
||||||
|
|
||||||
constructor(name: String, maxCap: Int = -1, isPrivatePool: Boolean = false) {
|
constructor(name: String, maxCap: Int = -1, isPrivatePool: Boolean = false, isolatedInitialization: Boolean = false) {
|
||||||
_name = name;
|
_name = name;
|
||||||
_maxCap = if(maxCap > 0)
|
_maxCap = if(maxCap > 0)
|
||||||
maxCap
|
maxCap
|
||||||
else 99;
|
else 99;
|
||||||
_privatePool = isPrivatePool;
|
_privatePool = isPrivatePool;
|
||||||
|
_isolatedInitialization = isolatedInitialization
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getClientPooled(parentClient: IPlatformClient, capacity: Int = _maxCap): IPlatformClient {
|
fun getClientPooled(parentClient: IPlatformClient, capacity: Int = _maxCap): IPlatformClient {
|
||||||
|
@ -21,7 +23,7 @@ class PlatformMultiClientPool {
|
||||||
return parentClient;
|
return parentClient;
|
||||||
val pool = synchronized(_clientPools) {
|
val pool = synchronized(_clientPools) {
|
||||||
if(!_clientPools.containsKey(parentClient))
|
if(!_clientPools.containsKey(parentClient))
|
||||||
_clientPools[parentClient] = PlatformClientPool(parentClient, _name, _privatePool).apply {
|
_clientPools[parentClient] = PlatformClientPool(parentClient, _name, _privatePool, _isolatedInitialization).apply {
|
||||||
this.onDead.subscribe { _, pool ->
|
this.onDead.subscribe { _, pool ->
|
||||||
synchronized(_clientPools) {
|
synchronized(_clientPools) {
|
||||||
if(_clientPools[parentClient] == pool)
|
if(_clientPools[parentClient] == pool)
|
||||||
|
|
|
@ -54,8 +54,11 @@ class DevJSClient : JSClient {
|
||||||
return DevJSClient(context, config, _devScript, _auth, _captcha, devID, descriptor.settings);
|
return DevJSClient(context, config, _devScript, _auth, _captcha, devID, descriptor.settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getCopy(privateCopy: Boolean): JSClient {
|
override fun getCopy(privateCopy: Boolean, noSaveState: Boolean): JSClient {
|
||||||
return DevJSClient(_context, descriptor, _script, if(!privateCopy) _auth else null, _captcha, saveState(), devID);
|
val client = DevJSClient(_context, descriptor, _script, if(!privateCopy) _auth else null, _captcha, if (noSaveState) null else saveState(), devID);
|
||||||
|
if (noSaveState)
|
||||||
|
client.initialize()
|
||||||
|
return client
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun initialize() {
|
override fun initialize() {
|
||||||
|
|
|
@ -195,8 +195,11 @@ open class JSClient : IPlatformClient {
|
||||||
_plugin.changeAllowDevSubmit(descriptor.appSettings.allowDeveloperSubmit);
|
_plugin.changeAllowDevSubmit(descriptor.appSettings.allowDeveloperSubmit);
|
||||||
}
|
}
|
||||||
|
|
||||||
open fun getCopy(withoutCredentials: Boolean = false): JSClient {
|
open fun getCopy(withoutCredentials: Boolean = false, noSaveState: Boolean = false): JSClient {
|
||||||
return JSClient(_context, descriptor, saveState(), _script, withoutCredentials);
|
val client = JSClient(_context, descriptor, if (noSaveState) null else saveState(), _script, withoutCredentials);
|
||||||
|
if (noSaveState)
|
||||||
|
client.initialize()
|
||||||
|
return client
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getUnderlyingPlugin(): V8Plugin {
|
fun getUnderlyingPlugin(): V8Plugin {
|
||||||
|
@ -211,6 +214,8 @@ open class JSClient : IPlatformClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun initialize() {
|
override fun initialize() {
|
||||||
|
if (_initialized) return
|
||||||
|
|
||||||
Logger.i(TAG, "Plugin [${config.name}] initializing");
|
Logger.i(TAG, "Plugin [${config.name}] initializing");
|
||||||
plugin.start();
|
plugin.start();
|
||||||
plugin.execute("plugin.config = ${Json.encodeToString(config)}");
|
plugin.execute("plugin.config = ${Json.encodeToString(config)}");
|
||||||
|
|
|
@ -94,6 +94,7 @@ class StatePlatform {
|
||||||
private val _trackerClientPool = PlatformMultiClientPool("Trackers", 1); //Used exclusively for playback trackers
|
private val _trackerClientPool = PlatformMultiClientPool("Trackers", 1); //Used exclusively for playback trackers
|
||||||
private val _liveEventClientPool = PlatformMultiClientPool("LiveEvents", 1); //Used exclusively for live events
|
private val _liveEventClientPool = PlatformMultiClientPool("LiveEvents", 1); //Used exclusively for live events
|
||||||
private val _privateClientPool = PlatformMultiClientPool("Private", 2, true); //Used primarily for calls if in incognito mode
|
private val _privateClientPool = PlatformMultiClientPool("Private", 2, true); //Used primarily for calls if in incognito mode
|
||||||
|
private val _instantClientPool = PlatformMultiClientPool("Instant", 1, false, true); //Used for all instant calls
|
||||||
|
|
||||||
|
|
||||||
private val _icons : HashMap<String, ImageVariable> = HashMap();
|
private val _icons : HashMap<String, ImageVariable> = HashMap();
|
||||||
|
@ -114,14 +115,14 @@ class StatePlatform {
|
||||||
|
|
||||||
Logger.i(StatePlatform::class.java.name, "Fetching video details [${url}]");
|
Logger.i(StatePlatform::class.java.name, "Fetching video details [${url}]");
|
||||||
if(!StateApp.instance.privateMode) {
|
if(!StateApp.instance.privateMode) {
|
||||||
_enabledClients.find { it.isContentDetailsUrl(url) }?.let {
|
_enabledClients.find { _instantClientPool.getClientPooled(it).isContentDetailsUrl(url) }?.let {
|
||||||
_mainClientPool.getClientPooled(it).getContentDetails(url)
|
_mainClientPool.getClientPooled(it).getContentDetails(url)
|
||||||
}
|
}
|
||||||
?: throw NoPlatformClientException("No client enabled that supports this url ($url)");
|
?: throw NoPlatformClientException("No client enabled that supports this url ($url)");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Logger.i(TAG, "Fetching details with private client");
|
Logger.i(TAG, "Fetching details with private client");
|
||||||
_enabledClients.find { it.isContentDetailsUrl(url) }?.let {
|
_enabledClients.find { _instantClientPool.getClientPooled(it).isContentDetailsUrl(url) }?.let {
|
||||||
_privateClientPool.getClientPooled(it).getContentDetails(url)
|
_privateClientPool.getClientPooled(it).getContentDetails(url)
|
||||||
}
|
}
|
||||||
?: throw NoPlatformClientException("No client enabled that supports this url ($url)");
|
?: throw NoPlatformClientException("No client enabled that supports this url ($url)");
|
||||||
|
@ -668,10 +669,10 @@ class StatePlatform {
|
||||||
|
|
||||||
|
|
||||||
//Video
|
//Video
|
||||||
fun hasEnabledVideoClient(url: String) : Boolean = getEnabledClients().any { it.isContentDetailsUrl(url) };
|
fun hasEnabledVideoClient(url: String) : Boolean = getEnabledClients().any { _instantClientPool.getClientPooled(it).isContentDetailsUrl(url) };
|
||||||
fun getContentClient(url: String) : IPlatformClient = getContentClientOrNull(url)
|
fun getContentClient(url: String) : IPlatformClient = getContentClientOrNull(url)
|
||||||
?: throw NoPlatformClientException("No client enabled that supports this content url (${url})");
|
?: throw NoPlatformClientException("No client enabled that supports this content url (${url})");
|
||||||
fun getContentClientOrNull(url: String) : IPlatformClient? = getEnabledClients().find { it.isContentDetailsUrl(url) };
|
fun getContentClientOrNull(url: String) : IPlatformClient? = getEnabledClients().find { _instantClientPool.getClientPooled(it).isContentDetailsUrl(url) };
|
||||||
fun getContentDetails(url: String, forceRefetch: Boolean = false): Deferred<IPlatformContentDetails> {
|
fun getContentDetails(url: String, forceRefetch: Boolean = false): Deferred<IPlatformContentDetails> {
|
||||||
Logger.i(TAG, "Platform - getContentDetails (${url})");
|
Logger.i(TAG, "Platform - getContentDetails (${url})");
|
||||||
if(forceRefetch)
|
if(forceRefetch)
|
||||||
|
@ -712,14 +713,14 @@ class StatePlatform {
|
||||||
return client.getContentRecommendations(url);
|
return client.getContentRecommendations(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
fun hasEnabledChannelClient(url : String) : Boolean = getEnabledClients().any { it.isChannelUrl(url) };
|
fun hasEnabledChannelClient(url : String) : Boolean = getEnabledClients().any { _instantClientPool.getClientPooled(it).isChannelUrl(url) };
|
||||||
fun getChannelClient(url : String, exclude: List<String>? = null) : IPlatformClient = getChannelClientOrNull(url, exclude)
|
fun getChannelClient(url : String, exclude: List<String>? = null) : IPlatformClient = getChannelClientOrNull(url, exclude)
|
||||||
?: throw NoPlatformClientException("No client enabled that supports this channel url (${url})");
|
?: throw NoPlatformClientException("No client enabled that supports this channel url (${url})");
|
||||||
fun getChannelClientOrNull(url : String, exclude: List<String>? = null) : IPlatformClient? =
|
fun getChannelClientOrNull(url : String, exclude: List<String>? = null) : IPlatformClient? =
|
||||||
if(exclude == null)
|
if(exclude == null)
|
||||||
getEnabledClients().find { it.isChannelUrl(url) }
|
getEnabledClients().find { _instantClientPool.getClientPooled(it).isChannelUrl(url) }
|
||||||
else
|
else
|
||||||
getEnabledClients().find { !exclude.contains(it.id) && it.isChannelUrl(url) };
|
getEnabledClients().find { !exclude.contains(it.id) && _instantClientPool.getClientPooled(it).isChannelUrl(url) };
|
||||||
|
|
||||||
fun getChannel(url: String, updateSubscriptions: Boolean = true): Deferred<IPlatformChannel> {
|
fun getChannel(url: String, updateSubscriptions: Boolean = true): Deferred<IPlatformChannel> {
|
||||||
Logger.i(TAG, "Platform - getChannel");
|
Logger.i(TAG, "Platform - getChannel");
|
||||||
|
@ -906,9 +907,9 @@ class StatePlatform {
|
||||||
return urls;
|
return urls;
|
||||||
}
|
}
|
||||||
|
|
||||||
fun hasEnabledPlaylistClient(url: String) : Boolean = getEnabledClients().any { it.isPlaylistUrl(url) };
|
fun hasEnabledPlaylistClient(url: String) : Boolean = getEnabledClients().any { _instantClientPool.getClientPooled(it).isPlaylistUrl(url) };
|
||||||
fun getPlaylistClientOrNull(url: String): IPlatformClient? = getEnabledClients().find { it.isPlaylistUrl(url) }
|
fun getPlaylistClientOrNull(url: String): IPlatformClient? = getEnabledClients().find { _instantClientPool.getClientPooled(it).isPlaylistUrl(url) }
|
||||||
fun getPlaylistClient(url: String): IPlatformClient = getEnabledClients().find { it.isPlaylistUrl(url) }
|
fun getPlaylistClient(url: String): IPlatformClient = getEnabledClients().find { _instantClientPool.getClientPooled(it).isPlaylistUrl(url) }
|
||||||
?: throw NoPlatformClientException("No client enabled that supports this playlist url (${url})");
|
?: throw NoPlatformClientException("No client enabled that supports this playlist url (${url})");
|
||||||
fun getPlaylist(url: String): IPlatformPlaylistDetails {
|
fun getPlaylist(url: String): IPlatformPlaylistDetails {
|
||||||
return getPlaylistClient(url).getPlaylist(url);
|
return getPlaylistClient(url).getPlaylist(url);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue