medooze / media-server-node

WebRTC Media Server for Node.js
MIT License
796 stars 119 forks source link

deduplicate SemanticSDP parsing #227

Closed mildsunrise closed 10 months ago

mildsunrise commented 10 months ago

we have copypasted this pattern (or variations of it) throughout the code:

thing = thing.constructor.name === "MediaInfo" ? thing.clone() : MediaInfo.expand(thing);

to parse thing into a SemanticSDP object, or clone it if already parsed.

This PR extracts this pattern into functions at Utils. It simplifies the code and satisfies the type checker.

mildsunrise commented 10 months ago

Shouldn't we move this to the semantic-sdp instead?

point. will do

murillo128 commented 10 months ago

how about extending X.expand() to no only support pojos but also check if the input is already an X and return it directly.

Then add a X.clone(x) => X.expand(x).clone()

?