Fix the problem that aria2 status is incorrect sometimes
This commit is contained in:
parent
690345ccf8
commit
de5884e94e
|
@ -285,12 +285,16 @@
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
aria2TaskService.onOperationSuccess(function () {
|
aria2TaskService.onConnectionSuccess(function () {
|
||||||
$rootScope.taskContext.rpcStatus = 'Connected';
|
if ($rootScope.taskContext.rpcStatus !== 'Connected') {
|
||||||
|
$rootScope.taskContext.rpcStatus = 'Connected';
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
aria2TaskService.onOperationError(function () {
|
aria2TaskService.onConnectionFailed(function () {
|
||||||
$rootScope.taskContext.rpcStatus = 'Disconnected';
|
if ($rootScope.taskContext.rpcStatus !== 'Disconnected') {
|
||||||
|
$rootScope.taskContext.rpcStatus = 'Disconnected';
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
aria2TaskService.onTaskCompleted(function (event) {
|
aria2TaskService.onTaskCompleted(function (event) {
|
||||||
|
|
|
@ -77,6 +77,13 @@
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (context.connectionSuccessCallback) {
|
||||||
|
context.connectionSuccessCallback({
|
||||||
|
rpcUrl: rpcUrl,
|
||||||
|
method: method
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if (context.successCallback) {
|
if (context.successCallback) {
|
||||||
context.successCallback(data.id, data.result);
|
context.successCallback(data.id, data.result);
|
||||||
}
|
}
|
||||||
|
@ -94,6 +101,13 @@
|
||||||
innerError: true
|
innerError: true
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (context.connectionFailedCallback) {
|
||||||
|
context.connectionFailedCallback({
|
||||||
|
rpcUrl: rpcUrl,
|
||||||
|
method: method
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (context.errorCallback) {
|
if (context.errorCallback) {
|
||||||
|
|
|
@ -9,6 +9,8 @@
|
||||||
var onFirstSuccessCallbacks = [];
|
var onFirstSuccessCallbacks = [];
|
||||||
var onOperationSuccessCallbacks = [];
|
var onOperationSuccessCallbacks = [];
|
||||||
var onOperationErrorCallbacks = [];
|
var onOperationErrorCallbacks = [];
|
||||||
|
var onConnectionSuccessCallbacks = [];
|
||||||
|
var onConnectionFailedCallbacks = [];
|
||||||
var onDownloadStartCallbacks = [];
|
var onDownloadStartCallbacks = [];
|
||||||
var onDownloadPauseCallbacks = [];
|
var onDownloadPauseCallbacks = [];
|
||||||
var onDownloadStopCallbacks = [];
|
var onDownloadStopCallbacks = [];
|
||||||
|
@ -45,6 +47,8 @@
|
||||||
var invokeContext = {
|
var invokeContext = {
|
||||||
uniqueId: uniqueId,
|
uniqueId: uniqueId,
|
||||||
requestBody: requestBody,
|
requestBody: requestBody,
|
||||||
|
connectionSuccessCallback: requestContext.connectionSuccessCallback,
|
||||||
|
connectionFailedCallback: requestContext.connectionFailedCallback,
|
||||||
successCallback: requestContext.successCallback,
|
successCallback: requestContext.successCallback,
|
||||||
errorCallback: requestContext.errorCallback
|
errorCallback: requestContext.errorCallback
|
||||||
};
|
};
|
||||||
|
@ -132,6 +136,14 @@
|
||||||
methodName: (!isSystemMethod ? getAria2MethodFullName(methodName) : methodName)
|
methodName: (!isSystemMethod ? getAria2MethodFullName(methodName) : methodName)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
context.connectionSuccessCallback = function () {
|
||||||
|
fireCustomEvent(onConnectionSuccessCallbacks);
|
||||||
|
};
|
||||||
|
|
||||||
|
context.connectionFailedCallback = function () {
|
||||||
|
fireCustomEvent(onConnectionFailedCallbacks);
|
||||||
|
};
|
||||||
|
|
||||||
if (secret && !isSystemMethod) {
|
if (secret && !isSystemMethod) {
|
||||||
finalParams.push(aria2RpcConstants.rpcTokenPrefix + secret);
|
finalParams.push(aria2RpcConstants.rpcTokenPrefix + secret);
|
||||||
}
|
}
|
||||||
|
@ -478,6 +490,12 @@
|
||||||
onOperationError: function (context) {
|
onOperationError: function (context) {
|
||||||
onOperationErrorCallbacks.push(context.callback);
|
onOperationErrorCallbacks.push(context.callback);
|
||||||
},
|
},
|
||||||
|
onConnectionSuccess: function (context) {
|
||||||
|
onConnectionSuccessCallbacks.push(context.callback);
|
||||||
|
},
|
||||||
|
onConnectionFailed: function (context) {
|
||||||
|
onConnectionFailedCallbacks.push(context.callback);
|
||||||
|
},
|
||||||
onDownloadStart: function (context) {
|
onDownloadStart: function (context) {
|
||||||
onDownloadStartCallbacks.push(context.callback);
|
onDownloadStartCallbacks.push(context.callback);
|
||||||
},
|
},
|
||||||
|
|
|
@ -844,6 +844,28 @@
|
||||||
callback: callback
|
callback: callback
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
onConnectionSuccess: function (callback) {
|
||||||
|
if (!callback) {
|
||||||
|
ariaNgLogService.warn('[aria2TaskService.onConnectionSuccess] callback is null');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
aria2RpcService.onConnectionSuccess({
|
||||||
|
callback: callback
|
||||||
|
});
|
||||||
|
|
||||||
|
},
|
||||||
|
onConnectionFailed: function (callback) {
|
||||||
|
if (!callback) {
|
||||||
|
ariaNgLogService.warn('[aria2TaskService.onConnectionFailed] callback is null');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
aria2RpcService.onConnectionFailed({
|
||||||
|
callback: callback
|
||||||
|
});
|
||||||
|
|
||||||
|
},
|
||||||
onFirstSuccess: function (callback) {
|
onFirstSuccess: function (callback) {
|
||||||
if (!callback) {
|
if (!callback) {
|
||||||
ariaNgLogService.warn('[aria2TaskService.onFirstSuccess] callback is null');
|
ariaNgLogService.warn('[aria2TaskService.onFirstSuccess] callback is null');
|
||||||
|
|
|
@ -28,6 +28,12 @@
|
||||||
context: context
|
context: context
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (content.result && context.connectionSuccessCallback) {
|
||||||
|
context.connectionSuccessCallback({
|
||||||
|
rpcUrl: rpcUrl
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if (content.result && context.successCallback) {
|
if (content.result && context.successCallback) {
|
||||||
ariaNgLogService.debug('[aria2WebSocketRpcService.request] ' + (context && context.requestBody && context.requestBody.method ? context.requestBody.method + ' ' : '') + 'response success', content);
|
ariaNgLogService.debug('[aria2WebSocketRpcService.request] ' + (context && context.requestBody && context.requestBody.method ? context.requestBody.method + ' ' : '') + 'response success', content);
|
||||||
|
|
||||||
|
@ -63,7 +69,7 @@
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var getSocketClient = function () {
|
var getSocketClient = function (context) {
|
||||||
if (socketClient === null) {
|
if (socketClient === null) {
|
||||||
try {
|
try {
|
||||||
socketClient = $websocket(rpcUrl);
|
socketClient = $websocket(rpcUrl);
|
||||||
|
@ -85,6 +91,26 @@
|
||||||
processEventCallback(content);
|
processEventCallback(content);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
socketClient.onOpen(function (e) {
|
||||||
|
ariaNgLogService.debug('[aria2WebSocketRpcService.onOpen] websocket is opened', e);
|
||||||
|
|
||||||
|
if (context && context.connectionSuccessCallback) {
|
||||||
|
context.connectionSuccessCallback({
|
||||||
|
rpcUrl: rpcUrl
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
socketClient.onClose(function (e) {
|
||||||
|
ariaNgLogService.warn('[aria2WebSocketRpcService.onClose] websocket is closed', e);
|
||||||
|
|
||||||
|
if (context && context.connectionFailedCallback) {
|
||||||
|
context.connectionFailedCallback({
|
||||||
|
rpcUrl: rpcUrl
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
|
@ -106,7 +132,9 @@
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var client = getSocketClient();
|
var client = getSocketClient({
|
||||||
|
connectionFailedCallback: context.connectionFailedCallback
|
||||||
|
});
|
||||||
var uniqueId = context.uniqueId;
|
var uniqueId = context.uniqueId;
|
||||||
var requestBody = angular.toJson(context.requestBody);
|
var requestBody = angular.toJson(context.requestBody);
|
||||||
|
|
||||||
|
|
Reference in a new issue