-
Notifications
You must be signed in to change notification settings - Fork 18
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
Change NotifyOnChangeOnly to accept a list #199
base: master
Are you sure you want to change the base?
Conversation
@Beastlybear2017 you can try to write a test, where to check if your solutions works. Here, for instance, test case that checks if the icecast-parser/test/Parser.spec.ts Lines 57 to 65 in e6ba7a3
You can add more cases like that where you check scenarios like “what if you provided no keys at all, that way it should notify every time” or “what if I provided the keys that doesn't exist in metadata, it should notify” and so on. |
I have added the tests (updated yours to use the new system), fixed any issues and commited my changes. All the tests pass / fail when they should |
Fixed previous issue - Now works as intened
Was able to test within my project and fixed an issue that I discorvered. Now works as intened |
Updates info for notifyOnChangeOnly
Great work! However, let's keep it backward compatible with older API. Let's leave the possibility to specify the boolean as before. |
@@ -47,7 +47,7 @@ You can provide additional parameters to constructor: | |||
- `userAgent` - by default `icecast-parser`. | |||
- `keepListen` - by default `false`. If you set to `true`, then response from radio station will not be destroyed and you can pipe it to another streams. E.g. piping it to the `speaker` module. | |||
- `autoUpdate` - by default `true`. If you set to `false`, then parser will not be listening for recent updates and immediately close the stream. So that, you will get a metadata only once. | |||
- `notifyOnChangeOnly` - by default `false`. If you set both `autoUpdate` and `notifyOnChangeOnly` to `true`, it will keep listening the stream and notifying you about metadata, but it will not notify if metadata did not change from the previous time. | |||
- `notifyOnChangeOnly` - by default `[]`. If you set both `autoUpdate` to `true` and `notifyOnChangeOnly` to include the a list of metadata keys to listen for (`['StreamTitle', 'StreamUrl']`), it will keep listening the stream and notifying you about metadata, but it will not notify if the selected metadata did not change from the previous time. |
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.
By default, let it be false
as before for backward compatibility.
@@ -9,7 +9,7 @@ export interface ParserOptions { | |||
errorInterval: number | |||
keepListen: boolean | |||
metadataInterval: number | |||
notifyOnChangeOnly: boolean | |||
notifyOnChangeOnly: string[] |
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.
notifyOnChangeOnly: string[] | |
notifyOnChangeOnly: boolean | string[] |
@@ -35,7 +35,7 @@ export class Parser extends EventEmitter { | |||
errorInterval: 10 * 60, | |||
keepListen: false, | |||
metadataInterval: 5, | |||
notifyOnChangeOnly: false, | |||
notifyOnChangeOnly: [], |
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.
notifyOnChangeOnly: [], | |
notifyOnChangeOnly: false, |
for (const [key, value] of metadata.entries()) { | ||
if (this.previousMetadata.get(key) !== value) { | ||
return true; | ||
if (this.options.notifyOnChangeOnly.length > 0) { |
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.
Now, here we can check the type of the option. If there is an array, we treat it by your logic but if there is a boolean, nothing changes and works as before.
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.
if (Array.isArray(this.options.notifyOnChangeOnly)) {
// your new logic
} else if (this.options.notifyOnChangeOnly === true) {
// old logic
}
@@ -57,11 +57,40 @@ describe('parser', () => { | |||
it('should properly emit metadata event when metadata has been updated', async () => await new Promise((resolve) => { | |||
expect.hasAssertions(); | |||
|
|||
const radio = new Parser({ autoUpdate: false, notifyOnChangeOnly: true, url: 'https://live.hunter.fm/80s_high' }); | |||
const radio = new Parser({ autoUpdate: false, notifyOnChangeOnly: [], url: 'https://live.hunter.fm/80s_high' }); |
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.
This change is no longer needed then and this test will check that everything works as before
I apologise if this is really dumb, I have never attempted to contribute towards a npm package before and have no clue how to / if it is possible to test it from a local file.
Here is my vision of how this would work, although have no clue if it works in practice :)