Files
Behavision/desktop/frontend/src/bridge.js
Suriyakumarvijayanayagam 1607f4ce74 Find the camera on the network instead of asking for its address
The add-camera form asked for an IP address, and a shop owner does not
know their camera's IP address - it is on a sticker under the camera or
in a menu that differs by make. That field is where onboarding stopped
for anyone who was not an installer.

behavision/discover.py: one ONVIF WS-Discovery multicast (names the
camera and often its make) merged with a TCP sweep of port 554 across
the local /24 (misses nothing that streams). Stdlib only, ~4 s on the
office network, both cameras found. The add-camera sheet leads with
'Find cameras on this network'; picking a row fills the address and,
when the make is recognisable, the stream path.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KGcjxF1cNLcuwc3DAPcnfj
2026-09-21 12:27:47 +05:30

67 lines
2.8 KiB
JavaScript

// The single seam between React and Go.
//
// Wails injects bound methods at window.go.main.App.*. Calling them through
// here rather than importing generated bindings means `npm run build` works
// without running `wails generate`, and it gives one place to handle the
// "engine not running yet" case that every screen has to survive.
const app = () => window?.go?.main?.App
export const isDesktop = () => Boolean(app())
async function call(name, ...args) {
const a = app()
if (!a || typeof a[name] !== 'function') {
throw new Error(`${name} is unavailable — run this inside the Behavision app`)
}
return a[name](...args)
}
// Every binding the UI uses, named as the UI thinks of them.
export const api = {
session: () => call('Session'),
login: (email, password) => call('Login', email, password),
logout: () => call('Logout'),
// The one-shot installation code that links this PC to a shop.
claim: (code) => call('Claim', code),
// Set this PC up on its own, with no head office at all.
runStandalone: () => call('RunStandalone'),
engineStatus: () => call('EngineStatus'),
startEngine: () => call('StartEngine'),
stopEngine: () => call('StopEngine'),
cameras: () => call('Cameras'),
testCamera: (cam) => call('TestCamera', cam),
discoverCameras: () => call('DiscoverCameras'),
saveCamera: (id, cam) => call('SaveCamera', id, cam),
deleteCamera: (id) => call('DeleteCamera', id),
startPlacement: (id, seconds) => call('StartPlacementCheck', id, seconds),
placementResult: (id) => call('PlacementResult', id),
streamURL: (id) => call('StreamURL', id),
live: () => call('Live'),
pipelineStatus: () => call('PipelineStatus'),
localIdentities: (n) => call('LocalIdentities', n),
localSightings: (n) => call('LocalSightings', n),
footfall: (from, to, bucket) => call('Footfall', from, to, bucket),
sites: () => call('Sites'),
visitorHistory: (id, limit) => call('VisitorHistory', id, limit),
visitorPhoto: (id) => call('VisitorPhoto', id),
forgetCustomer: (id) => call('ForgetCustomer', id),
sales: (from, to) => call('Sales', from, to),
customers: (q, limit) => call('Customers', q, limit),
saveProfile: (p) => call('SaveProfile', p),
ask: (history) => call('Ask', history),
recordPurchase: (id, amount, items, notes) =>
call('RecordPurchase', id, amount, items, notes),
}
// Errors from Go arrive as strings or Error objects depending on the path.
// Normalising here keeps every catch block in the UI to one line.
export function message(err) {
if (!err) return 'Something went wrong.'
if (typeof err === 'string') return err
return err.message || String(err)
}