-
-
Notifications
You must be signed in to change notification settings - Fork 590
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use correct return type for RTCSession encryption keys #4423
Conversation
This changes the return type of some public functions
As per matrix-org/matrix-js-sdk#4423 the key can be undefined and so we should handle this rather than waiting for SubtleCrypto.importKey() to fail.
@@ -483,6 +486,7 @@ export class MatrixRTCSession extends TypedEventEmitter<MatrixRTCSessionEvent, M | |||
} | |||
} | |||
|
|||
// n.b. this will extend the array if necessary and fill in the gaps with undefined |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will actually make it a sparse array with empty slots that are skipped by iteration methods.
Which gets me thinking, maybe callers can hook into that...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe callers can hook into that...
That is indeed the case; see element-hq/element-call#2646 (comment) which makes the updated typehints of this PR unnecessary (though the comments & updated unit test remain useful).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, TypeScript doesn't seem to model sparse arrays at all. So, as far as I can see, there is no compile time hint that a sparse array can contain empty values.
I don't find this very satisfactory. /me ponders
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is --noUncheckedIndexedAccess
, but that would require updating many other parts of the codebase to comply with it.
I've made #4427 as an alternative which cleans up the API entirely. I prefer that as an approach to this. |
* Handle case of encryption key for an index to be undefined As per matrix-org/matrix-js-sdk#4423 the key can be undefined and so we should handle this rather than waiting for SubtleCrypto.importKey() to fail. * Use release version of matrix-js-sdk Diff is matrix-org/matrix-js-sdk@baa6d13...v34.7.0 * Use RTCSession. reemitEncryptionKeys() * Add some test coverage whilst we are here * Add some test coverage whilst we are here * Lint
The functions have always possibly returned
undefined
where the key at a particular index was not known. This changes the return type to match this reality.Checklist
public
/exported
symbols have accurate TSDoc documentation.