Developer guide · API v1

Integrate with your website

LAN Device Bridge lets websites call LAN device APIs after user approval. The website does not manage device passwords.

Websites receive API responses only for approved devices and scopes. They cannot elevate their own permissions or read device passwords.

1. Add the SDK to your project

Copy lan-device-bridge.js into your website source and import it locally. Avoid importing directly from this domain to prevent CORS dependencies and unexpected version changes.

JavaScript / TypeScript example

import { lanDeviceBridge } from './lan-device-bridge.js';

const listed = await lanDeviceBridge.listDevices();
if (!listed.ok || listed.data.length === 0) {
  // Show instructions: install the extension, add a device and grant this origin access.
  showBridgeHelp();
  return;
}

const device = listed.data[0];
const access = await lanDeviceBridge.getAccess(device.id);
if (access.data.scope !== 'full_api') {
  // Guide: click the extension icon → choose a device → Full Device API → reload.
  showPermissionHelp(device.name);
  return;
}

const response = await lanDeviceBridge.call({
  deviceId: device.id,
  method: 'GET',
  path: device.vendor === 'hikvision'
    ? '/ISAPI/System/deviceInfo'
    : '/cgi-bin/magicBox.cgi?action=getDeviceType'
});

if (!response.ok) throw new Error(response.error.message);
if (!response.data.ok) throw new Error(`Device returned HTTP ${response.data.status}`);
console.log(response.data.text);

2. Recommended UI flow

A

Check the bridge

Call listDevices(). If there is no response, show setup instructions instead of retrying continuously.

B

Choose a device

Only show devices the website is permitted to see. Store deviceId in the app configuration if needed.

C

Check the scope

Call getAccess(deviceId) before write operations. If access is missing, direct the user to the extension popup.

3. API contract

FunctionResult
listDevices()Devices visible to the website; excludes passwords.
getAccess(deviceId)Scope: none, read or full_api.
call({ deviceId, method, path, headers, body })The response contains status, text and contentType.

4. Integration rules

5. Coding assistant prompt

Replace the bracketed sections, then paste the prompt into your coding assistant.

Integration prompt