Skip to content

Commit

Permalink
fix: export DescriptionType enum values
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
achingbrain committed Jun 12, 2024
1 parent d59c64c commit 0404388
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export interface SelectedCandidateInfo {
}

// Must be same as rtc enum class Direction
export const enum Direction {
export enum Direction {
SendOnly = 'SendOnly',
RecvOnly = 'RecvOnly',
SendRecv = 'SendRecv',
Expand Down
8 changes: 8 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,11 @@ export default {
...nodeDataChannel,
DataChannelStream,
};

export const DescriptionType = {
unspec: 'unspec',
offer: 'offer',
answer: 'answer',
pranswer: 'pranswer',
rollback: 'rollback',
};

0 comments on commit 0404388

Please sign in to comment.