Files
cam-reverse/cmd/pair.ts
T
Adriano Cunha 69a8b2e172 Update opts in pair.ts
Update opts in pair.ts to include attempt_to_fix_packet_loss.

Otherwise it will fail with:

```
cmd/pair.ts:16:29 - error TS2345: Argument of type '{ debug: boolean; ansi: boolean; discovery_ip: string; }' is not assignable to parameter of type 'opt'.
  Property 'attempt_to_fix_packet_loss' is missing in type '{ debug: boolean; ansi: boolean; discovery_ip: string; }' but required in type 'opt'.
```
2024-04-23 22:05:11 -07:00

38 lines
1.1 KiB
TypeScript

import { RemoteInfo } from "dgram";
import { discoverDevices } from "../discovery.js";
import { DevSerial } from "../impl.js";
import { Handlers, makeSession, Session, configureWifi } from "../session.js";
const opts = {
debug: true,
ansi: true,
discovery_ip: "192.168.1.255",
attempt_to_fix_packet_loss: false,
};
let sessions: Record<string, Session> = {};
let devEv = discoverDevices(opts);
if (process.env.SSID == undefined || process.env.PSK == undefined) {
throw new Error("Set `SSID` and `PSK` environment variables");
}
const onLogin = configureWifi(process.env.SSID, process.env.PSK);
console.log(process.env.SSID, process.env.PSK);
devEv.on("discover", (rinfo: RemoteInfo, dev: DevSerial) => {
if (dev.devId in sessions) {
console.log(`ignoring ${dev.devId} - ${rinfo.address}`);
return;
}
console.log(`discovered ${dev.devId} - ${rinfo.address}`);
const s = makeSession(Handlers, dev, rinfo, onLogin, opts);
s.eventEmitter.on("disconnect", () => {
console.log("deleting from sessions");
sessions[dev.devId] = undefined;
});
sessions[dev.devId] = s;
});