添加是否运行状态查询
This commit is contained in:
parent
00adabeb3f
commit
ce067a1e89
@ -26,24 +26,32 @@ public class Webserver extends CordovaPlugin {
|
|||||||
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
|
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
|
||||||
if ("start".equals(action)) {
|
if ("start".equals(action)) {
|
||||||
try {
|
try {
|
||||||
this.start(args, callbackContext);
|
this.start(args, callbackContext);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if ("stop".equals(action)) {
|
if ("stop".equals(action)) {
|
||||||
this.stop(args, callbackContext);
|
this.stop(args, callbackContext);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if ("onRequest".equals(action)) {
|
if ("onRequest".equals(action)) {
|
||||||
this.onRequest(args, callbackContext);
|
this.onRequest(args, callbackContext);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if ("sendResponse".equals(action)) {
|
if ("sendResponse".equals(action)) {
|
||||||
this.sendResponse(args, callbackContext);
|
this.sendResponse(args, callbackContext);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
if ("isRunning".equals(action)) {
|
||||||
|
if(this.nanoHTTPDWebserver!=null){
|
||||||
|
callbackContext.success(this.nanoHTTPDWebserver.isAlive()?1:0);
|
||||||
|
}else{
|
||||||
|
callbackContext.success(0);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
return false; // Returning false results in a "MethodNotFound" error.
|
return false; // Returning false results in a "MethodNotFound" error.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -167,4 +167,10 @@
|
|||||||
let pluginResult = CDVPluginResult(status: CDVCommandStatus_OK)
|
let pluginResult = CDVPluginResult(status: CDVCommandStatus_OK)
|
||||||
self.commandDelegate!.send(pluginResult, callbackId: command.callbackId)
|
self.commandDelegate!.send(pluginResult, callbackId: command.callbackId)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@objc(isRunning:)
|
||||||
|
func isRunning(_ command: CDVInvokedUrlCommand) {
|
||||||
|
let pluginResult = CDVPluginResult(status: CDVCommandStatus_OK,messageAsInt: self.webServer.isRunning ? 1 : 0)
|
||||||
|
self.commandDelegate!.send(pluginResult, callbackId: command.callbackId)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ const START_FUNCTION = 'start';
|
|||||||
const ONREQUEST_FUNCTION = 'onRequest';
|
const ONREQUEST_FUNCTION = 'onRequest';
|
||||||
const SENDRESPONSE_FUNCION = 'sendResponse';
|
const SENDRESPONSE_FUNCION = 'sendResponse';
|
||||||
const STOP_FUNCTION = 'stop';
|
const STOP_FUNCTION = 'stop';
|
||||||
|
const ISRUNNING_FUNCTION = 'isRunning';
|
||||||
|
|
||||||
export function start(success_callback, error_callback, port) {
|
export function start(success_callback, error_callback, port) {
|
||||||
let params = [];
|
let params = [];
|
||||||
@ -54,3 +55,12 @@ export function stop(success_callback, error_callback) {
|
|||||||
[]
|
[]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
export function isRunning(success_callback, error_callback) {
|
||||||
|
exec(
|
||||||
|
success_callback,
|
||||||
|
error_callback,
|
||||||
|
WEBSERVER_CLASS,
|
||||||
|
ISRUNNING_FUNCTION,
|
||||||
|
[]
|
||||||
|
);
|
||||||
|
}
|
@ -7,6 +7,7 @@ exports.start = start;
|
|||||||
exports.onRequest = onRequest;
|
exports.onRequest = onRequest;
|
||||||
exports.sendResponse = sendResponse;
|
exports.sendResponse = sendResponse;
|
||||||
exports.stop = stop;
|
exports.stop = stop;
|
||||||
|
exports.isRunning = isRunning;
|
||||||
|
|
||||||
var _exec = require('cordova/exec');
|
var _exec = require('cordova/exec');
|
||||||
|
|
||||||
@ -19,6 +20,7 @@ var START_FUNCTION = 'start';
|
|||||||
var ONREQUEST_FUNCTION = 'onRequest';
|
var ONREQUEST_FUNCTION = 'onRequest';
|
||||||
var SENDRESPONSE_FUNCION = 'sendResponse';
|
var SENDRESPONSE_FUNCION = 'sendResponse';
|
||||||
var STOP_FUNCTION = 'stop';
|
var STOP_FUNCTION = 'stop';
|
||||||
|
var ISRUNNING_FUNCTION = 'isRunning';
|
||||||
|
|
||||||
function start(success_callback, error_callback, port) {
|
function start(success_callback, error_callback, port) {
|
||||||
var params = [];
|
var params = [];
|
||||||
@ -41,3 +43,6 @@ function sendResponse(requestId, params, success_callback, error_callback) {
|
|||||||
function stop(success_callback, error_callback) {
|
function stop(success_callback, error_callback) {
|
||||||
(0, _exec2.default)(success_callback, error_callback, WEBSERVER_CLASS, STOP_FUNCTION, []);
|
(0, _exec2.default)(success_callback, error_callback, WEBSERVER_CLASS, STOP_FUNCTION, []);
|
||||||
}
|
}
|
||||||
|
function isRunning(success_callback, error_callback) {
|
||||||
|
(0, _exec2.default)(success_callback, error_callback, WEBSERVER_CLASS, ISRUNNING_FUNCTION, []);
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user