mirror of
https://github.com/DavidVentura/cam-reverse
synced 2026-08-10 12:58:22 -04:00
14 lines
446 B
TypeScript
14 lines
446 B
TypeScript
import { createSocket, RemoteInfo } from "node:dgram";
|
|
export const mockServer = (onMessage: (msg: DataView) => Uint8Array[]) => {
|
|
const sock = createSocket("udp4");
|
|
const SEND_PORT = 32108;
|
|
sock.bind(SEND_PORT);
|
|
sock.on("message", (msg, rinfo: RemoteInfo) => {
|
|
const dv = new DataView(new Uint8Array(msg).buffer);
|
|
onMessage(dv).forEach((out) => {
|
|
sock.send(out, rinfo.port, rinfo.address);
|
|
});
|
|
});
|
|
|
|
return sock;
|
|
};
|