Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@ base class options, as well as any of these PCM formatting options:
Fired when the backend `open()` call has completed. This happens once the first
`write()` call happens on the speaker instance.

#### "progress" event

Fired after each data write to the speaker instance. The parameter contains progress info:
* `numwr` - the cumulative number of writes (this is related to the number of frames)
* `wrlen` - the number of bytes written this time
* `wrtotal` - the total number of bytes written
* `buflen` - the number of bytes currently remaining in the buffer
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we try and name these something more human friendly?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually it would be a kind of acknowledgement or ack .


#### "flush" event

Fired after the speaker instance has had `end()` called, and after the audio data
Expand Down
6 changes: 5 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,12 @@ class Speaker extends Writable {
binding.write(handle, b, b.length, onwrite)
}

var THIS = this; //preserve "this" for onwrite call-back
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need this variable since onwrite is an arrow-function

const onwrite = (r) => {
debug('wrote %o bytes', r)
debug('wrote %o bytes', r);
if (isNaN(++THIS.numwr)) THIS.numwr = 1; //track #writes; is this == #frames?
if (isNaN(THIS.wrtotal += r)) THIS.wrtotal = r; //track total data written
THIS.emit('progress', {numwr: THIS.numwr, wrlen: r, wrtotal: THIS.wrtotal, buflen: (left || []).length}); //give caller some progress info
if (r !== b.length) {
done(new Error(`write() failed: ${r}`))
} else if (left) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "speaker",
"version": "0.4.0",
"version": "0.4.1",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't bump the version in the PR, that's better left to the release process

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the replies.

For the version bump, I've worked on other projects where they did that. I'll take it out.

I was thinking that the call-back would loose context (I haven't worked with libuv much), but I can remove "THIS" if it's not needed.

For the naming conventions, there are a lot of styles out there. Is there an example style that I should use? WRT the actual data fields included in the event, I just put in there what I needed for my little use case, but other data can be added if appropriate. Or should it not put include any data, and then the receiver can just pull the data out of the object?

"license": "MIT",
"description": "Output PCM audio data to the speakers",
"author": "Nathan Rajlich <[email protected]> (http://tootallnate.net)",
Expand Down