|
| 1 | +// |
| 2 | +// Copyright (c) 2018 Cisco Systems |
| 3 | +// Licensed under the MIT License |
| 4 | +// |
| 5 | + |
| 6 | +/** |
| 7 | + * In this example, we'll update the Branding logo in Halfwake mode |
| 8 | + */ |
| 9 | + |
| 10 | +// |
| 11 | +// Connect to the device |
| 12 | +// |
| 13 | + |
| 14 | +const jsxapi = require('jsxapi'); |
| 15 | + |
| 16 | +// Check args |
| 17 | +if (!process.env.JSXAPI_DEVICE_URL || !process.env.JSXAPI_USERNAME) { |
| 18 | + console.info("Please specify info to connect to your device as JSXAPI_DEVICE_URL, JSXAPI_USERNAME, JSXAPI_PASSWORD env variables"); |
| 19 | + console.info("Bash example: JSXAPI_DEVICE_URL='ssh://192.168.1.34' JSXAPI_USERNAME='integrator' JSXAPI_PASSWORD='integrator' node example.js"); |
| 20 | + process.exit(1); |
| 21 | +} |
| 22 | + |
| 23 | +// Empty passwords are supported |
| 24 | +const password = process.env.JSXAPI_PASSWORD ? process.env.JSXAPI_PASSWORD : ""; |
| 25 | + |
| 26 | +// Connect to the device |
| 27 | +console.debug("connecting to your device..."); |
| 28 | +const xapi = jsxapi.connect(process.env.JSXAPI_DEVICE_URL, { |
| 29 | + username: process.env.JSXAPI_USERNAME, |
| 30 | + password: password |
| 31 | +}); |
| 32 | +xapi.on('error', (err) => { |
| 33 | + console.error(`connexion failed: ${err}, exiting`); |
| 34 | + process.exit(1); |
| 35 | +}); |
| 36 | +xapi.on('ready', () => { |
| 37 | + console.log("connexion successful"); |
| 38 | + |
| 39 | + let encoded; |
| 40 | + try { |
| 41 | + // Read binary data |
| 42 | + const fs = require('fs'); |
| 43 | + const bitmap = fs.readFileSync("./img/create-logo-transparent.png"); |
| 44 | + |
| 45 | + // Convert binary data to base64 encoded string |
| 46 | + encoded = new Buffer(bitmap).toString('base64'); |
| 47 | + |
| 48 | + console.log("image encoding successful"); |
| 49 | + } |
| 50 | + catch (err) { |
| 51 | + console.error(`could not read image: ${err.message}, exiting`); |
| 52 | + process.exit(1); |
| 53 | + } |
| 54 | + |
| 55 | + // Update Awake message |
| 56 | + xapi.command('UserInterface Branding Upload', { |
| 57 | + Type: 'HalfwakeBranding', |
| 58 | + body: encoded |
| 59 | + }) |
| 60 | + .then(() => { |
| 61 | + console.info('updated Branding logo in Halfwake mode'); |
| 62 | + |
| 63 | + // Switch to Halwake mode |
| 64 | + xapi.command('Standby Halfwake') |
| 65 | + .then(() => xapi.close()); |
| 66 | + }) |
| 67 | + .catch((err) => { |
| 68 | + console.error(`could not update Brand logo: ${err.message}`); |
| 69 | + xapi.close(); |
| 70 | + }); |
| 71 | +}); |
0 commit comments