mirror of
https://github.com/vector-im/element-call.git
synced 2026-08-08 20:09:19 +00:00
Awful hacks to use BLE PTT device via webbluetooth
This commit is contained in:
@@ -55,6 +55,7 @@
|
|||||||
"@matrix-org/olm": "https://gitlab.matrix.org/api/v4/projects/27/packages/npm/@matrix-org/olm/-/@matrix-org/olm-3.2.8.tgz",
|
"@matrix-org/olm": "https://gitlab.matrix.org/api/v4/projects/27/packages/npm/@matrix-org/olm/-/@matrix-org/olm-3.2.8.tgz",
|
||||||
"@storybook/react": "^6.5.0-alpha.5",
|
"@storybook/react": "^6.5.0-alpha.5",
|
||||||
"@types/request": "^2.48.8",
|
"@types/request": "^2.48.8",
|
||||||
|
"@types/web-bluetooth": "^0.0.14",
|
||||||
"@typescript-eslint/eslint-plugin": "^5.22.0",
|
"@typescript-eslint/eslint-plugin": "^5.22.0",
|
||||||
"@typescript-eslint/parser": "^5.22.0",
|
"@typescript-eslint/parser": "^5.22.0",
|
||||||
"babel-loader": "^8.2.3",
|
"babel-loader": "^8.2.3",
|
||||||
|
|||||||
@@ -60,6 +60,10 @@ export interface PTTState {
|
|||||||
connected: boolean;
|
connected: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let btsetupdone = false;
|
||||||
|
let characteristics;
|
||||||
|
let globalButtonHeld;
|
||||||
|
|
||||||
export const usePTT = (
|
export const usePTT = (
|
||||||
client: MatrixClient,
|
client: MatrixClient,
|
||||||
groupCall: GroupCall,
|
groupCall: GroupCall,
|
||||||
@@ -228,6 +232,64 @@ export const usePTT = (
|
|||||||
[setConnected]
|
[setConnected]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const onCharatceristicChange = useCallback(async () => {
|
||||||
|
const val = await characteristics[0].value;
|
||||||
|
const strval = new TextDecoder("utf-8").decode(val);
|
||||||
|
|
||||||
|
if (globalButtonHeld && strval.startsWith("+PTT=R")) {
|
||||||
|
stopTalking();
|
||||||
|
} else if (!globalButtonHeld && strval.startsWith("+PTT=P")) {
|
||||||
|
startTalking();
|
||||||
|
}
|
||||||
|
|
||||||
|
//setTimeout(async () => {
|
||||||
|
//console.log(e);
|
||||||
|
//return;
|
||||||
|
|
||||||
|
//onCharatceristicChange();
|
||||||
|
//}, 200);
|
||||||
|
}, [startTalking, stopTalking]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (btsetupdone) return;
|
||||||
|
btsetupdone = true;
|
||||||
|
async function doBluetooth() {
|
||||||
|
try {
|
||||||
|
const device = await navigator.bluetooth.requestDevice({
|
||||||
|
//filters: [{ services: ["00006666-0000-1000-8000-00805f9b34fb"] }],
|
||||||
|
filters: [{ services: [0x6666] }],
|
||||||
|
//optionalServices: [0x6666],
|
||||||
|
//acceptAllDevices: true,
|
||||||
|
});
|
||||||
|
console.log(device);
|
||||||
|
console.log("connecting ble");
|
||||||
|
const connectedServer = await device.gatt.connect();
|
||||||
|
console.log("connected", connectedServer);
|
||||||
|
const service = await connectedServer.getPrimaryService(
|
||||||
|
//"00006666-0000-1000-8000-00805f9b34fb"
|
||||||
|
0x6666
|
||||||
|
);
|
||||||
|
console.log(service);
|
||||||
|
characteristics = await service.getCharacteristics();
|
||||||
|
console.log("characteristics: ", characteristics);
|
||||||
|
|
||||||
|
//let readProm = Promise.resolve();
|
||||||
|
|
||||||
|
console.log("starting notifs");
|
||||||
|
await characteristics[0].startNotifications();
|
||||||
|
characteristics[0].oncharacteristicvaluechanged =
|
||||||
|
onCharatceristicChange;
|
||||||
|
console.log("listener added");
|
||||||
|
|
||||||
|
//setInterval(onCharatceristicChange, 5000);
|
||||||
|
//onCharatceristicChange();
|
||||||
|
} catch (e) {
|
||||||
|
console.log("error setting up ble ptt", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
doBluetooth();
|
||||||
|
}, [pttButtonHeld, startTalking, stopTalking, onCharatceristicChange]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
function onKeyDown(event: KeyboardEvent): void {
|
function onKeyDown(event: KeyboardEvent): void {
|
||||||
if (event.code === "Space") {
|
if (event.code === "Space") {
|
||||||
@@ -292,6 +354,8 @@ export const usePTT = (
|
|||||||
}));
|
}));
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
globalButtonHeld = pttButtonHeld;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
pttButtonHeld,
|
pttButtonHeld,
|
||||||
isAdmin,
|
isAdmin,
|
||||||
|
|||||||
@@ -39,6 +39,9 @@ export default defineConfig(({ mode }) => {
|
|||||||
proxy: {
|
proxy: {
|
||||||
"/_matrix": env.VITE_DEFAULT_HOMESERVER || "http://localhost:8008",
|
"/_matrix": env.VITE_DEFAULT_HOMESERVER || "http://localhost:8008",
|
||||||
},
|
},
|
||||||
|
hmr: {
|
||||||
|
clientPort: 443,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
resolve: {
|
resolve: {
|
||||||
dedupe: [
|
dedupe: [
|
||||||
|
|||||||
@@ -3046,6 +3046,11 @@
|
|||||||
resolved "https://registry.yarnpkg.com/@types/unist/-/unist-2.0.6.tgz#250a7b16c3b91f672a24552ec64678eeb1d3a08d"
|
resolved "https://registry.yarnpkg.com/@types/unist/-/unist-2.0.6.tgz#250a7b16c3b91f672a24552ec64678eeb1d3a08d"
|
||||||
integrity sha512-PBjIUxZHOuj0R15/xuwJYjFi+KZdNFrehocChv4g5hu6aFroHue8m0lBP0POdK2nKzbw0cgV1mws8+V/JAcEkQ==
|
integrity sha512-PBjIUxZHOuj0R15/xuwJYjFi+KZdNFrehocChv4g5hu6aFroHue8m0lBP0POdK2nKzbw0cgV1mws8+V/JAcEkQ==
|
||||||
|
|
||||||
|
"@types/web-bluetooth@^0.0.14":
|
||||||
|
version "0.0.14"
|
||||||
|
resolved "https://registry.yarnpkg.com/@types/web-bluetooth/-/web-bluetooth-0.0.14.tgz#94e175b53623384bff1f354cdb3197a8d63cdbe5"
|
||||||
|
integrity sha512-5d2RhCard1nQUC3aHcq/gHzWYO6K0WJmAbjO7mQJgCQKtZpgXxv1rOM6O/dBDhDYYVutk1sciOgNSe+5YyfM8A==
|
||||||
|
|
||||||
"@types/webpack-env@^1.16.0":
|
"@types/webpack-env@^1.16.0":
|
||||||
version "1.16.3"
|
version "1.16.3"
|
||||||
resolved "https://registry.yarnpkg.com/@types/webpack-env/-/webpack-env-1.16.3.tgz#b776327a73e561b71e7881d0cd6d34a1424db86a"
|
resolved "https://registry.yarnpkg.com/@types/webpack-env/-/webpack-env-1.16.3.tgz#b776327a73e561b71e7881d0cd6d34a1424db86a"
|
||||||
|
|||||||
Reference in New Issue
Block a user