Write Webserver in ES6
This commit is contained in:
parent
155b46fae4
commit
d091dc88cd
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,3 +1,6 @@
|
||||
# IDE
|
||||
.idea
|
||||
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
|
5480
package-lock.json
generated
Normal file
5480
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
10
package.json
10
package.json
@ -31,8 +31,16 @@
|
||||
"response"
|
||||
],
|
||||
"devDependencies": {
|
||||
"babel-cli": "^6.24.1",
|
||||
"babel-core": "^6.25.0",
|
||||
"babel-loader": "^7.1.1",
|
||||
"babel-preset-env": "^1.6.0",
|
||||
"babel-preset-es2015": "^6.24.1",
|
||||
"babel-preset-stage-2": "^6.24.1",
|
||||
"cordova": "^6.1.1"
|
||||
},
|
||||
"scripts": {
|
||||
}
|
||||
"build": "babel src/www/webserver.js --out-file webserver.js"
|
||||
},
|
||||
"dependencies": {}
|
||||
}
|
||||
|
56
src/www/webserver.js
Normal file
56
src/www/webserver.js
Normal file
@ -0,0 +1,56 @@
|
||||
import exec from 'cordova/exec';
|
||||
|
||||
const WEBSERVER_CLASS = 'Webserver';
|
||||
const START_FUNCTION = 'start';
|
||||
const ONREQUEST_FUNCTION = 'onRequest';
|
||||
const SENDRESPONSE_FUNCION = 'sendResponse';
|
||||
const STOP_FUNCTION = 'stop';
|
||||
|
||||
export function start(success_callback, error_callback, port) {
|
||||
let params = [];
|
||||
if (port) {
|
||||
params.push(port);
|
||||
}
|
||||
exec(
|
||||
success_callback,
|
||||
error_callback,
|
||||
WEBSERVER_CLASS,
|
||||
START_FUNCTION,
|
||||
params
|
||||
);
|
||||
}
|
||||
|
||||
export function onRequest(success_callback) {
|
||||
exec(
|
||||
success_callback,
|
||||
function(error) {console.error(error)},
|
||||
WEBSERVER_CLASS,
|
||||
ONREQUEST_FUNCTION,
|
||||
[]
|
||||
);
|
||||
}
|
||||
|
||||
export function sendResponse(
|
||||
requestId,
|
||||
params,
|
||||
success_callback,
|
||||
error_callback
|
||||
) {
|
||||
exec(
|
||||
success_callback,
|
||||
error_callback,
|
||||
WEBSERVER_CLASS,
|
||||
SENDRESPONSE_FUNCION,
|
||||
[requestId, params]
|
||||
);
|
||||
}
|
||||
|
||||
export function stop(success_callback, error_callback) {
|
||||
exec(
|
||||
success_callback,
|
||||
error_callback,
|
||||
WEBSERVER_CLASS,
|
||||
STOP_FUNCTION,
|
||||
[]
|
||||
);
|
||||
}
|
77
webserver.js
77
webserver.js
@ -1,50 +1,43 @@
|
||||
var WEBSERVER_CLASS = "Webserver";
|
||||
'use strict';
|
||||
|
||||
exports.start = function(success_callback, error_callback, port) {
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.start = start;
|
||||
exports.onRequest = onRequest;
|
||||
exports.sendResponse = sendResponse;
|
||||
exports.stop = stop;
|
||||
|
||||
var _exec = require('cordova/exec');
|
||||
|
||||
var _exec2 = _interopRequireDefault(_exec);
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
var WEBSERVER_CLASS = 'Webserver';
|
||||
var START_FUNCTION = 'start';
|
||||
var ONREQUEST_FUNCTION = 'onRequest';
|
||||
var SENDRESPONSE_FUNCION = 'sendResponse';
|
||||
var STOP_FUNCTION = 'stop';
|
||||
|
||||
function start(success_callback, error_callback, port) {
|
||||
var params = [];
|
||||
if (port) {
|
||||
params.push(port);
|
||||
}
|
||||
cordova.exec(
|
||||
success_callback,
|
||||
error_callback,
|
||||
WEBSERVER_CLASS,
|
||||
"start",
|
||||
params
|
||||
);
|
||||
};
|
||||
(0, _exec2.default)(success_callback, error_callback, WEBSERVER_CLASS, START_FUNCTION, params);
|
||||
}
|
||||
|
||||
exports.onRequest = function(success_callback) {
|
||||
cordova.exec(
|
||||
success_callback,
|
||||
function(error) {console.error(error)},
|
||||
WEBSERVER_CLASS,
|
||||
"onRequest",
|
||||
[]
|
||||
);
|
||||
};
|
||||
function onRequest(success_callback) {
|
||||
(0, _exec2.default)(success_callback, function (error) {
|
||||
console.error(error);
|
||||
}, WEBSERVER_CLASS, ONREQUEST_FUNCTION, []);
|
||||
}
|
||||
|
||||
exports.sendResponse = function(
|
||||
requestId,
|
||||
params,
|
||||
success_callback,
|
||||
error_callback
|
||||
) {
|
||||
cordova.exec(
|
||||
success_callback,
|
||||
error_callback,
|
||||
WEBSERVER_CLASS,
|
||||
"sendResponse",
|
||||
[requestId, params]
|
||||
);
|
||||
};
|
||||
function sendResponse(requestId, params, success_callback, error_callback) {
|
||||
(0, _exec2.default)(success_callback, error_callback, WEBSERVER_CLASS, SENDRESPONSE_FUNCION, [requestId, params]);
|
||||
}
|
||||
|
||||
exports.stop = function(success_callback, error_callback) {
|
||||
cordova.exec(
|
||||
success_callback,
|
||||
error_callback,
|
||||
WEBSERVER_CLASS,
|
||||
"stop",
|
||||
[]
|
||||
);
|
||||
};
|
||||
function stop(success_callback, error_callback) {
|
||||
(0, _exec2.default)(success_callback, error_callback, WEBSERVER_CLASS, STOP_FUNCTION, []);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user