Auto detect server

This commit is contained in:
Myx
2022-07-28 01:20:23 +02:00
parent 4ae248dfa0
commit 0a7442d908
34 changed files with 53196 additions and 47 deletions

View File

@@ -0,0 +1,26 @@
# PhoneGap Wake On Lan
Very basic plugin for sending wake on lan requests from a phonegap app.
# Installation
1. phonegap plugin add https://github.com/lipemat/phonegap-wake-on-lan.git
2. Or add `<plugin spec="https://github.com/lipemat/phonegap-wake-on-lan.git" source="git"/>` to your main config.xml
# Usage in JS
~~~~
document.addEventListener( 'deviceready', function(){
//replace the broadcast ip and mac
var BROADCAST = '192.168.1.255';
var MAC = '48-2C-6A-1E-59-3D';
window.plugins.WakeOnLan.wake( BROADCAST, MAC, function( r ){
console.log( r )
}, function( r){
console.error( r )
} );
}, false );
~~~~
### That's it! Super straight forward.
Wake On Lan Plugin For Cordova/Phonegap

View File

@@ -0,0 +1,58 @@
{
"name": "phonegap-wake-on-lan",
"version": "8.1.1-dev",
"description": "You can use the BarcodeScanner plugin to scan different types of barcodes (using the device's camera) and get the metadata encoded in them for processing within your application.",
"cordova": {
"id": "phonegap-wake-on-lan",
"platforms": [
"ios",
"android",
"windows",
"browser"
]
},
"repository": {
"type": "local",
"url": "C:\\repos\\IonicGoToBed\\go-to-bed\\Client\\plugins\\phonegap-wake-on-lan"
},
"keywords": [
"ecosystem:cordova",
"ecosystem:phonegap",
"cordova-ios",
"cordova-android",
"cordova-windows",
"cordova-browser",
"cordova:plugin"
],
"engines": {
"cordovaDependencies": {
"<7.0.0": {
"cordova-android": "<6.3.0"
},
"7.0.0": {
"cordova-android": ">=6.3.0"
},
"7.1.0": {
"cordova-android": ">=6.3.0",
"cordova": ">=7.1.0"
},
"8.0.0": {
"cordova-android": ">=6.3.0",
"cordova": ">=7.1.0"
}
}
},
"author": "Adobe PhoneGap Team",
"license": "MIT",
"scripts": {
"test": "jasmine-node --color spec"
},
"devDependencies": {
"jasmine-node": "1.14.5",
"pluginpub": "^0.0.9"
},
"dependencies": {
"nopt": "^4.0.1",
"shelljs": "^0.8.3"
}
}

View File

@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
id="com.matlipe.WakeOnLan"
version="1.0.2">
<name>Wake On Lan</name>
<description>
Send Magic Packets to Wake Up Devices
</description>
<author>Mat Lipe</author>
<license>MIT</license>
<keywords>Wake On Lan</keywords>
<engines>
<engine name="cordova" version=">=3.0.0"/>
</engines>
<js-module src="www/WakeOnLan.js" name="WakeOnLan">
<clobbers target="window.plugins.WakeOnLan"/>
</js-module>
<!-- android -->
<platform name="android">
<config-file target="res/xml/config.xml" parent="/*">
<feature name="WakeOnLan">
<param name="android-package" value="com.matlipe.WakeOnLan"/>
<param name="onload" value="true"/>
</feature>
</config-file>
<source-file src="src/WakeOnLan.java" target-dir="src/com/matlipe/WakeOnLan"/>
</platform>
</plugin>

View File

@@ -0,0 +1,89 @@
package com.matlipe;
import org.apache.cordova.CordovaPlugin;
import org.apache.cordova.CallbackContext;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
public class WakeOnLan extends CordovaPlugin {
private static final String WAKE_ACTION = "wake";
private static final int PORT = 9;
@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
boolean result = false;
if( WAKE_ACTION.equals( action ) ){
if( wake( args ) ){
callbackContext.success( "Device has been woken up" );
result = true;
} else {
callbackContext.error( "Device did not wake up" );
}
} else {
callbackContext.error( "Invalid action : " + action + " passed" );
}
return result;
}
private Boolean wake( JSONArray args ) {
Boolean result = false;
try{
String ipStr = args.getString( 0 );
String macStr = args.getString( 1 );
byte[] macBytes = getMacBytes( macStr );
byte[] bytes = new byte[ 6 + 16 * macBytes.length ];
for( int i = 0; i < 6; i++ ){
bytes[ i ] = ( byte ) 0xff;
}
for( int i = 6; i < bytes.length; i += macBytes.length ){
System.arraycopy( macBytes, 0, bytes, i, macBytes.length );
}
InetAddress address = InetAddress.getByName( ipStr );
DatagramPacket packet = new DatagramPacket( bytes, bytes.length, address, PORT );
DatagramSocket socket = new DatagramSocket();
socket.send( packet );
socket.close();
System.out.println( "Wake-on-LAN packet sent." );
result = true;
} catch( Exception e ){
System.out.println( "WakeOnLan Exception thrown" + e.toString() );
}
return result;
}
private byte[] getMacBytes( String macStr ) throws IllegalArgumentException {
byte[] bytes = new byte[ 6 ];
String[] hex = macStr.split( "(\\:|\\-)" );
if( hex.length != 6 ){
throw new IllegalArgumentException( "Invalid MAC address." );
}
try{
for( int i = 0; i < 6; i++ ){
bytes[ i ] = ( byte ) Integer.parseInt( hex[ i ], 16 );
}
} catch( NumberFormatException e ){
throw new IllegalArgumentException( "Invalid hex digit in MAC address." );
}
return bytes;
}
}

View File

@@ -0,0 +1,24 @@
/*
Copyright 2011 Simon Yeldon
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
var WakeOnLan = function(){}
WakeOnLan.prototype.wake = function(mac, ip, success, fail) {
return PhoneGap.exec( success, fail, "WakeOnLan", "wake", [mac, ip]);
}
PhoneGap.addConstructor(function() {
PhoneGap.addPlugin('wol', new WakeOnLan());
});