-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Secondary notification queue implementation
* feat: Notification queues fixed #89 by @theimo1221 * Removal of events and compliance to tests * Two PlayNotification Calls with 2nd having immediate resolve * Two PlayNotification Calls with First Reolving Promise after 2nd * Implement general Timeout functionality within PlayNotification and extend tests * Revert changes to "returns false when not playing" * Move new tests to seperate describe Block * Add individual Timeout for specific queue items plus Test * Clear specific timeout after it being played * chore: Lint errors * chore: Second TTS method * chore: Fixing debug style * chore: Fixing tests Not merged: * ~~Always trigger "STOPPED" event~~ Co-authored-by: Thiemo <[email protected]>
- Loading branch information
Showing
6 changed files
with
1,379 additions
and
23 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,4 +48,4 @@ sonos.PlayNotification({ | |
// process.exit(0) | ||
// }, 2000) | ||
// }) | ||
// .catch(console.error) | ||
// .catch(console.error) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import { PlayNotificationOptions } from './requests'; | ||
|
||
export interface NotificationQueueItem { | ||
/** | ||
* Desired PlayNotificationOptions | ||
* | ||
* @type {number} | ||
*/ | ||
options: PlayNotificationOptions; | ||
|
||
/** | ||
* The Resolve Promise we have to resolve once finished successfully | ||
* | ||
* @type {(reject: boolean | PromiseLike<boolean>) => void} | ||
*/ | ||
resolve: (resolve: boolean | PromiseLike<boolean>) => void; | ||
|
||
/** | ||
* The Reject Promise we have to resolve once finished with failure | ||
* | ||
* @type {(reject: boolean | PromiseLike<boolean>) => void} | ||
*/ | ||
reject: (reject: boolean | PromiseLike<boolean>) => void; | ||
|
||
/** | ||
* Whether we should only resolve the promise when we reverted correctly | ||
* | ||
* @type {boolean} | ||
*/ | ||
resolveAfterRevert: boolean; | ||
|
||
/** | ||
* Object with details regarding the timeout for this queue item | ||
* | ||
* @type {NotificationQueueTimeoutItem} | ||
*/ | ||
generalTimeout?: NotificationQueueTimeoutItem; | ||
|
||
/** | ||
* Object with details regarding the timeout for this specific queue item (Starting when this is Queue Item becomes first) | ||
* | ||
* @type {NotificationQueueTimeoutItem} | ||
*/ | ||
individualTimeout?: NotificationQueueTimeoutItem; | ||
} | ||
|
||
export class NotificationQueueTimeoutItem { | ||
public constructor( | ||
/** | ||
* The timeout reference to clear if anything is okay | ||
* | ||
* @type {NotificationQueueTimeoutItem} | ||
*/ | ||
public timeout: NodeJS.Timeout, | ||
|
||
/** | ||
* The timestamp when the timeout will fire | ||
* | ||
* @type {NotificationQueueTimeoutItem} | ||
*/ | ||
public fireTime: number, | ||
) { } | ||
|
||
public timeLeft(): number { | ||
return this.fireTime - (new Date()).getTime(); | ||
} | ||
} | ||
|
||
export class NotificationQueue { | ||
public queue: NotificationQueueItem[] = []; | ||
|
||
public promisesToResolve: Array<{ | ||
promise: (resolve: boolean | PromiseLike<boolean>) => void, | ||
value: boolean, | ||
timeout?: NotificationQueueTimeoutItem, | ||
}> = []; | ||
|
||
public playing = false; | ||
|
||
/** | ||
* Whether any item in the Queue changed the volume | ||
* | ||
* @type {boolean} | ||
*/ | ||
public volumeChanged = false; | ||
|
||
/** | ||
* Whether the Queue played any item at all | ||
* | ||
* @type {boolean} | ||
*/ | ||
public anythingPlayed = false; | ||
} |
This file contains 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
This file contains 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
Oops, something went wrong.