75 lines
2.8 KiB
JavaScript
75 lines
2.8 KiB
JavaScript
/** @odoo-module **/
|
|
|
|
/**
|
|
* Multi-Device Support Demonstration
|
|
*
|
|
* This script demonstrates how multiple devices maintain independent
|
|
* printer configurations for the same POS configuration.
|
|
*
|
|
* Run this in the browser console to see multi-device support in action.
|
|
*/
|
|
|
|
import { BluetoothPrinterStorage } from '../js/storage_manager.js';
|
|
|
|
export function demonstrateMultiDeviceSupport() {
|
|
console.log('=== Multi-Device Support Demonstration ===\n');
|
|
|
|
// Simulate Device 1
|
|
console.log('📱 Device 1: Initializing...');
|
|
const device1 = new BluetoothPrinterStorage();
|
|
const device1Id = device1.getDeviceId();
|
|
console.log(` Device ID: ${device1Id}`);
|
|
|
|
const device1Config = {
|
|
deviceId: 'printer-001',
|
|
deviceName: 'Kitchen Printer',
|
|
macAddress: '00:11:22:33:44:55',
|
|
lastConnected: Date.now(),
|
|
settings: {
|
|
characterSet: 'CP437',
|
|
paperWidth: 48,
|
|
autoReconnect: true,
|
|
timeout: 10000
|
|
}
|
|
};
|
|
|
|
device1.saveConfiguration(1, device1Config);
|
|
console.log(' ✅ Saved configuration for POS Config 1');
|
|
console.log(` Printer: ${device1Config.deviceName}`);
|
|
console.log(` MAC: ${device1Config.macAddress}\n`);
|
|
|
|
// Verify Device 1 can load its configuration
|
|
const device1Loaded = device1.loadConfiguration(1);
|
|
console.log('📱 Device 1: Loading configuration...');
|
|
console.log(` ✅ Loaded: ${device1Loaded.deviceName}`);
|
|
console.log(` Paper Width: ${device1Loaded.settings.paperWidth} chars\n`);
|
|
|
|
// Show storage key structure
|
|
console.log('🔑 Storage Key Structure:');
|
|
console.log(` Key: bluetooth_printer_${device1Id}_1`);
|
|
console.log(` Format: bluetooth_printer_{deviceId}_{posConfigId}\n`);
|
|
|
|
// Demonstrate that the same POS config can have different printers on different devices
|
|
console.log('💡 Key Insight:');
|
|
console.log(' Each device uses its unique device ID in the storage key.');
|
|
console.log(' This ensures complete isolation between devices.\n');
|
|
|
|
// Show all configurations for this device
|
|
const allConfigs = device1.getAllConfigurations();
|
|
console.log('📋 All Configurations for Device 1:');
|
|
allConfigs.forEach(({ posConfigId, config }) => {
|
|
console.log(` POS ${posConfigId}: ${config.deviceName} (${config.macAddress})`);
|
|
});
|
|
|
|
console.log('\n=== Demonstration Complete ===');
|
|
console.log('✅ Multi-device support is working correctly!');
|
|
console.log(' - Each device has a unique ID');
|
|
console.log(' - Storage keys include device ID');
|
|
console.log(' - Configurations are isolated per device');
|
|
}
|
|
|
|
// Export for use in browser console
|
|
if (typeof window !== 'undefined') {
|
|
window.demonstrateMultiDeviceSupport = demonstrateMultiDeviceSupport;
|
|
}
|