123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- <!DOCTYPE HTML>
- <html>
- <head>
- <script src="./webadb.js"></script>
- <script>
- let adb;
- let webusb;
- let log = (...args) => {
- if (args[0] instanceof Error) {
- console.error.apply(console, args);
- } else {
- console.log.apply(console, args);
- }
- document.getElementById('log').innerText += args.join(' ') + '\n';
- };
- let init = async () => {
- log('init');
- webusb = await Adb.open("WebUSB");
- };
- let connect = async () => {
- await init();
- log('connect');
- if (webusb.isAdb()) {
- try {
- adb = null;
- // console.log(webusb)
- adb = await webusb.connectAdb("host::", () => {
- log("Please check the screen of your " + webusb.device.productName + ".");
- });
- } catch(error) {
- console.log('error',error)
- log(error);
- adb = null;
- }
- }
- };
- let disconnect = async () => {
- log('disconnect');
- webusb.close();
- };
- let get_ip = async () => {
- try {
- if (!adb) throw new Error('Not connected');
- log('get_ip');
- let shell = await adb.shell('ip addr show to 0.0.0.0/0 scope global');
- let response = await shell.receive();
- let decoder = new TextDecoder('utf-8');
- if(response && response.data){
- let txt = decoder.decode(response.data);
- log(txt);
- }else{
- log('no response')
- }
-
- } catch (error) {
- log(error);
- }
- };
- let tcpip = async () => {
- try {
- if (!adb) throw new Error('Not connected');
- let port = document.getElementById('port').value;
- log('requesting tcpip mode on port', port);
- await adb.tcpip(port);
- log('tcpip connection ready');
- } catch (error) {
- log(error);
- }
- };
- let send = async ()=>{
- try{
- if(!adb) throw new Error('Not connected')
- let a = await adb.send('push ./output.mp4 /root/')
- // log(a)
- }catch(error){
- log(error)
- }
- }
- let add_ui = () => {
- // Adb.Opt.use_checksum = false;
- Adb.Opt.debug = true;
- // Adb.Opt.dump = true;
- document.getElementById('connect').onclick = connect;
- document.getElementById('get_ip').onclick = get_ip;
- document.getElementById('disconnect').onclick = disconnect;
- document.getElementById('tcpip').onclick = tcpip;
- document.getElementById('send').onclick = send;
- document.getElementById('clear').onclick = () => {
- document.getElementById('log').innerText = '';
- };
- };
- document.addEventListener('DOMContentLoaded', add_ui, false);
- </script>
- </head>
- <body>
- <button id="connect">Connect</button>
- <br />
- <br />
-
- <button id="send">send</button>
- <button id="get_ip">Get IP addr</button>
- <br />
- <br />
- <input type="text" id="port" value="5037" />
- <button id="tcpip" value="tcpip">tcpip</button>
- <br />
- <br />
- <button id="disconnect">Disconnect</button>
- <br />
- <br />
- <h2>Messages <button id="clear">clear</button></h2>
- <pre id="log"></pre>
- </body>
- </html>
|