This commit is contained in:
nik
2025-10-03 22:27:28 +03:00
parent 829fad0e17
commit 871cf7e792
16520 changed files with 2967597 additions and 3 deletions

View File

@@ -0,0 +1,29 @@
/**
* Copyright 2024 Google LLC.
* Copyright (c) Microsoft Corporation.
*
* 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.
*/
import type { Bluetooth, EmptyResult } from '../../../protocol/protocol.js';
import type { CdpTarget } from '../cdp/CdpTarget.js';
import type { BrowsingContextStorage } from '../context/BrowsingContextStorage.js';
import type { EventManager } from '../session/EventManager.js';
export declare class BluetoothProcessor {
#private;
constructor(eventManager: EventManager, browsingContextStorage: BrowsingContextStorage);
simulateAdapter(params: Bluetooth.SimulateAdapterParameters): Promise<EmptyResult>;
simulatePreconnectedPeripheral(params: Bluetooth.SimulatePreconnectedPeripheralParameters): Promise<EmptyResult>;
simulateAdvertisement(params: Bluetooth.SimulateAdvertisementParameters): Promise<EmptyResult>;
onCdpTargetCreated(cdpTarget: CdpTarget): void;
handleRequestDevicePrompt(params: Bluetooth.HandleRequestDevicePromptParameters): Promise<EmptyResult>;
}

View File

@@ -0,0 +1,81 @@
/**
* Copyright 2024 Google LLC.
* Copyright (c) Microsoft Corporation.
*
* 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.
*/
export class BluetoothProcessor {
#eventManager;
#browsingContextStorage;
constructor(eventManager, browsingContextStorage) {
this.#eventManager = eventManager;
this.#browsingContextStorage = browsingContextStorage;
}
async simulateAdapter(params) {
const context = this.#browsingContextStorage.getContext(params.context);
// Bluetooth spec requires overriding the existing adapter (step 6). From the CDP
// perspective, we need to disable the emulation first.
// https://webbluetoothcg.github.io/web-bluetooth/#bluetooth-simulateAdapter-command
await context.cdpTarget.browserCdpClient.sendCommand('BluetoothEmulation.disable');
await context.cdpTarget.browserCdpClient.sendCommand('BluetoothEmulation.enable', {
state: params.state,
});
return {};
}
async simulatePreconnectedPeripheral(params) {
const context = this.#browsingContextStorage.getContext(params.context);
await context.cdpTarget.browserCdpClient.sendCommand('BluetoothEmulation.simulatePreconnectedPeripheral', {
address: params.address,
name: params.name,
knownServiceUuids: params.knownServiceUuids,
manufacturerData: params.manufacturerData,
});
return {};
}
async simulateAdvertisement(params) {
const context = this.#browsingContextStorage.getContext(params.context);
await context.cdpTarget.browserCdpClient.sendCommand('BluetoothEmulation.simulateAdvertisement', {
entry: params.scanEntry,
});
return {};
}
onCdpTargetCreated(cdpTarget) {
cdpTarget.cdpClient.on('DeviceAccess.deviceRequestPrompted', (event) => {
this.#eventManager.registerEvent({
type: 'event',
method: 'bluetooth.requestDevicePromptUpdated',
params: {
context: cdpTarget.id,
prompt: event.id,
devices: event.devices,
},
}, cdpTarget.id);
});
}
async handleRequestDevicePrompt(params) {
const context = this.#browsingContextStorage.getContext(params.context);
if (params.accept) {
await context.cdpTarget.cdpClient.sendCommand('DeviceAccess.selectPrompt', {
id: params.prompt,
deviceId: params.device,
});
}
else {
await context.cdpTarget.cdpClient.sendCommand('DeviceAccess.cancelPrompt', {
id: params.prompt,
});
}
return {};
}
}
//# sourceMappingURL=BluetoothProcessor.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"BluetoothProcessor.js","sourceRoot":"","sources":["../../../../../src/bidiMapper/modules/bluetooth/BluetoothProcessor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAOH,MAAM,OAAO,kBAAk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