allow onLogin CB to be specified

This commit is contained in:
DavidVentura
2024-01-31 16:32:06 +01:00
parent f7eb287d5b
commit 9685f8008e
4 changed files with 20 additions and 9 deletions
+2 -4
View File
@@ -20,8 +20,6 @@ const handleIncomingPunch = (msg: Buffer, ee: EventEmitter, rinfo: RemoteInfo, o
export const discoverDevices = (options: opt): EventEmitter => {
const sock = createSocket("udp4");
//const BCAST_IP = "192.168.1.255";
const BCAST_IP = "192.168.40.101";
const SEND_PORT = 32108;
const ee = new EventEmitter();
@@ -39,9 +37,9 @@ export const discoverDevices = (options: opt): EventEmitter => {
let buf = create_LanSearch();
setInterval(() => {
console.log(".");
sock.send(new Uint8Array(buf.buffer), SEND_PORT, BCAST_IP);
sock.send(new Uint8Array(buf.buffer), SEND_PORT, options.discovery_ip);
}, 2000);
sock.send(new Uint8Array(buf.buffer), SEND_PORT, BCAST_IP);
sock.send(new Uint8Array(buf.buffer), SEND_PORT, options.discovery_ip);
});
sock.bind();
+9 -4
View File
@@ -1,11 +1,16 @@
import { createWriteStream } from "node:fs";
import http from "node:http";
import { RemoteInfo } from "dgram";
import { Handlers, makeSession, Session } from "./session.js";
import { Handlers, makeSession, Session, startVideoStream } from "./session.js";
import { discoverDevices } from "./discovery.js";
import { DevSerial } from "./impl.js";
const opts = { debug: false, ansi: false };
const opts = {
debug: false,
ansi: false,
discovery_ip: "192.168.40.101", //, "192.168.1.255";
};
let BOUNDARY = "a very good boundary line";
let responses = [];
@@ -38,13 +43,13 @@ const server = http.createServer((req, res) => {
});
let devEv = discoverDevices(opts);
devEv.on("discover", (rinfo, dev: DevSerial) => {
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, opts);
const s = makeSession(Handlers, dev, rinfo, startVideoStream, opts);
const withAudio = false;
s.eventEmitter.on("frame", (frame: Buffer) => {
let s = `--${BOUNDARY}\r\n`;
+1
View File
@@ -1,4 +1,5 @@
export type opt = {
debug: boolean;
ansi: boolean;
discovery_ip: string;
};
+8 -1
View File
@@ -45,6 +45,7 @@ export const makeSession = (
handlers: Record<keyof typeof Commands, PacketHandler>,
dev: DevSerial,
ra: RemoteInfo,
onLogin: (s: Session) => void,
options: opt,
): Session => {
const sock = createSocket("udp4");
@@ -111,7 +112,13 @@ export const makeSession = (
return session;
};
const startVideoStream = (s: Session) => {
export const configureWifi = (ssid: string, password: string) => {
return (s: Session) => {
[SendWifiDetails(s, ssid, password, true)].forEach(s.send);
};
};
export const startVideoStream = (s: Session) => {
[
...SendVideoResolution(s, 2), // 640x480
SendStartVideo(s),