add typing
This commit is contained in:
@@ -59,9 +59,8 @@ const EstablishSession = () => {
|
|||||||
const ls = create_LanSearch(); // Broadcast
|
const ls = create_LanSearch(); // Broadcast
|
||||||
};
|
};
|
||||||
|
|
||||||
const MakeSock = (
|
type sock = { send: (msg: DataView) => void; broadcast: (msg: DataView) => void };
|
||||||
cb: (msg: Buffer, rinfo: any) => void,
|
const MakeSock = (cb: (msg: Buffer, rinfo: any) => void): sock => {
|
||||||
): { send: (msg: DataView) => void; broadcast: (msg: DataView) => void } => {
|
|
||||||
const server = dgram.createSocket("udp4");
|
const server = dgram.createSocket("udp4");
|
||||||
|
|
||||||
server.on("error", (err) => {
|
server.on("error", (err) => {
|
||||||
@@ -95,13 +94,13 @@ const MakeSock = (
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
const notImpl = (sock, dv: DataView) => {
|
const notImpl = (sock: sock, dv: DataView) => {
|
||||||
const raw = dv.readU16();
|
const raw = dv.readU16();
|
||||||
const cmd = CommandsByValue[raw];
|
const cmd = CommandsByValue[raw];
|
||||||
console.log(`^^ ${cmd} (${raw.toString(16)}) and it's not implemented yet`);
|
console.log(`^^ ${cmd} (${raw.toString(16)}) and it's not implemented yet`);
|
||||||
};
|
};
|
||||||
|
|
||||||
const noop = (sock, dv: DataView) => {};
|
const noop = (sock: sock, dv: DataView) => {};
|
||||||
const create_P2pAliveAck = (): DataView => {
|
const create_P2pAliveAck = (): DataView => {
|
||||||
const outbuf = new DataView(new Uint8Array(4).buffer);
|
const outbuf = new DataView(new Uint8Array(4).buffer);
|
||||||
outbuf.writeU16(Commands.P2PAliveAck);
|
outbuf.writeU16(Commands.P2PAliveAck);
|
||||||
@@ -118,7 +117,8 @@ const create_P2pRdy = (inbuf: DataView): DataView => {
|
|||||||
return outbuf;
|
return outbuf;
|
||||||
};
|
};
|
||||||
|
|
||||||
const handle_Drw = (sock, dv: DataView) => {
|
let seen = [0];
|
||||||
|
const handle_Drw = (sock: sock, dv: DataView) => {
|
||||||
// TODO
|
// TODO
|
||||||
// INPUT
|
// INPUT
|
||||||
// byte 4 = d1 or d2, just add 1
|
// byte 4 = d1 or d2, just add 1
|
||||||
@@ -172,7 +172,8 @@ const handle_Drw = (sock, dv: DataView) => {
|
|||||||
// 1 data?? video+aud
|
// 1 data?? video+aud
|
||||||
// Send_Pkt_DrwAck(10,0xd2,channel,1,&cmd_,sock_fd,ipaddr_);
|
// Send_Pkt_DrwAck(10,0xd2,channel,1,&cmd_,sock_fd,ipaddr_);
|
||||||
};
|
};
|
||||||
const handle_P2PRdy = (sock, dv: DataView) => {
|
const challenge = [0, 0, 0, 0];
|
||||||
|
const handle_P2PRdy = (sock: sock, dv: DataView) => {
|
||||||
const b = SendUsrChk("admin", "admin");
|
const b = SendUsrChk("admin", "admin");
|
||||||
sock.send(b);
|
sock.send(b);
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
@@ -215,11 +216,11 @@ const handle_P2PRdy = (sock, dv: DataView) => {
|
|||||||
sock.send(buf);
|
sock.send(buf);
|
||||||
}, 100);
|
}, 100);
|
||||||
};
|
};
|
||||||
const handle_P2PAlive = (sock, dv: DataView) => {
|
const handle_P2PAlive = (sock: sock, dv: DataView) => {
|
||||||
const b = create_P2pAliveAck();
|
const b = create_P2pAliveAck();
|
||||||
sock.send(b);
|
sock.send(b);
|
||||||
};
|
};
|
||||||
const handle_PunchPkt = (sock, dv: DataView) => {
|
const handle_PunchPkt = (sock: sock, dv: DataView) => {
|
||||||
console.log(`Got a nice punchpkt`);
|
console.log(`Got a nice punchpkt`);
|
||||||
const punchCmd = dv.readU16();
|
const punchCmd = dv.readU16();
|
||||||
const len = dv.add(2).readU16();
|
const len = dv.add(2).readU16();
|
||||||
@@ -231,7 +232,7 @@ const handle_PunchPkt = (sock, dv: DataView) => {
|
|||||||
sock.send(create_P2pRdy(dv.add(4).readByteArray(len)));
|
sock.send(create_P2pRdy(dv.add(4).readByteArray(len)));
|
||||||
};
|
};
|
||||||
|
|
||||||
export const Handlers: Record<keyof typeof Commands, (sock: any, dv: DataView) => void> = {
|
export const Handlers: Record<keyof typeof Commands, (sock: sock, dv: DataView) => void> = {
|
||||||
// FIXME: keys are 'any' bc import?
|
// FIXME: keys are 'any' bc import?
|
||||||
PunchPkt: handle_PunchPkt,
|
PunchPkt: handle_PunchPkt,
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user