VulpesOS/assets/webapps/bluetooth.gaiamobile.org/shared/js/bluetooth_helper.js
OverSu b38dea0597 Publish Vulpes Preview 15 sources for desktop, Android and Tundra
Share Gaia assets and adapters, keep private profiles and development documents local, and update both public READMEs.
2026-09-30 23:13:03 +02:00

1 line
No EOL
3 KiB
JavaScript

var BluetoothHelper=function(){var n={HFP:4382,A2DP:4365},t=window.navigator.mozBluetooth,e=!1,o=[],i=null,c=null,a=!0,s=function(n){n&&t&&(e?n():o.push(n))},d=function(n,t,e){n.onsuccess=function(){t&&t(n.result)},n.onerror=function(){console.log("Error handling bluetooth request"),e&&e()}},u=function(){i?(e=!0,o.forEach(function(n){n()}),o=[]):console.log("BluetoothHelper(): connot get default adapter yet")},r=function(){t.onattributechanged=function(n){for(var e in n.attrs)switch(n.attrs[e]){case"defaultAdapter":console.log("defaultAdapter changed. address:",t.defaultAdapter.address),i=t.defaultAdapter,u()}},i=t.defaultAdapter,i&&u()},f=function(){var n=t.getDefaultAdapter();n&&(n.onsuccess=function(){i&&(c=i),e=!0,i=n.result,c&&c.onpairedstatuschanged&&(i.onpairedstatuschanged=c.onpairedstatuschanged),o.forEach(function(n){n()}),o=[]},n.onerror=function(){console.log("BluetoothHelper(): connot get default adapter!!!")})},l=function(){a?r():f()},g=function(){i&&(c=i),e=!1,i=null};return t&&("undefined"==typeof t.onattributechanged&&(a=!1),a?t.onadapteradded=function(n){l()}:(t.addEventListener("enabled",l),t.addEventListener("adapteradded",l),t.addEventListener("disabled",g)),l()),{profiles:n,answerWaitingCall:function(){s(function(){i.answerWaitingCall()})},ignoreWaitingCall:function(){s(function(){i.ignoreWaitingCall()})},toggleCalls:function(){s(function(){i.toggleCalls()})},getConnectedDevicesByProfile:function(n,t){s(function(){d(i.getConnectedDevices(n),t)})},connectSco:function(n){s(function(){d(i.connectSco(),n)})},disconnectSco:function(n){s(function(){d(i.disconnectSco(),n)})},getPairedDevices:function(n){s(function(){d(i.getPairedDevices(),n)})},getAddress:function(n){return a?void console.log("getAddress function is deprecated"):void s(function(){var t=i.address;n(t)})},setPairingConfirmation:function(n,t){return a?void console.log("setPairingConfirmation API is deprecated"):void s(function(){i.setPairingConfirmation(n,t)})},setPinCode:function(n,t){return a?void console.log("setPairingConfirmation API is deprecated"):void s(function(){i.setPinCode(n,t)})},setPasskey:function(n,t){return a?void console.log("setPairingConfirmation API is deprecated"):void s(function(){i.setPasskey(n,t)})},isScoConnected:function(n,t){s(function(){d(i.isScoConnected(),n,t)})},sendMediaMetaData:function(n,t,e){s(function(){d(i.sendMediaMetaData(n),t,e)})},sendMediaPlayStatus:function(n,t,e){s(function(){d(i.sendMediaPlayStatus(n),t,e)})},set onhfpstatuschanged(n){s(function(){i.onhfpstatuschanged=n})},set onscostatuschanged(n){s(function(){i.onscostatuschanged=n})},set ona2dpstatuschanged(n){s(function(){i.ona2dpstatuschanged=n})},set onrequestmediaplaystatus(n){s(function(){i.onrequestmediaplaystatus=n})},set onpairedstatuschanged(n){return a?void console.log("onpairedstatuschanged API is deprecated"):void s(function(){i.onpairedstatuschanged=n})},v2:a,enable:function(){a?s(function(){i.enable()}):console.log("enable is not support in v1 API!")},disable:function(){a?s(function(){i.disable()}):console.log("disable is not support in v1 API!")}}};