diff --git a/package.json b/package.json new file mode 100644 index 0000000..e782779 --- /dev/null +++ b/package.json @@ -0,0 +1,39 @@ +{ + "name": "cordova-plugin-webserver", + "version": "1.0.0", + "description": "Cordova Webserver", + "homepage": "", + "author": { + "name": "Michael Bykovski" + }, + "license": "Apache-2.0", + "cordova": { + "id": "cordova-plugin-webserver", + "platforms": [ + "ios", + "android" + ] + }, + "repository": { + "type": "git", + "url": "" + }, + "keywords": [ + "cordova", + "ios", + "android", + "ecosystem:cordova", + "cordova-ios", + "cordova:plugin", + "webserver", + "http", + "request", + "response" + ], + "devDependencies": { + "cordova": "^6.1.1" + }, + "scripts": { + "deploy": "cd tests/app && cordova run --device" + } +} diff --git a/plugin.xml b/plugin.xml new file mode 100644 index 0000000..31884ce --- /dev/null +++ b/plugin.xml @@ -0,0 +1,37 @@ + + + + + + + + + Webserver for Cordova Apps + webserver,cordova,http, request, response,server + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/android/Webserver.java b/src/android/Webserver.java new file mode 100644 index 0000000..d8d3982 --- /dev/null +++ b/src/android/Webserver.java @@ -0,0 +1,21 @@ +package org.apache.cordova.plugin; + +import org.apache.cordova.api.CordovaPlugin; +import org.apache.cordova.api.PluginResult; +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +/** + * This class echoes a string called from JavaScript. + */ +public class Webserver extends CordovaPlugin { + @Override + public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { + if ("start".equals(action)) { + callbackContext.success(); + return true; + } + return false; // Returning false results in a "MethodNotFound" error. + } +} diff --git a/src/ios/Webserver.swift b/src/ios/Webserver.swift new file mode 100644 index 0000000..9d5014a --- /dev/null +++ b/src/ios/Webserver.swift @@ -0,0 +1,12 @@ +@objc(Webserver) class Webserver : CDVPlugin { + func start(command: CDVInvokedUrlCommand) { + var pluginResult = CDVPluginResult( + status: CDVCommandStatus_OK + ) + + self.commandDelegate!.sendPluginResult( + pluginResult, + callbackId: command.callbackId + ) + } +} diff --git a/tests/package.json b/tests/package.json new file mode 100644 index 0000000..f4653ff --- /dev/null +++ b/tests/package.json @@ -0,0 +1,14 @@ +{ + "name": "cordova-plugin-webserver-tests", + "version": "1.0.0", + "description": "", + "cordova": { + "id": "cordova-plugin-webserver-tests", + "platforms": [] + }, + "keywords": [ + "ecosystem:cordova" + ], + "author": "Michael Bykovski", + "license": "Apache 2.0" +} diff --git a/tests/plugin.xml b/tests/plugin.xml new file mode 100644 index 0000000..04e5870 --- /dev/null +++ b/tests/plugin.xml @@ -0,0 +1,11 @@ + + + + Cordova Plugin Webserver Tests + Apache 2.0 + + + + diff --git a/tests/tests.js b/tests/tests.js new file mode 100644 index 0000000..0c3d272 --- /dev/null +++ b/tests/tests.js @@ -0,0 +1,33 @@ +exports.defineAutoTests = function() { + + describe('Webserver (window.webserver)', function () { + var fns = [ + 'start' + ]; + + it('should exist', function() { + expect(webserver).toBeDefined(); + }); + + fns.forEach(function(fn) { + it('should contain a ' + fn + ' function', function () { + expect(typeof webserver[fn]).toBeDefined(); + expect(typeof webserver[fn] === 'function').toBe(true); + }); + }) + }); +}; + +exports.defineManualTests = function(contentEl, createActionButton) { + createActionButton('Start', function() { + webserver.start( + function() { + console.log('Success!'); + }, + function() { + console.log('Error!'); + }, + + ); + }); +}; diff --git a/webserver.js b/webserver.js new file mode 100644 index 0000000..8a76b6e --- /dev/null +++ b/webserver.js @@ -0,0 +1,3 @@ +exports.start = function(success_callback, error_callback) { + cordova.exec(success_callback, error_callback, "Webserver", "start", []); +};