Conversation
k2d222
left a comment
There was a problem hiding this comment.
See comment, otherwise LGTM 👍
| await ctx.resume() | ||
|
|
||
| const src = new MediaStreamAudioSourceNode(ctx, { numberOfChannels: channels, bitDepth }) | ||
| const track = new MediaStreamTrack('audio', 'mic', { channelCount: channels, sampleSize: bitDepth, sampleRate }) |
There was a problem hiding this comment.
This makes a lot more sense, but I would make this a subclass of MediaStreamTrack. In the WebAudio spec, MediaStreamTrack has no public constructor, and no pushData method. But you can freely extend the spec by creating a CustomMediaStreamTrack type, that has a public constructor and the push method. There is prior art with CanvasCaptureMediaStreamTrack.
For the parameters, I would provide just one in an object, because it's not clear what the first two parameters are for (track kind, and track label). In short:
const track = new CustomMediaStreamTrack({
kind: 'audio',
label: 'track from audio-mic',
settings: { channelCount, sampleSize, bitDepth }
});There was a problem hiding this comment.
Good point, added.
Do you think CustomMediaStreamTrack is fine name? It's not immediately reflective of its purpose.
There was a problem hiding this comment.
Pull request overview
This PR refactors the media-stream side of the library to expose explicit MediaStream/MediaStreamTrack classes, move PCM ingestion onto a new CustomMediaStreamTrack, and align the microphone example/docs with that new flow. It fits into the codebase by reshaping how MediaStreamAudioSourceNode interoperates with Node-side audio capture.
Changes:
- Add exported
MediaStream,MediaStreamTrack, andCustomMediaStreamTrackclasses plus TypeScript declarations. - Rework
MediaStreamAudioSourceNodeto read queued audio from a track instead of acceptingpushData()directly. - Update the polyfill, tests, example microphone app, and README to use the new custom-track-based capture path.
Reviewed changes
Copilot reviewed 8 out of 9 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
test/polyfill.test.js |
Updates polyfill tests for new globals and custom track behavior. |
test/MediaStreamNodes.test.js |
Reworks media stream node tests to feed audio through CustomMediaStreamTrack. |
src/MediaStreamAudioSourceNode.js |
Moves source-node input handling to track-backed buffers and keeps destination-node track creation in sync. |
src/MediaStream.js |
Introduces the new MediaStream/track implementations and PCM normalization logic. |
polyfill.js |
Simplifies globals installed by the Node polyfill. |
index.js |
Exports the new media stream classes from the package root. |
index.d.ts |
Updates public typings for the new media stream API surface. |
examples/mic.js |
Migrates the microphone demo to push PCM into a custom track. |
README.md |
Rewrites microphone capture guidance around CustomMediaStreamTrack. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Agent-Logs-Url: https://github.com/audiojs/web-audio-api/sessions/65b9b190-f4f3-4010-b138-002f2c928f29 Co-authored-by: dy <300067+dy@users.noreply.github.com>
Agent-Logs-Url: https://github.com/audiojs/web-audio-api/sessions/7235af34-e944-4ffd-a5d3-799530153992 Co-authored-by: dy <300067+dy@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 8 out of 10 changed files in this pull request and generated 6 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
… buffers Agent-Logs-Url: https://github.com/audiojs/web-audio-api/sessions/27f3cc8d-37f9-4feb-865a-8f33d5b75a8a Co-authored-by: dy <300067+dy@users.noreply.github.com>
Agent-Logs-Url: https://github.com/audiojs/web-audio-api/sessions/9e18cfad-5d7c-4809-b293-e4c1f3de4c01 Co-authored-by: dy <300067+dy@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 8 out of 10 changed files in this pull request and generated 7 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@copilot apply changes based on the comments in this thread |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 8 out of 10 changed files in this pull request and generated 5 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
…gment in dest node Agent-Logs-Url: https://github.com/audiojs/web-audio-api/sessions/5c1f80bb-b76b-4ff2-9b7f-c8ca82dc86c5 Co-authored-by: dy <300067+dy@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 8 out of 10 changed files in this pull request and generated 7 comments.
Comments suppressed due to low confidence (1)
src/MediaStreamAudioSourceNode.js:115
createMediaStreamDestination().streamis still a plain object here instead of an instance of the newMediaStreamclass. That means destination streams do not participate in the EventTarget-based API added by this PR (instanceof MediaStream, stream events, etc.), so callers now get two incompatible "MediaStream" shapes depending on where the stream came from.
this.#stream = {
get _buffers() { return track._buffers },
read() { return track._buffers.shift() || null },
get readable() { return track._buffers.length > 0 },
getTracks: () => [track],
getAudioTracks: () => [track],
getVideoTracks: () => [],
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
…docs to README Agent-Logs-Url: https://github.com/audiojs/web-audio-api/sessions/21dacecc-c458-4c59-9617-29c97ae5ac2c Co-authored-by: dy <300067+dy@users.noreply.github.com>
The last outstanding item from that review was the strong-reference |
|
@copilot CI fails, please fix |
… fix WPT silence-detector test Agent-Logs-Url: https://github.com/audiojs/web-audio-api/sessions/0daa36f8-3469-425c-89fa-365d5fb40d2c Co-authored-by: dy <300067+dy@users.noreply.github.com>
Fixed in 2515659. The WPT test |
Based on #35 (comment)
This is much closer to a standard implementation of
MediaStreamTrackandMediaStream.Here's why:
MediaStreamTrackandMediaStreaminherit fromEventTarget. Both classes now explicitly extendEventTarget.MediaStreamTrackhas standard read-only properties (id,kind,label,readyState) andenabledflag.clone(),getSettings(),stop(),getTracks(),getAudioTracks(),getVideoTracks(),addTrack(),removeTrack().pushData) now lives appropriately on theMediaStreamTrack, mirroring how audio capture happens on a track level natively, rather than on theMediaStreamAudioSourceNodedirectly.The tests run successfully with this refactored, more standards-compliant implementation.