mirror of
https://gitlab.futo.org/videostreaming/grayjay.git
synced 2025-08-27 12:46:12 +00:00
Locking of most known v8 interactions, fix returning previously returned jvm objects, Related fixes
This commit is contained in:
parent
58c9aeb1a2
commit
2fca7e9a01
12 changed files with 274 additions and 143 deletions
|
@ -99,10 +99,8 @@ open class JSClient : IPlatformClient {
|
|||
override val icon: ImageVariable;
|
||||
override var capabilities: PlatformClientCapabilities = PlatformClientCapabilities();
|
||||
|
||||
private val _busyLock = Object();
|
||||
private var _busyCounter = 0;
|
||||
private var _busyAction = "";
|
||||
val isBusy: Boolean get() = _busyCounter > 0;
|
||||
val isBusy: Boolean get() = _plugin.isBusy;
|
||||
val isBusyAction: String get() {
|
||||
return _busyAction;
|
||||
}
|
||||
|
@ -225,9 +223,12 @@ open class JSClient : IPlatformClient {
|
|||
|
||||
Logger.i(TAG, "Plugin [${config.name}] initializing");
|
||||
plugin.start();
|
||||
Logger.i(TAG, "Plugin [${config.name}] started");
|
||||
plugin.execute("plugin.config = ${Json.encodeToString(config)}");
|
||||
plugin.execute("plugin.settings = parseSettings(${Json.encodeToString(descriptor.getSettingsWithDefaults())})");
|
||||
|
||||
Logger.i(TAG, "Plugin [${config.name}] configs set");
|
||||
|
||||
descriptor.appSettings.loadDefaults(descriptor.config);
|
||||
|
||||
_initialized = true;
|
||||
|
@ -254,6 +255,7 @@ open class JSClient : IPlatformClient {
|
|||
hasGetChannelPlaylists = plugin.executeBoolean("!!source.getChannelPlaylists") ?: false,
|
||||
hasGetContentRecommendations = plugin.executeBoolean("!!source.getContentRecommendations") ?: false
|
||||
);
|
||||
Logger.i(TAG, "Plugin [${config.name}] capabilities retrieved");
|
||||
|
||||
try {
|
||||
if (capabilities.hasGetChannelTemplateByClaimMap)
|
||||
|
@ -565,7 +567,7 @@ open class JSClient : IPlatformClient {
|
|||
Logger.i(TAG, "JSClient.getPlaybackTracker(${url})");
|
||||
val tracker = plugin.executeTyped<V8Value>("source.getPlaybackTracker(${Json.encodeToString(url)})");
|
||||
if(tracker is V8ValueObject)
|
||||
return@isBusyWith JSPlaybackTracker(config, tracker);
|
||||
return@isBusyWith JSPlaybackTracker(this, tracker);
|
||||
else
|
||||
return@isBusyWith null;
|
||||
}
|
||||
|
@ -747,25 +749,23 @@ open class JSClient : IPlatformClient {
|
|||
return urls;
|
||||
}
|
||||
|
||||
|
||||
fun <T> busy(handle: ()->T): T {
|
||||
return _plugin.busy {
|
||||
return@busy handle();
|
||||
}
|
||||
}
|
||||
|
||||
fun <T> isBusyWith(actionName: String, handle: ()->T): T {
|
||||
val busyId = kotlin.random.Random.nextInt(9999);
|
||||
//val busyId = kotlin.random.Random.nextInt(9999);
|
||||
return busy {
|
||||
try {
|
||||
|
||||
Logger.v(TAG, "Busy with [${actionName}] (${busyId})")
|
||||
synchronized(_busyLock) {
|
||||
_busyCounter++;
|
||||
}
|
||||
_busyAction = actionName;
|
||||
return handle();
|
||||
return@busy handle();
|
||||
|
||||
}
|
||||
finally {
|
||||
_busyAction = "";
|
||||
synchronized(_busyLock) {
|
||||
_busyCounter--;
|
||||
}
|
||||
Logger.v(TAG, "Busy done [${actionName}] (${busyId})")
|
||||
}
|
||||
}
|
||||
private fun <T> isBusyWith(handle: ()->T): T {
|
||||
|
|
|
@ -29,7 +29,9 @@ abstract class JSPager<T> : IPager<T> {
|
|||
this.pager = pager;
|
||||
this.config = config;
|
||||
|
||||
plugin.busy {
|
||||
_hasMorePages = pager.getOrDefault(config, "hasMore", "Pager", false) ?: false;
|
||||
}
|
||||
getResults();
|
||||
}
|
||||
|
||||
|
@ -44,11 +46,14 @@ abstract class JSPager<T> : IPager<T> {
|
|||
override fun nextPage() {
|
||||
warnIfMainThread("JSPager.nextPage");
|
||||
|
||||
pager = plugin.getUnderlyingPlugin().catchScriptErrors("[${plugin.config.name}] JSPager", "pager.nextPage()") {
|
||||
val pluginV8 = plugin.getUnderlyingPlugin();
|
||||
pluginV8.busy {
|
||||
pager = pluginV8.catchScriptErrors("[${plugin.config.name}] JSPager", "pager.nextPage()") {
|
||||
pager.invoke("nextPage", arrayOf<Any>());
|
||||
};
|
||||
_hasMorePages = pager.getOrDefault(config, "hasMore", "Pager", false) ?: false;
|
||||
_resultChanged = true;
|
||||
}
|
||||
/*
|
||||
try {
|
||||
}
|
||||
|
@ -70,6 +75,8 @@ abstract class JSPager<T> : IPager<T> {
|
|||
return previousResults;
|
||||
|
||||
warnIfMainThread("JSPager.getResults");
|
||||
|
||||
return plugin.getUnderlyingPlugin().busy {
|
||||
val items = pager.getOrThrow<V8ValueArray>(config, "results", "JSPager");
|
||||
if (items.v8Runtime.isDead || items.v8Runtime.isClosed)
|
||||
throw IllegalStateException("Runtime closed");
|
||||
|
@ -78,7 +85,8 @@ abstract class JSPager<T> : IPager<T> {
|
|||
.toList();
|
||||
_lastResults = newResults;
|
||||
_resultChanged = false;
|
||||
return newResults;
|
||||
return@busy newResults;
|
||||
}
|
||||
}
|
||||
|
||||
abstract fun convertResult(obj: V8ValueObject): T;
|
||||
|
|
|
@ -2,44 +2,59 @@ package com.futo.platformplayer.api.media.platforms.js.models
|
|||
|
||||
import com.caoccao.javet.values.reference.V8ValueObject
|
||||
import com.futo.platformplayer.api.media.models.playback.IPlaybackTracker
|
||||
import com.futo.platformplayer.api.media.platforms.js.JSClient
|
||||
import com.futo.platformplayer.engine.IV8PluginConfig
|
||||
import com.futo.platformplayer.engine.exceptions.ScriptImplementationException
|
||||
import com.futo.platformplayer.getOrThrow
|
||||
import com.futo.platformplayer.logging.Logger
|
||||
import com.futo.platformplayer.states.StatePlatform
|
||||
import com.futo.platformplayer.warnIfMainThread
|
||||
|
||||
class JSPlaybackTracker: IPlaybackTracker {
|
||||
private val _config: IV8PluginConfig;
|
||||
private val _obj: V8ValueObject;
|
||||
private lateinit var _client: JSClient;
|
||||
private lateinit var _config: IV8PluginConfig;
|
||||
private lateinit var _obj: V8ValueObject;
|
||||
|
||||
private var _hasCalledInit: Boolean = false;
|
||||
private val _hasInit: Boolean;
|
||||
private var _hasInit: Boolean = false;
|
||||
|
||||
private var _lastRequest: Long = Long.MIN_VALUE;
|
||||
|
||||
private val _hasOnConcluded: Boolean;
|
||||
private var _hasOnConcluded: Boolean = false;
|
||||
|
||||
override var nextRequest: Int = 1000
|
||||
private set;
|
||||
|
||||
constructor(config: IV8PluginConfig, obj: V8ValueObject) {
|
||||
constructor(client: JSClient, obj: V8ValueObject) {
|
||||
warnIfMainThread("JSPlaybackTracker.constructor");
|
||||
|
||||
client.busy {
|
||||
if (!obj.has("onProgress"))
|
||||
throw ScriptImplementationException(config, "Missing onProgress on PlaybackTracker");
|
||||
throw ScriptImplementationException(
|
||||
client.config,
|
||||
"Missing onProgress on PlaybackTracker"
|
||||
);
|
||||
if (!obj.has("nextRequest"))
|
||||
throw ScriptImplementationException(config, "Missing nextRequest on PlaybackTracker");
|
||||
throw ScriptImplementationException(
|
||||
client.config,
|
||||
"Missing nextRequest on PlaybackTracker"
|
||||
);
|
||||
_hasOnConcluded = obj.has("onConcluded");
|
||||
|
||||
this._config = config;
|
||||
this._client = client;
|
||||
this._config = client.config;
|
||||
this._obj = obj;
|
||||
this._hasInit = obj.has("onInit");
|
||||
}
|
||||
}
|
||||
|
||||
override fun onInit(seconds: Double) {
|
||||
warnIfMainThread("JSPlaybackTracker.onInit");
|
||||
synchronized(_obj) {
|
||||
if(_hasCalledInit)
|
||||
return;
|
||||
|
||||
_client.busy {
|
||||
if (_hasInit) {
|
||||
Logger.i("JSPlaybackTracker", "onInit (${seconds})");
|
||||
_obj.invokeVoid("onInit", seconds);
|
||||
|
@ -48,6 +63,7 @@ class JSPlaybackTracker: IPlaybackTracker {
|
|||
_hasCalledInit = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onProgress(seconds: Double, isPlaying: Boolean) {
|
||||
warnIfMainThread("JSPlaybackTracker.onProgress");
|
||||
|
@ -55,6 +71,7 @@ class JSPlaybackTracker: IPlaybackTracker {
|
|||
if(!_hasCalledInit && _hasInit)
|
||||
onInit(seconds);
|
||||
else {
|
||||
_client.busy {
|
||||
Logger.i("JSPlaybackTracker", "onProgress (${seconds}, ${isPlaying})");
|
||||
_obj.invokeVoid("onProgress", Math.floor(seconds), isPlaying);
|
||||
nextRequest = Math.max(100, _obj.getOrThrow(_config, "nextRequest", "PlaybackTracker", false));
|
||||
|
@ -62,15 +79,18 @@ class JSPlaybackTracker: IPlaybackTracker {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
override fun onConcluded() {
|
||||
warnIfMainThread("JSPlaybackTracker.onConcluded");
|
||||
if(_hasOnConcluded) {
|
||||
synchronized(_obj) {
|
||||
Logger.i("JSPlaybackTracker", "onConcluded");
|
||||
_client.busy {
|
||||
_obj.invokeVoid("onConcluded", -1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
override fun shouldUpdate(): Boolean = (_lastRequest < 0 || (System.currentTimeMillis() - _lastRequest) > nextRequest);
|
||||
|
|
|
@ -46,6 +46,8 @@ class JSRequestExecutor {
|
|||
if (_executor.isClosed)
|
||||
throw IllegalStateException("Executor object is closed");
|
||||
|
||||
return _plugin.getUnderlyingPlugin().busy {
|
||||
|
||||
val result = if(_plugin is DevJSClient)
|
||||
StateDeveloper.instance.handleDevCall(_plugin.devID, "requestExecutor.executeRequest()") {
|
||||
V8Plugin.catchScriptErrors<Any>(
|
||||
|
@ -67,7 +69,7 @@ class JSRequestExecutor {
|
|||
try {
|
||||
if(result is V8ValueString) {
|
||||
val base64Result = Base64.getDecoder().decode(result.value);
|
||||
return base64Result;
|
||||
return@busy base64Result;
|
||||
}
|
||||
if(result is V8ValueTypedArray) {
|
||||
val buffer = result.buffer;
|
||||
|
@ -75,7 +77,7 @@ class JSRequestExecutor {
|
|||
val bytesResult = ByteArray(result.byteLength);
|
||||
byteBuffer.get(bytesResult, 0, result.byteLength);
|
||||
buffer.close();
|
||||
return bytesResult;
|
||||
return@busy bytesResult;
|
||||
}
|
||||
if(result is V8ValueObject && result.has("type")) {
|
||||
val type = result.getOrThrow<Int>(_config, "type", "JSRequestModifier");
|
||||
|
@ -94,12 +96,13 @@ class JSRequestExecutor {
|
|||
result.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
open fun cleanup() {
|
||||
if (!hasCleanup || _executor.isClosed)
|
||||
return;
|
||||
|
||||
_plugin.busy {
|
||||
if(_plugin is DevJSClient)
|
||||
StateDeveloper.instance.handleDevCall(_plugin.devID, "requestExecutor.executeRequest()") {
|
||||
V8Plugin.catchScriptErrors<Any>(
|
||||
|
@ -118,6 +121,7 @@ class JSRequestExecutor {
|
|||
_executor.invokeVoid("cleanup", null);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
protected fun finalize() {
|
||||
cleanup();
|
||||
|
|
|
@ -27,6 +27,7 @@ import com.futo.platformplayer.getOrThrowNullable
|
|||
import com.futo.platformplayer.states.StateDeveloper
|
||||
|
||||
class JSVideoDetails : JSVideo, IPlatformVideoDetails {
|
||||
private val _plugin: JSClient;
|
||||
private val _hasGetComments: Boolean;
|
||||
private val _hasGetContentRecommendations: Boolean;
|
||||
private val _hasGetPlaybackTracker: Boolean;
|
||||
|
@ -48,6 +49,7 @@ class JSVideoDetails : JSVideo, IPlatformVideoDetails {
|
|||
|
||||
constructor(plugin: JSClient, obj: V8ValueObject) : super(plugin.config, obj) {
|
||||
val contextName = "VideoDetails";
|
||||
_plugin = plugin;
|
||||
val config = plugin.config;
|
||||
description = _content.getOrThrow(config, "description", contextName);
|
||||
video = JSVideoSourceDescriptor.fromV8(plugin, _content.getOrThrow(config, "video", contextName));
|
||||
|
@ -86,7 +88,7 @@ class JSVideoDetails : JSVideo, IPlatformVideoDetails {
|
|||
val tracker = _content.invoke<V8Value>("getPlaybackTracker", arrayOf<Any>())
|
||||
?: return@catchScriptErrors null;
|
||||
if(tracker is V8ValueObject)
|
||||
return@catchScriptErrors JSPlaybackTracker(_pluginConfig, tracker);
|
||||
return@catchScriptErrors JSPlaybackTracker(_plugin, tracker);
|
||||
else
|
||||
return@catchScriptErrors null;
|
||||
};
|
||||
|
|
|
@ -77,7 +77,11 @@ abstract class JSSource {
|
|||
|
||||
Logger.v("JSSource", "Request executor for [${type}] requesting");
|
||||
val result = V8Plugin.catchScriptErrors<Any>(_config, "[${_config.name}] JSSource", "obj.getRequestExecutor()") {
|
||||
_plugin.isBusyWith("getRequestExecutor") {
|
||||
_plugin.getUnderlyingPlugin().busy {
|
||||
_obj.invoke("getRequestExecutor", arrayOf<Any>());
|
||||
}
|
||||
}
|
||||
};
|
||||
Logger.v("JSSource", "Request executor for [${type}] received");
|
||||
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
package com.futo.platformplayer.engine
|
||||
|
||||
import android.content.Context
|
||||
import com.caoccao.javet.entities.JavetEntityError
|
||||
import com.caoccao.javet.exceptions.JavetCompilationException
|
||||
import com.caoccao.javet.exceptions.JavetException
|
||||
import com.caoccao.javet.exceptions.JavetExecutionException
|
||||
import com.caoccao.javet.interfaces.IJavetEntityError
|
||||
import com.caoccao.javet.interop.V8Host
|
||||
import com.caoccao.javet.interop.V8Runtime
|
||||
import com.caoccao.javet.interop.options.V8Flags
|
||||
|
@ -42,6 +44,9 @@ import com.futo.platformplayer.logging.Logger
|
|||
import com.futo.platformplayer.states.StateAssets
|
||||
import com.futo.platformplayer.warnIfMainThread
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
import java.util.concurrent.Semaphore
|
||||
import java.util.concurrent.locks.ReentrantLock
|
||||
import kotlin.concurrent.withLock
|
||||
|
||||
class V8Plugin {
|
||||
val config: IV8PluginConfig;
|
||||
|
@ -70,9 +75,10 @@ class V8Plugin {
|
|||
val onStopped = Event1<V8Plugin>();
|
||||
|
||||
//TODO: Implement a more universal isBusy system for plugins + JSClient + pooling? TBD if propagation would be beneficial
|
||||
private val _busyCounterLock = Object();
|
||||
private var _busyCounter = 0;
|
||||
val isBusy get() = synchronized(_busyCounterLock) { _busyCounter > 0 };
|
||||
//private val _busyCounterLock = Object();
|
||||
//private var _busyCounter = 0;
|
||||
private val _busyLock = ReentrantLock()//Semaphore(1);
|
||||
val isBusy get() = _busyLock.isLocked;//synchronized(_busyCounterLock) { _busyCounter > 0 };
|
||||
|
||||
var allowDevSubmit: Boolean = false
|
||||
private set(value) {
|
||||
|
@ -146,14 +152,19 @@ class V8Plugin {
|
|||
val host = V8Host.getV8Instance();
|
||||
val options = host.jsRuntimeType.getRuntimeOptions();
|
||||
|
||||
Logger.i(TAG, "Plugin [${config.name}] start: Creating runtime")
|
||||
|
||||
_runtime = host.createV8Runtime(options);
|
||||
if (!host.isIsolateCreated)
|
||||
throw IllegalStateException("Isolate not created");
|
||||
|
||||
Logger.i(TAG, "Plugin [${config.name}] start: Created runtime")
|
||||
|
||||
//Setup bridge
|
||||
_runtime?.let {
|
||||
it.converter = V8Converter();
|
||||
|
||||
Logger.i(TAG, "Plugin [${config.name}] start: Loading packages")
|
||||
for (pack in _depsPackages) {
|
||||
if (pack.variableName != null)
|
||||
it.createV8ValueObject().use { v8valueObject ->
|
||||
|
@ -166,6 +177,8 @@ class V8Plugin {
|
|||
}
|
||||
}
|
||||
|
||||
Logger.i(TAG, "Plugin [${config.name}] start: Loading deps")
|
||||
|
||||
//Load deps
|
||||
for (dep in _deps)
|
||||
catchScriptErrors("Dep[${dep.key}]") {
|
||||
|
@ -176,20 +189,23 @@ class V8Plugin {
|
|||
if (config.allowEval)
|
||||
it.allowEval(true);
|
||||
|
||||
Logger.i(TAG, "Plugin [${config.name}] start: Loading script")
|
||||
//Load plugin
|
||||
catchScriptErrors("Plugin[${config.name}]") {
|
||||
it.getExecutor(script).executeVoid()
|
||||
};
|
||||
isStopped = false;
|
||||
Logger.i(TAG, "Plugin [${config.name}] start: Script loaded")
|
||||
}
|
||||
}
|
||||
}
|
||||
fun stop(){
|
||||
Logger.i(TAG, "Stopping plugin [${config.name}]");
|
||||
isStopped = true;
|
||||
whenNotBusy {
|
||||
busy {
|
||||
Logger.i(TAG, "Plugin stopping");
|
||||
synchronized(_runtimeLock) {
|
||||
if(isStopped)
|
||||
return@busy;
|
||||
isStopped = true;
|
||||
|
||||
//Cleanup http
|
||||
|
@ -203,7 +219,7 @@ class V8Plugin {
|
|||
_runtime = null;
|
||||
if(!it.isClosed && !it.isDead) {
|
||||
try {
|
||||
it.close(true);
|
||||
it.close();
|
||||
}
|
||||
catch(ex: JavetException) {
|
||||
//In case race conditions are going on, already closed runtimes are fine.
|
||||
|
@ -219,6 +235,12 @@ class V8Plugin {
|
|||
}
|
||||
}
|
||||
|
||||
fun <T> busy(handle: ()->T): T {
|
||||
_busyLock.withLock {
|
||||
//Logger.i(TAG, "Entered busy: " + Thread.currentThread().stackTrace.drop(3)?.firstOrNull()?.toString() + ", " + Thread.currentThread().stackTrace.drop(4)?.firstOrNull()?.toString());
|
||||
return handle();
|
||||
}
|
||||
}
|
||||
fun execute(js: String) : V8Value {
|
||||
return executeTyped<V8Value>(js);
|
||||
}
|
||||
|
@ -227,6 +249,14 @@ class V8Plugin {
|
|||
if(isStopped)
|
||||
throw PluginEngineStoppedException(config, "Instance is stopped", js);
|
||||
|
||||
return busy {
|
||||
|
||||
val runtime = _runtime ?: throw IllegalStateException("JSPlugin not started yet");
|
||||
return@busy catchScriptErrors("Plugin[${config.name}]", js) {
|
||||
runtime.getExecutor(js).execute()
|
||||
};
|
||||
}
|
||||
/*
|
||||
synchronized(_busyCounterLock) {
|
||||
_busyCounter++;
|
||||
}
|
||||
|
@ -249,11 +279,26 @@ class V8Plugin {
|
|||
_busyCounter--;
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
fun executeBoolean(js: String) : Boolean? = catchScriptErrors("Plugin[${config.name}]") { executeTyped<V8ValueBoolean>(js).value };
|
||||
fun executeString(js: String) : String? = catchScriptErrors("Plugin[${config.name}]") { executeTyped<V8ValueString>(js).value };
|
||||
fun executeInteger(js: String) : Int? = catchScriptErrors("Plugin[${config.name}]") { executeTyped<V8ValueInteger>(js).value };
|
||||
fun executeBoolean(js: String) : Boolean? = busy { catchScriptErrors("Plugin[${config.name}]") { executeTyped<V8ValueBoolean>(js).value } }
|
||||
fun executeString(js: String) : String? = busy { catchScriptErrors("Plugin[${config.name}]") { executeTyped<V8ValueString>(js).value } }
|
||||
fun executeInteger(js: String) : Int? = busy { catchScriptErrors("Plugin[${config.name}]") { executeTyped<V8ValueInteger>(js).value } }
|
||||
|
||||
/*
|
||||
fun <T> whenNotBusyBlocking(handler: (V8Plugin)->T): T {
|
||||
while(true) {
|
||||
synchronized(_busyCounterLock) {
|
||||
if(_busyCounter == 0)
|
||||
{
|
||||
return handler(this);
|
||||
}
|
||||
}
|
||||
Thread.sleep(1);
|
||||
}
|
||||
}
|
||||
*/
|
||||
/*
|
||||
fun whenNotBusy(handler: (V8Plugin)->Unit) {
|
||||
synchronized(_busyCounterLock) {
|
||||
if(_busyCounter == 0)
|
||||
|
@ -264,12 +309,25 @@ class V8Plugin {
|
|||
if(it == 0) {
|
||||
Logger.w(TAG, "V8Plugin afterBusy handled");
|
||||
afterBusy.remove(tag);
|
||||
|
||||
var failed = false;
|
||||
synchronized(_busyCounterLock) {
|
||||
if(_busyCounter > 0) {
|
||||
failed = true;
|
||||
return@synchronized
|
||||
}
|
||||
handler(this);
|
||||
}
|
||||
if(failed)
|
||||
busy {
|
||||
handler(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
private fun getPackage(packageName: String, allowNull: Boolean = false): V8Package? {
|
||||
//TODO: Auto get all package types?
|
||||
|
@ -331,24 +389,29 @@ class V8Plugin {
|
|||
throw ScriptCompilationException(config, "Compilation: [${context}]: ${scriptEx.message}\n(${scriptEx.scriptingError.lineNumber})[${scriptEx.scriptingError.startColumn}-${scriptEx.scriptingError.endColumn}]: ${scriptEx.scriptingError.sourceLine}", null, codeStripped);
|
||||
}
|
||||
catch(executeEx: JavetExecutionException) {
|
||||
if(executeEx.scriptingError?.context is V8ValueObject) {
|
||||
val obj = executeEx.scriptingError?.context as V8ValueObject
|
||||
if(obj.has("plugin_type") == true) {
|
||||
val pluginType = obj.get<V8ValueString>("plugin_type").toString();
|
||||
if(executeEx.scriptingError?.context is IJavetEntityError) {
|
||||
val obj = executeEx.scriptingError?.context as IJavetEntityError
|
||||
if(obj.context.containsKey("plugin_type") == true) {
|
||||
val pluginType = obj.context["plugin_type"].toString();
|
||||
//val pluginType = obj.get<V8ValueString>("plugin_type").toString();
|
||||
|
||||
//Captcha
|
||||
if (pluginType == "CaptchaRequiredException") {
|
||||
throw ScriptCaptchaRequiredException(config,
|
||||
obj.get<V8ValueString>("url")?.toString(),
|
||||
obj.get<V8ValueString>("body")?.toString(),
|
||||
obj.context["url"]?.toString(),
|
||||
obj.context["body"]?.toString(),
|
||||
//obj.get<V8ValueString>("url")?.toString(),
|
||||
//obj.get<V8ValueString>("body")?.toString(),
|
||||
executeEx, executeEx.scriptingError?.stack, codeStripped);
|
||||
}
|
||||
|
||||
//Reload Required
|
||||
if (pluginType == "ReloadRequiredException") {
|
||||
throw ScriptReloadRequiredException(config,
|
||||
obj.get<V8ValueString>("message")?.toString(),
|
||||
obj.get<V8ValueString>("reloadData")?.toString(),
|
||||
obj.context["msg"]?.toString(),
|
||||
obj.context["reloadData"]?.toString(),
|
||||
//obj.get<V8ValueString>("message")?.toString(),
|
||||
//obj.get<V8ValueString>("reloadData")?.toString(),
|
||||
executeEx, executeEx.scriptingError?.stack, codeStripped);
|
||||
}
|
||||
|
||||
|
|
|
@ -13,8 +13,8 @@ open class V8BindObject : IV8Convertable {
|
|||
|
||||
override fun toV8(runtime: V8Runtime): V8Value? {
|
||||
synchronized(this) {
|
||||
if(_runtimeObj != null)
|
||||
return _runtimeObj;
|
||||
//if(_runtimeObj != null)
|
||||
// return _runtimeObj;
|
||||
|
||||
val v8Obj = runtime.createV8ValueObject();
|
||||
v8Obj.bind(this);
|
||||
|
|
|
@ -4,6 +4,7 @@ import android.media.MediaCodec
|
|||
import android.media.MediaCodecList
|
||||
import com.caoccao.javet.annotations.V8Function
|
||||
import com.caoccao.javet.annotations.V8Property
|
||||
import com.caoccao.javet.interop.callback.JavetCallbackContext
|
||||
import com.caoccao.javet.utils.JavetResourceUtils
|
||||
import com.caoccao.javet.values.V8Value
|
||||
import com.caoccao.javet.values.reference.V8ValueFunction
|
||||
|
@ -112,29 +113,43 @@ class PackageBridge : V8Package {
|
|||
@V8Function
|
||||
fun setTimeout(func: V8ValueFunction, timeout: Long): Int {
|
||||
val id = timeoutCounter++;
|
||||
|
||||
val funcClone = func.toClone<V8ValueFunction>()
|
||||
|
||||
StateApp.instance.scopeOrNull?.launch(Dispatchers.IO) {
|
||||
delay(timeout);
|
||||
if(_plugin.isStopped)
|
||||
return@launch;
|
||||
synchronized(timeoutMap) {
|
||||
if(!timeoutMap.contains(id)) {
|
||||
_plugin.busy {
|
||||
if(!_plugin.isStopped)
|
||||
JavetResourceUtils.safeClose(funcClone);
|
||||
}
|
||||
return@launch;
|
||||
}
|
||||
timeoutMap.remove(id);
|
||||
}
|
||||
try {
|
||||
_plugin.whenNotBusy {
|
||||
Logger.v(TAG, "Timeout started [${id}]");
|
||||
_plugin.busy {
|
||||
Logger.v(TAG, "Timeout call started [${id}]");
|
||||
if(!_plugin.isStopped)
|
||||
funcClone.callVoid(null, arrayOf<Any>());
|
||||
Logger.v(TAG, "Timeout call ended [${id}]");
|
||||
}
|
||||
Logger.v(TAG, "Timeout resolved [${id}]");
|
||||
}
|
||||
catch(ex: Throwable) {
|
||||
Logger.e(TAG, "Failed timeout callback", ex);
|
||||
}
|
||||
finally {
|
||||
_plugin.busy {
|
||||
if(!_plugin.isStopped)
|
||||
JavetResourceUtils.safeClose(funcClone);
|
||||
}
|
||||
//_plugin.whenNotBusy {
|
||||
//}
|
||||
}
|
||||
};
|
||||
synchronized(timeoutMap) {
|
||||
timeoutMap.add(id);
|
||||
|
|
|
@ -656,8 +656,10 @@ class PackageHttp: V8Package {
|
|||
_isOpen = true;
|
||||
if(hasOpen && _listeners?.isClosed != true) {
|
||||
try {
|
||||
_package._plugin.busy {
|
||||
_listeners?.invokeVoid("open", arrayOf<Any>());
|
||||
}
|
||||
}
|
||||
catch(ex: Throwable){
|
||||
Logger.e(TAG, "Socket for [${_packageClient.parentConfig.name}] open failed: " + ex.message, ex);
|
||||
}
|
||||
|
@ -666,8 +668,10 @@ class PackageHttp: V8Package {
|
|||
override fun message(msg: String) {
|
||||
if(hasMessage && _listeners?.isClosed != true) {
|
||||
try {
|
||||
_package._plugin.busy {
|
||||
_listeners?.invokeVoid("message", msg);
|
||||
}
|
||||
}
|
||||
catch(ex: Throwable) {}
|
||||
}
|
||||
}
|
||||
|
@ -675,8 +679,10 @@ class PackageHttp: V8Package {
|
|||
if(hasClosing && _listeners?.isClosed != true)
|
||||
{
|
||||
try {
|
||||
_package._plugin.busy {
|
||||
_listeners?.invokeVoid("closing", code, reason);
|
||||
}
|
||||
}
|
||||
catch(ex: Throwable){
|
||||
Logger.e(TAG, "Socket for [${_packageClient.parentConfig.name}] closing failed: " + ex.message, ex);
|
||||
}
|
||||
|
@ -686,8 +692,10 @@ class PackageHttp: V8Package {
|
|||
_isOpen = false;
|
||||
if(hasClosed && _listeners?.isClosed != true) {
|
||||
try {
|
||||
_package._plugin.busy {
|
||||
_listeners?.invokeVoid("closed", code, reason);
|
||||
}
|
||||
}
|
||||
catch(ex: Throwable){
|
||||
Logger.e(TAG, "Socket for [${_packageClient.parentConfig.name}] closed failed: " + ex.message, ex);
|
||||
}
|
||||
|
@ -702,8 +710,10 @@ class PackageHttp: V8Package {
|
|||
Logger.e(TAG, "Websocket failure: ${exception.message} (${_url})", exception);
|
||||
if(hasFailure && _listeners?.isClosed != true) {
|
||||
try {
|
||||
_package._plugin.busy {
|
||||
_listeners?.invokeVoid("failure", exception.message);
|
||||
}
|
||||
}
|
||||
catch(ex: Throwable){
|
||||
Logger.e(TAG, "Socket for [${_packageClient.parentConfig.name}] closed failed: " + ex.message, ex);
|
||||
}
|
||||
|
|
|
@ -2497,7 +2497,9 @@ class VideoDetailView : ConstraintLayout {
|
|||
|
||||
val url = _url;
|
||||
if (!url.isNullOrBlank()) {
|
||||
fragment.lifecycleScope.launch(Dispatchers.Main) {
|
||||
setLoading(true);
|
||||
}
|
||||
_taskLoadVideo.run(url);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -570,7 +570,7 @@ abstract class FutoVideoPlayerBase : RelativeLayout {
|
|||
if (generated != null) {
|
||||
withContext(Dispatchers.Main) {
|
||||
val dataSource = if(videoSource is JSSource && (videoSource.requiresCustomDatasource))
|
||||
videoSource.getHttpDataSourceFactory()
|
||||
withContext(Dispatchers.IO) { videoSource.getHttpDataSourceFactory() }
|
||||
else
|
||||
DefaultHttpDataSource.Factory().setUserAgent(DEFAULT_USER_AGENT);
|
||||
|
||||
|
@ -593,6 +593,7 @@ abstract class FutoVideoPlayerBase : RelativeLayout {
|
|||
catch(reloadRequired: ScriptReloadRequiredException) {
|
||||
Logger.i(TAG, "Reload required detected");
|
||||
StatePlatform.instance.handleReloadRequired(reloadRequired, {
|
||||
Logger.i(TAG, "ReloadRequired started reloading video");
|
||||
onReloadRequired.emit();
|
||||
});
|
||||
}
|
||||
|
@ -704,9 +705,11 @@ abstract class FutoVideoPlayerBase : RelativeLayout {
|
|||
val plugin = audioSource.getUnderlyingPlugin();
|
||||
if(plugin == null)
|
||||
return@launch;
|
||||
/*
|
||||
StatePlatform.instance.reEnableClient(plugin.id, {
|
||||
onReloadRequired.emit();
|
||||
});
|
||||
*/
|
||||
}
|
||||
catch(ex: Throwable) {
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue