diff --git a/package-lock.json b/package-lock.json index 5d1c6d6a..7daf43b2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6377,7 +6377,7 @@ }, "packages/webrtc": { "name": "werift", - "version": "0.18.9", + "version": "0.18.11", "license": "MIT", "dependencies": { "@fidm/x509": "^1.2.1", diff --git a/packages/webrtc/package.json b/packages/webrtc/package.json index 6bbc5a16..c33644d3 100644 --- a/packages/webrtc/package.json +++ b/packages/webrtc/package.json @@ -1,6 +1,6 @@ { "name": "werift", - "version": "0.18.9", + "version": "0.18.11", "description": "WebRTC Implementation for TypeScript (Node.js)", "keywords": [ "WebRTC", diff --git a/packages/webrtc/src/sdp.ts b/packages/webrtc/src/sdp.ts index 564c74a8..8bfb269b 100644 --- a/packages/webrtc/src/sdp.ts +++ b/packages/webrtc/src/sdp.ts @@ -669,6 +669,9 @@ export function codecParametersFromString(str: string) { } else { parameters[k] = v; } + } else if (param.includes(":")) { + const [k, v] = param.split(":"); + parameters[k] = Number.isNaN(Number(v)) ? v : Number(v); } else { parameters[param] = undefined; } @@ -676,11 +679,14 @@ export function codecParametersFromString(str: string) { return parameters; } -export function codecParametersToString(parameters: { - [key: string]: string | number; -}) { +export function codecParametersToString( + parameters: { + [key: string]: string | number; + }, + joint: string = "=" +) { const params = Object.entries(parameters).map(([k, v]) => { - if (v) return `${k}=${v}`; + if (v) return `${k}${joint}${v}`; else return k; }); if (params.length > 0) { diff --git a/packages/webrtc/tests/sdp.test.ts b/packages/webrtc/tests/sdp.test.ts index 8f2a8bdb..e88e39a3 100644 --- a/packages/webrtc/tests/sdp.test.ts +++ b/packages/webrtc/tests/sdp.test.ts @@ -1,4 +1,9 @@ -import { GroupDescription, MediaDescription, SessionDescription } from "../src"; +import { + codecParametersFromString, + GroupDescription, + MediaDescription, + SessionDescription, +} from "../src"; describe("sdp", () => { test("rtx", () => { @@ -12,4 +17,17 @@ describe("sdp", () => { new GroupDescription("FID", ["ssrc", "rtx"]), ]); }); + + describe("codecParametersFromString", () => { + test("h264 parameters", () => { + const params = codecParametersFromString( + "packetization-mode:0;profile-level-id:42001f;level-asymmetry-allowed:0" + ); + expect(params).toEqual({ + "level-asymmetry-allowed": 0, + "packetization-mode": 0, + "profile-level-id": "42001f", + }); + }); + }); });