Skip to content

js-sdk voip architecture: Input validation & types #1433

@dbkr

Description

@dbkr

Your use case

https://github.com/matrix-org/matrix-js-sdk/blob/fc2671d8538a3339ca5925ef42e3ba6102f7e8f2/src/matrixrtc/CallMembership.ts#L40 takes a typed data structure and does further validation on it that should be unnecessary because of the types. This is a bit weird and confusing, but is because we are casting the raw content from the event into a CallMembershipData and then having the constructor take a typed interface, so we are technically lying about the type of the data between those points.

Now that I think about this more, I suspect the neatest solution would be to have a separate validator function that takes unknown, validates it and returns CallMembershipData or throws, then you can construct the CallMembership with a validated CallMembershipData.

Either way, we should do something less confusing, but still actually do explicit validation which we have often neglected in the past.

Have you considered any alternatives?

No response

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    T-TaskRefactoring, enabling or disabling functionality, other engineering tasks

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions