From dc53f5d96b0771559bc66a914f41e24093af89b7 Mon Sep 17 00:00:00 2001 From: foomoon Date: Wed, 13 Dec 2023 22:36:42 -0600 Subject: [PATCH] udp error handling --- dist/lib/light.d.ts | 4 +--- dist/lib/light.js | 4 +++- src/lib/light.ts | 8 +++++--- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/dist/lib/light.d.ts b/dist/lib/light.d.ts index f8add7c..f995848 100644 --- a/dist/lib/light.d.ts +++ b/dist/lib/light.d.ts @@ -1,7 +1,5 @@ /// -/// import { AxiosInstance, AxiosResponse } from "axios"; -import * as udp from "node:dgram"; import { Frame } from "./frame.js"; import { Movie } from "./movie.js"; import { rgbColor, hsvColor, deviceMode, timer, coordinate, layout } from "./interfaces.js"; @@ -17,7 +15,7 @@ export declare class Light { token: AuthenticationToken | undefined; activeLoginCall: boolean; nleds: number | undefined; - udpClient: udp.Socket; + udpClient: any; /** * Creates an instance of Light. * diff --git a/dist/lib/light.js b/dist/lib/light.js index 765d0e3..9a0b773 100644 --- a/dist/lib/light.js +++ b/dist/lib/light.js @@ -67,7 +67,7 @@ export class Light { this.udpClient = udp.createSocket("udp4"); } else { - this.udpClient = new udp.Socket(); + this.udpClient = null; } } autoEndLoginCall() { @@ -488,6 +488,8 @@ export class Light { return __awaiter(this, void 0, void 0, function* () { if (!this.token) throw errNoToken; + if (!this.udpClient) + throw new Error("UDP not supported in browser"); // Generate the header let tokenArray = this.token.getTokenDecoded(); let udpHeader = Buffer.alloc(tokenArray.length + 4); diff --git a/src/lib/light.ts b/src/lib/light.ts index eaa8e22..ba49817 100644 --- a/src/lib/light.ts +++ b/src/lib/light.ts @@ -61,7 +61,7 @@ export class Light { token: AuthenticationToken | undefined; activeLoginCall: boolean; nleds: number | undefined; - udpClient: udp.Socket; + udpClient: any; //udp.Socket; /** * Creates an instance of Light. * @@ -80,7 +80,7 @@ export class Light { if (typeof window === "undefined") { this.udpClient = udp.createSocket("udp4"); } else { - this.udpClient = new udp.Socket(); + this.udpClient = null; } } async autoEndLoginCall(): Promise { @@ -476,6 +476,8 @@ export class Light { async sendRealTimeFrameUDP(frame: Frame) { if (!this.token) throw errNoToken; + if (!this.udpClient) throw new Error("UDP not supported in browser"); + // Generate the header let tokenArray = this.token.getTokenDecoded(); let udpHeader = Buffer.alloc(tokenArray.length + 4); @@ -490,7 +492,7 @@ export class Light { const data = Buffer.alloc(udpHeader.length + frame.getNLeds() * 3); data.fill(udpHeader); data.fill(frame.toOctet(), udpHeader.length); - this.udpClient.send(data, 7777, this.ipaddr, (error) => { + this.udpClient.send(data, 7777, this.ipaddr, (error: any) => { if (error) { console.warn(error); }