refactor(webstreams): fix layer boundaries and extract EncryptTransform#163
Draft
imaTik0 wants to merge 1 commit intorefactor/webstreams-dead-code-and-typesfrom
Draft
refactor(webstreams): fix layer boundaries and extract EncryptTransform#163imaTik0 wants to merge 1 commit intorefactor/webstreams-dead-code-and-typesfrom
imaTik0 wants to merge 1 commit intorefactor/webstreams-dead-code-and-typesfrom
Conversation
Move service/ types into their owning layer:
- src/service/EventDispatcher.ts → src/webStreams/EventDispatcher.ts
(fix removeOnStateChangeListener filter, add JSDoc, wrap emit in try/catch)
- src/service/WebRtcInterface.ts → src/webStreams/WebRtcInterface.ts
(remove server event types that belong in native layer; add WebRtcMethodCall
discriminated union; import Jsep from ApiTypes)
ApiTypes.ts:
- Add Jsep interface (sdp + RTCSdpType) replacing the loose string in WebRtcInterface
- Add StreamTrack interface (replaces StreamApi-local definition)
- Remove dead types: StreamRemoteInfo, StreamList, StreamTrackList, PublishMeta,
TrackInfo, StreamRoomInfo, StreamRoomList, TrackType
WebRtcInterfaceImpl.ts:
- Update import paths to new locations
- Replace { [K: string]: Function } methodsMap with typed MethodMap
- Fix method bindings with .bind(this) and typed lambda for updateSessionId
- methodCall now uses WebRtcMethodCall["name"] as key type
EncryptTransform.ts (new src/webStreams/worker/):
- Extract per-frame AES-256-GCM logic out of the monolithic worker.ts
- Pure class: no worker globals, no postMessage, no module state
- encryptFrame takes lastRms as a parameter; decryptFrame returns rms | null
worker.ts:
- Use EncryptTransform and new WorkerEvents discriminated unions
- Add RTCRtpScriptTransform entry point (modern browsers) alongside postMessage
- Add stop operation with AbortController-based pipeline cancellation
- logPipelineError ignores AbortError in addition to "Destination stream closed"
KeyStore.ts:
- Make setKeys async (was fire-and-forget; importKeyAndWipeMaterial is async)
- Add getEncryptionExternalKeyId() and resolveKeyId() stubs
(same value as getEncryptionKeyId for now; session-prefix refactor comes later)
Add EncryptTransform.test.ts covering audio/video encrypt+decrypt round-trips,
header preservation, tamper detection, and short-frame passthrough.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Move service/ types into their owning layer:
ApiTypes.ts:
WebRtcInterfaceImpl.ts:
EncryptTransform.ts (new src/webStreams/worker/):
worker.ts:
KeyStore.ts:
Add EncryptTransform.test.ts covering audio/video encrypt+decrypt round-trips, header preservation, tamper detection, and short-frame passthrough.