From e3437e95d7e59442f19e63b2142fdaa570f9cb53 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Wed, 12 Jun 2024 09:06:59 +0100 Subject: [PATCH] fix: export `DescriptionType` enum values At compliation time the values of a `const enum` in TS get changed to numbers which breaks JS APIs that expect the string values. At runtime anything in a `.d.ts` file is not available, so the solution is to export enum definitions from the `.d.ts` file as a regular `enum` (no `const`) and export the matching values from the implementation file as a plain object. --- lib/index.d.ts | 2 +- lib/index.js | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/index.d.ts b/lib/index.d.ts index 717c3133..66f7a6a7 100644 --- a/lib/index.d.ts +++ b/lib/index.d.ts @@ -63,7 +63,7 @@ export interface RtcConfig { } // Lowercase to match the description type string from libdatachannel -export const enum DescriptionType { +export enum DescriptionType { Unspec = 'unspec', Offer = 'offer', Answer = 'answer', diff --git a/lib/index.js b/lib/index.js index 1e2f9000..3035b61a 100644 --- a/lib/index.js +++ b/lib/index.js @@ -41,3 +41,11 @@ export default { ...nodeDataChannel, DataChannelStream, }; + +export const DescriptionType = { + Unspec: 'unspec', + Offer: 'offer', + Answer: 'answer', + Pranswer: 'pranswer', + Rollback: 'rollback', +};