UNPKG

lavva.webbluetooth

Version:

Library implementing WebBluetooth custom functionality if underlying platform does support it

79 lines 2.44 kB
// index.ts at the root of lavva.webbluetooth package export * from './DeviceStore'; export * from './LavvaBluetooth'; export class NativeBluetoothDeviceInfo { constructor() { this.rssi = 0; this.uuids = null; this.deviceName = ""; this.deviceAddress = ""; } } export class NativeEvent { constructor() { this.handlers = []; } GetHandlers() { return this.handlers; } RemoveAllSubscriptions() { this.handlers = []; } Subscribe(handler) { this.handlers.push(handler); } Unsubscribe(handler) { this.handlers = this.handlers.filter(h => h !== handler); } Invoke() { this.handlers.slice(0).forEach(h => { try { h(); } catch (ex) { console.error(ex); } }); } } export class NativeTypedEvent { constructor(name) { this.handlers = []; this.name = name; } Subscribe(handler) { //NativeAPI.Log(`[NativeTypedEvent] Subscribing to event: ${this.name} handler: ${JSON.stringify(handler)} is handler null`); this.handlers.push(handler); } Unsubscribe(handler) { this.handlers = this.handlers.filter(h => h !== handler); } RemoveAllSubscriptions() { this.handlers = []; } Invoke(data) { //NativeAPI.Log(`[NativeTypedEvent] Invoking event ${this.name} handlers: ${this.handlers.length} data: ${JSON.stringify(data)}`); this.handlers.slice(0).forEach(h => { try { if (h !== undefined && h !== null) h(data); } catch (ex) { console.error(`[NativeTypedEvent] Error invoking event ${this.name} handler: ${JSON.stringify(h)} error: ${ex}`); } }); } } export class ExtendedWebBluetooth { static IsCustomSearchScreenSupported() { let customBluetooth = navigator.bluetooth; return navigator.bluetooth !== undefined && customBluetooth.SUPPORTS_OWN_SEARCH_SCREEN !== undefined; } static SetSearchScreen(screen) { if (!ExtendedWebBluetooth.IsCustomSearchScreenSupported()) throw new Error("Custom search screen is not supported"); let customBluetooth = navigator.bluetooth; customBluetooth.SetSearchScreen(screen); } } //# sourceMappingURL=ExtendedWebBluetooth.js.map