bluetooth-switcher
Advanced tools
Comparing version 0.1.1 to 0.1.2
parcelRequire=function(e,r,t,n){var i,o="function"==typeof parcelRequire&&parcelRequire,u="function"==typeof require&&require;function f(t,n){if(!r[t]){if(!e[t]){var i="function"==typeof parcelRequire&&parcelRequire;if(!n&&i)return i(t,!0);if(o)return o(t,!0);if(u&&"string"==typeof t)return u(t);var c=new Error("Cannot find module '"+t+"'");throw c.code="MODULE_NOT_FOUND",c}p.resolve=function(r){return e[t][1][r]||r},p.cache={};var l=r[t]=new f.Module(t);e[t][0].call(l.exports,p,l,l.exports,this)}return r[t].exports;function p(e){return f(p.resolve(e))}}f.isParcelRequire=!0,f.Module=function(e){this.id=e,this.bundle=f,this.exports={}},f.modules=e,f.cache=r,f.parent=o,f.register=function(r,t){e[r]=[function(e,r){r.exports=t},{}]};for(var c=0;c<t.length;c++)try{f(t[c])}catch(e){i||(i=e)}if(t.length){var l=f(t[t.length-1]);"object"==typeof exports&&"undefined"!=typeof module?module.exports=l:"function"==typeof define&&define.amd?define(function(){return l}):n&&(this[n]=l)}if(parcelRequire=f,i)throw i;return f}({"D3Fn":[function(require,module,exports) { | ||
"use strict";var e=this&&this.__awaiter||function(e,n,t,r){return new(t||(t=Promise))(function(o,i){function s(e){try{c(r.next(e))}catch(n){i(n)}}function a(e){try{c(r.throw(e))}catch(n){i(n)}}function c(e){var n;e.done?o(e.value):(n=e.value,n instanceof t?n:new t(function(e){e(n)})).then(s,a)}c((r=r.apply(e,n||[])).next())})},n=this&&this.__generator||function(e,n){var t,r,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(i){return function(a){return function(i){if(t)throw new TypeError("Generator is already executing.");for(;s;)try{if(t=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return s.label++,{value:i[1],done:!1};case 5:s.label++,r=i[1],i=[0];continue;case 7:i=s.ops.pop(),s.trys.pop();continue;default:if(!(o=(o=s.trys).length>0&&o[o.length-1])&&(6===i[0]||2===i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){s.label=i[1];break}if(6===i[0]&&s.label<o[1]){s.label=o[1],o=i;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(i);break}o[2]&&s.ops.pop(),s.trys.pop();continue}i=n.call(e,s)}catch(a){i=[6,a],r=0}finally{t=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,a])}}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.JsonRpc=void 0;var t=function(){function t(){this.handlers={}}return t.getAvailability=function(t){return e(this,void 0,Promise,function(){return n(this,function(e){return[2,new Promise(function(e){var n=new WebSocket(t);n.onopen=function(){n.close(),e(!0)},n.onerror=function(){e(!1)}})]})})},t.prototype.open=function(t){return e(this,void 0,Promise,function(){var e=this;return n(this,function(n){return[2,new Promise(function(n){e.webSocket=new WebSocket(t),e.webSocket.onmessage=e.handleMessage.bind(e),e.webSocket.onopen=function(){return n()}})]})})},t.prototype.setMessageHandler=function(e,n){this.handlers[e]=n},t.prototype.removeMessageHandler=function(e){this.handlers[e]&&delete this.handlers[e]},t.prototype.send=function(e,n){if(this.webSocket){var t={jsonrpc:"2.0",id:1,method:e,params:n};this.webSocket.send(JSON.stringify(t))}},t.prototype.handleMessage=function(e){var n=JSON.parse(e.data);if("2.0"===n.jsonrpc){var t=this.handlers[n.method];t&&t(n)}},t}();exports.JsonRpc=t; | ||
"use strict";var e=this&&this.__awaiter||function(e,n,t,o){return new(t||(t=Promise))(function(r,i){function s(e){try{c(o.next(e))}catch(n){i(n)}}function a(e){try{c(o.throw(e))}catch(n){i(n)}}function c(e){var n;e.done?r(e.value):(n=e.value,n instanceof t?n:new t(function(e){e(n)})).then(s,a)}c((o=o.apply(e,n||[])).next())})},n=this&&this.__generator||function(e,n){var t,o,r,i,s={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]};return i={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function a(i){return function(a){return function(i){if(t)throw new TypeError("Generator is already executing.");for(;s;)try{if(t=1,o&&(r=2&i[0]?o.return:i[0]?o.throw||((r=o.return)&&r.call(o),0):o.next)&&!(r=r.call(o,i[1])).done)return r;switch(o=0,r&&(i=[2&i[0],r.value]),i[0]){case 0:case 1:r=i;break;case 4:return s.label++,{value:i[1],done:!1};case 5:s.label++,o=i[1],i=[0];continue;case 7:i=s.ops.pop(),s.trys.pop();continue;default:if(!(r=(r=s.trys).length>0&&r[r.length-1])&&(6===i[0]||2===i[0])){s=0;continue}if(3===i[0]&&(!r||i[1]>r[0]&&i[1]<r[3])){s.label=i[1];break}if(6===i[0]&&s.label<r[1]){s.label=r[1],r=i;break}if(r&&s.label<r[2]){s.label=r[2],s.ops.push(i);break}r[2]&&s.ops.pop(),s.trys.pop();continue}i=n.call(e,s)}catch(a){i=[6,a],o=0}finally{t=r=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,a])}}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.JsonRpc=void 0;var t=function(){function t(){this.handlers={}}return t.getAvailability=function(t){return e(this,void 0,Promise,function(){return n(this,function(e){return[2,new Promise(function(e){var n=new WebSocket(t);n.onopen=function(){n.close(),e(!0)},n.onerror=function(){e(!1)}})]})})},t.prototype.open=function(t){return e(this,void 0,Promise,function(){var e=this;return n(this,function(n){return[2,new Promise(function(n){e.webSocket=new WebSocket(t),e.webSocket.onmessage=e.handleMessage.bind(e),e.webSocket.onopen=function(){return n()}})]})})},t.prototype.setMessageHandler=function(e,n){this.handlers[e]=n},t.prototype.removeMessageHandler=function(e){this.handlers[e]&&delete this.handlers[e]},t.prototype.send=function(e,n){if(this.webSocket){var t={jsonrpc:"2.0",id:1,method:e,params:n};console.log("send",t),this.webSocket.send(JSON.stringify(t))}},t.prototype.handleMessage=function(e){var n=JSON.parse(e.data);if("2.0"===n.jsonrpc){var t=this.handlers[n.method];t&&t(n)}},t}();exports.JsonRpc=t; | ||
},{}],"yh9p":[function(require,module,exports) { | ||
@@ -14,3 +14,3 @@ "use strict";exports.byteLength=u,exports.toByteArray=i,exports.fromByteArray=d;for(var r=[],t=[],e="undefined"!=typeof Uint8Array?Uint8Array:Array,n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",o=0,a=n.length;o<a;++o)r[o]=n[o],t[n.charCodeAt(o)]=o;function h(r){var t=r.length;if(t%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var e=r.indexOf("=");return-1===e&&(e=t),[e,e===t?0:4-e%4]}function u(r){var t=h(r),e=t[0],n=t[1];return 3*(e+n)/4-n}function c(r,t,e){return 3*(t+e)/4-e}function i(r){var n,o,a=h(r),u=a[0],i=a[1],f=new e(c(r,u,i)),A=0,d=i>0?u-4:u;for(o=0;o<d;o+=4)n=t[r.charCodeAt(o)]<<18|t[r.charCodeAt(o+1)]<<12|t[r.charCodeAt(o+2)]<<6|t[r.charCodeAt(o+3)],f[A++]=n>>16&255,f[A++]=n>>8&255,f[A++]=255&n;return 2===i&&(n=t[r.charCodeAt(o)]<<2|t[r.charCodeAt(o+1)]>>4,f[A++]=255&n),1===i&&(n=t[r.charCodeAt(o)]<<10|t[r.charCodeAt(o+1)]<<4|t[r.charCodeAt(o+2)]>>2,f[A++]=n>>8&255,f[A++]=255&n),f}function f(t){return r[t>>18&63]+r[t>>12&63]+r[t>>6&63]+r[63&t]}function A(r,t,e){for(var n,o=[],a=t;a<e;a+=3)n=(r[a]<<16&16711680)+(r[a+1]<<8&65280)+(255&r[a+2]),o.push(f(n));return o.join("")}function d(t){for(var e,n=t.length,o=n%3,a=[],h=0,u=n-o;h<u;h+=16383)a.push(A(t,h,h+16383>u?u:h+16383));return 1===o?(e=t[n-1],a.push(r[e>>2]+r[e<<4&63]+"==")):2===o&&(e=(t[n-2]<<8)+t[n-1],a.push(r[e>>10]+r[e>>4&63]+r[e<<2&63]+"=")),a.join("")}t["-".charCodeAt(0)]=62,t["_".charCodeAt(0)]=63; | ||
},{"./bluetoothRemoteGATTServer":"icim"}],"vB5J":[function(require,module,exports) { | ||
"use strict";var e=this&&this.__awaiter||function(e,n,t,r){return new(t||(t=Promise))(function(i,o){function c(e){try{a(r.next(e))}catch(n){o(n)}}function s(e){try{a(r.throw(e))}catch(n){o(n)}}function a(e){var n;e.done?i(e.value):(n=e.value,n instanceof t?n:new t(function(e){e(n)})).then(c,s)}a((r=r.apply(e,n||[])).next())})},n=this&&this.__generator||function(e,n){var t,r,i,o,c={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function s(o){return function(s){return function(o){if(t)throw new TypeError("Generator is already executing.");for(;c;)try{if(t=1,r&&(i=2&o[0]?r.return:o[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,o[1])).done)return i;switch(r=0,i&&(o=[2&o[0],i.value]),o[0]){case 0:case 1:i=o;break;case 4:return c.label++,{value:o[1],done:!1};case 5:c.label++,r=o[1],o=[0];continue;case 7:o=c.ops.pop(),c.trys.pop();continue;default:if(!(i=(i=c.trys).length>0&&i[i.length-1])&&(6===o[0]||2===o[0])){c=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]<i[3])){c.label=o[1];break}if(6===o[0]&&c.label<i[1]){c.label=i[1],i=o;break}if(i&&c.label<i[2]){c.label=i[2],c.ops.push(o);break}i[2]&&c.ops.pop(),c.trys.pop();continue}o=n.call(e,c)}catch(s){o=[6,s],r=0}finally{t=i=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,s])}}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.ScratchLink=void 0;var t=require("./jsonRpc"),r=require("./bluetoothDevice"),i=function(){function i(){this.isScanning=!1,this.foundDevices={}}return i.getAvailability=function(){return e(this,void 0,Promise,function(){return n(this,function(e){return[2,t.JsonRpc.getAvailability(i.WEBSOCKET_URL)]})})},i.prototype.requestDevice=function(o){return e(this,void 0,void 0,function(){var e=this;return n(this,function(n){switch(n.label){case 0:return this.rpc?[3,2]:(this.rpc=new t.JsonRpc,[4,this.rpc.open(i.WEBSOCKET_URL)]);case 1:n.sent(),n.label=2;case 2:return this.isScanning?(console.log("Already scanning."),[2,this.foundDevices]):(this.isScanning=!0,this.rpc.setMessageHandler("didDiscoverPeripheral",function(n){var t=new r.BluetoothDevice(n.params.peripheralId,n.params.name||void 0,n.params.rssi||void 0);e.foundDevices[t.id]=t}),this.rpc.send("discover",o),[2,new Promise(function(n){var t=setTimeout(function(){i()},1e3),r=setInterval(function(){Object.keys(e.foundDevices).length>0&&i()},100),i=function(){e.isScanning=!1,clearTimeout(t),clearInterval(r);var i=Object.values(e.foundDevices)[0];e.rpc&&(e.rpc.removeMessageHandler("didDiscoverPeripheral"),i&&i.setRpc(e.rpc)),n(i)}})])}})})},i.WEBSOCKET_URL="wss://device-manager.scratch.mit.edu:20110/scratch/ble",i}();exports.ScratchLink=i; | ||
"use strict";var e=this&&this.__awaiter||function(e,n,t,r){return new(t||(t=Promise))(function(i,o){function c(e){try{a(r.next(e))}catch(n){o(n)}}function s(e){try{a(r.throw(e))}catch(n){o(n)}}function a(e){var n;e.done?i(e.value):(n=e.value,n instanceof t?n:new t(function(e){e(n)})).then(c,s)}a((r=r.apply(e,n||[])).next())})},n=this&&this.__generator||function(e,n){var t,r,i,o,c={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function s(o){return function(s){return function(o){if(t)throw new TypeError("Generator is already executing.");for(;c;)try{if(t=1,r&&(i=2&o[0]?r.return:o[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,o[1])).done)return i;switch(r=0,i&&(o=[2&o[0],i.value]),o[0]){case 0:case 1:i=o;break;case 4:return c.label++,{value:o[1],done:!1};case 5:c.label++,r=o[1],o=[0];continue;case 7:o=c.ops.pop(),c.trys.pop();continue;default:if(!(i=(i=c.trys).length>0&&i[i.length-1])&&(6===o[0]||2===o[0])){c=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]<i[3])){c.label=o[1];break}if(6===o[0]&&c.label<i[1]){c.label=i[1],i=o;break}if(i&&c.label<i[2]){c.label=i[2],c.ops.push(o);break}i[2]&&c.ops.pop(),c.trys.pop();continue}o=n.call(e,c)}catch(s){o=[6,s],r=0}finally{t=i=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,s])}}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.ScratchLink=void 0;var t=require("./jsonRpc"),r=require("./bluetoothDevice"),i=function(){function i(){this.isScanning=!1,this.foundDevices={}}return i.getAvailability=function(){return e(this,void 0,Promise,function(){return n(this,function(e){return[2,t.JsonRpc.getAvailability(i.WEBSOCKET_URL)]})})},i.prototype.requestDevice=function(o){return e(this,void 0,void 0,function(){var e=this;return n(this,function(n){switch(n.label){case 0:return console.log("requestDevice",o),this.rpc?[3,2]:(this.rpc=new t.JsonRpc,[4,this.rpc.open(i.WEBSOCKET_URL)]);case 1:n.sent(),n.label=2;case 2:return this.isScanning?(console.log("Already scanning."),[2,this.foundDevices]):(this.isScanning=!0,this.rpc.setMessageHandler("didDiscoverPeripheral",function(n){var t=new r.BluetoothDevice(n.params.peripheralId,n.params.name||void 0,n.params.rssi||void 0);e.foundDevices[t.id]=t}),this.rpc.send("discover",o),[2,new Promise(function(n){var t=setTimeout(function(){i()},1e3),r=setInterval(function(){Object.keys(e.foundDevices).length>0&&i()},100),i=function(){e.isScanning=!1,clearTimeout(t),clearInterval(r);var i=Object.values(e.foundDevices)[0];e.rpc&&(e.rpc.removeMessageHandler("didDiscoverPeripheral"),i&&i.setRpc(e.rpc)),n(i)}})])}})})},i.WEBSOCKET_URL="wss://device-manager.scratch.mit.edu:20110/scratch/ble",i}();exports.ScratchLink=i; | ||
},{"./jsonRpc":"D3Fn","./bluetoothDevice":"rHCK"}],"btcH":[function(require,module,exports) { | ||
@@ -17,0 +17,0 @@ "use strict";var e=this&&this.__createBinding||(Object.create?function(e,t,r,i){void 0===i&&(i=r),Object.defineProperty(e,i,{enumerable:!0,get:function(){return t[r]}})}:function(e,t,r,i){void 0===i&&(i=r),e[i]=t[r]}),t=this&&this.__exportStar||function(t,r){for(var i in t)"default"===i||Object.prototype.hasOwnProperty.call(r,i)||e(r,t,i)};Object.defineProperty(exports,"__esModule",{value:!0}),t(require("./scratchLink"),exports); |
{ | ||
"name": "bluetooth-switcher", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"main": "dist/index.js", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -51,3 +51,3 @@ export class JsonRpc { | ||
// console.log('send', message); | ||
console.log('send', message); | ||
@@ -54,0 +54,0 @@ this.webSocket.send(JSON.stringify(message)); |
@@ -18,2 +18,3 @@ import { JsonRpc } from './jsonRpc'; | ||
async requestDevice(options?: { filters?: { serviceUuid?: string }[] }) { | ||
console.log('requestDevice', options); | ||
if (!this.rpc) { | ||
@@ -20,0 +21,0 @@ this.rpc = new JsonRpc(); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
58950
363