StationModule.ts 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import { UniqueMethods } from "../types/Modules";
  2. import BaseModule from "../BaseModule";
  3. import ModuleManager from "../ModuleManager";
  4. export default class StationModule extends BaseModule {
  5. /**
  6. * Station Module
  7. *
  8. * @param {ModuleManager} moduleManager Module manager class
  9. */
  10. public constructor(moduleManager: ModuleManager) {
  11. super(moduleManager, "stations");
  12. }
  13. /**
  14. * startup - Startup station module
  15. */
  16. public override startup(): Promise<void> {
  17. return new Promise((resolve, reject) => {
  18. super
  19. .startup()
  20. .then(() => {
  21. console.log("Station Startup");
  22. super.started();
  23. resolve();
  24. })
  25. .catch(err => reject(err));
  26. });
  27. }
  28. /**
  29. * addToQueue - Add media to queue
  30. *
  31. * @param {object} payload Payload
  32. * @param {string} payload.songId Song ID
  33. */
  34. public addToQueue(payload: { songId: string }): Promise<void> {
  35. return new Promise((resolve, reject) => {
  36. const { songId } = payload;
  37. // console.log(`Adding song ${songId} to the queue.`);
  38. setTimeout(
  39. () => (Math.round(Math.random()) ? resolve() : reject()),
  40. Math.random() * 1000
  41. );
  42. });
  43. }
  44. /**
  45. *
  46. * @returns {{ number: number }} return
  47. */
  48. public addA(): Promise<{ number: number }> {
  49. return new Promise<{ number: number }>(resolve => {
  50. resolve({ number: 123 });
  51. });
  52. }
  53. /**
  54. *
  55. */
  56. public addB(): Promise<void> {
  57. return new Promise<void>(resolve => {
  58. resolve();
  59. });
  60. }
  61. }
  62. export type StationModuleJobs = {
  63. [Property in keyof UniqueMethods<StationModule>]: {
  64. payload: Parameters<UniqueMethods<StationModule>[Property]>[0];
  65. returns: Awaited<ReturnType<UniqueMethods<StationModule>[Property]>>;
  66. };
  67. };