@homebridge-plugins/homebridge-cloudflared-tunnel
Version:
The Cloudflared Tunnel plugin allows you to run a Cloudflare-Tunnel for exposing your homebridge instance for remote access.
47 lines • 1.93 kB
JavaScript
import fs from 'node:fs';
/* Copyright(C) 2023`-2024, donavanbecker (https://github.com/donavanbecker). All rights reserved.
*
* server.ts: @homebridge-plugins/homebridge-cloudflared-tunnel.
*/
import { HomebridgePluginUiServer } from '@homebridge/plugin-ui-utils';
class PluginUiServer extends HomebridgePluginUiServer {
constructor() {
super();
/*
A native method getCachedAccessories() was introduced in config-ui-x v4.37.0
The following is for users who have a lower version of config-ui-x
*/
this.onRequest('getCachedAccessories', () => {
try {
const plugin = '@homebridge-plugins/homebridge-cloudflared-tunnel';
const devicesToReturn = [];
// The path and file of the cached accessories
const accFile = `${this.homebridgeStoragePath}/accessories/cachedAccessories`;
// Check the file exists
if (fs.existsSync(accFile)) {
// read the cached accessories file
const cachedAccessories = JSON.parse(fs.readFileSync(accFile, 'utf8'));
cachedAccessories.forEach((accessory) => {
// Check the accessory is from this plugin
if (accessory.plugin === plugin) {
// Add the cached accessory to the array
devicesToReturn.push(accessory.accessory);
}
});
}
// Return the array
return devicesToReturn;
}
catch {
// Just return an empty accessory list in case of any errors
return [];
}
});
this.ready();
}
}
function startPluginUiServer() {
return new PluginUiServer();
}
startPluginUiServer();
//# sourceMappingURL=server.js.map