All files / integration connection.ts

100% Statements 6/6
100% Branches 0/0
100% Functions 0/0
100% Lines 6/6

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34                36x       3x 1x       2x               1x           1x    
import { connectSmartCube } from 'smartcube-web-bluetooth';
import type { ConnectSmartCubeOptions } from 'smartcube-web-bluetooth';
import type { SmartCubeTransportConnection } from '@wstein/regrip-core/bindings/smartCubeTransport';
export {
  disconnectConnection,
  requestInitialState,
} from '@wstein/regrip-core/session/connectionLifecycle';
 
export const macAddressProvider = async (
  device: BluetoothDevice,
  isFallbackCall?: boolean,
): Promise<string | null> => {
  if (isFallbackCall) {
    return prompt(
      'Unable to determine cube MAC address!\nEnable chrome://flags/#enable-experimental-web-platform-features and reload, or enter it manually:',
    );
  }
  return typeof device.watchAdvertisements === 'function'
    ? null
    : prompt(
        'Web Bluetooth advertisement watching is unavailable.\nEnable chrome://flags/#enable-experimental-web-platform-features and reload, or enter the cube MAC address manually:',
      );
};
 
export async function connectCube(): Promise<SmartCubeTransportConnection> {
  const options: ConnectSmartCubeOptions & { diagnostics?: boolean } = {
    macAddressProvider,
    // Enhanced transports expose rejected decoder packets; stock v4 safely
    // ignores this forward-compatible option.
    diagnostics: true,
  };
  return connectSmartCube(options);
}