Initial plugin release
This commit is contained in:
commit
9505ff6522
7 files changed
+1420
No files matched your search
@@ -0,0 +1,75 @@
|
||||
var exec = require("cordova/exec");
|
||||
|
||||
function normalizeError(error) {
|
||||
if (typeof error !== "string") {
|
||||
return error || { code: "UNKNOWN", message: "Unknown error" };
|
||||
}
|
||||
|
||||
try {
|
||||
return JSON.parse(error);
|
||||
} catch (parseError) {
|
||||
return {
|
||||
code: "UNKNOWN",
|
||||
message: error
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
function execWithPromise(action, options, success, error) {
|
||||
if (typeof success === "function" || typeof error === "function") {
|
||||
exec(
|
||||
success,
|
||||
function (nativeError) {
|
||||
if (typeof error === "function") {
|
||||
error(normalizeError(nativeError));
|
||||
}
|
||||
},
|
||||
"BluememeWifiConnector",
|
||||
action,
|
||||
[options || {}]
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
return new Promise(function (resolve, reject) {
|
||||
exec(
|
||||
resolve,
|
||||
function (nativeError) {
|
||||
reject(normalizeError(nativeError));
|
||||
},
|
||||
"BluememeWifiConnector",
|
||||
action,
|
||||
[options || {}]
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
connect: function (options, success, error) {
|
||||
return execWithPromise("connect", options, success, error);
|
||||
},
|
||||
|
||||
connectLocalOnly: function (options, success, error) {
|
||||
return execWithPromise("connectLocalOnly", options, success, error);
|
||||
},
|
||||
|
||||
addNetworkSuggestion: function (options, success, error) {
|
||||
return execWithPromise("addNetworkSuggestion", options, success, error);
|
||||
},
|
||||
|
||||
removeNetworkSuggestion: function (options, success, error) {
|
||||
return execWithPromise("removeNetworkSuggestion", options, success, error);
|
||||
},
|
||||
|
||||
saveNetwork: function (options, success, error) {
|
||||
return execWithPromise("saveNetwork", options, success, error);
|
||||
},
|
||||
|
||||
disconnect: function (options, success, error) {
|
||||
if (typeof options === "function" || typeof options === "undefined") {
|
||||
return execWithPromise("disconnect", {}, options, success);
|
||||
}
|
||||
|
||||
return execWithPromise("disconnect", options || {}, success, error);
|
||||
}
|
||||
};
|
||||
Reference in new issue
Block a user