Skip to content
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

[Player] Prepare module for event producer #91

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions packages/common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"@tidal-music/common": "workspace:*"
},
"devDependencies": {
"@tidal-music/event-producer": "workspace:*",
"@vitest/coverage-v8": "1.4.0",
"@vitest/ui": "1.4.0",
"typescript": "5.4.2",
Expand Down
3 changes: 3 additions & 0 deletions packages/common/src/eventSender.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import type * as _EventSender from '@tidal-music/event-producer';
Copy link
Contributor

Choose a reason for hiding this comment

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

Common should not be allowed to import from any SDK module I think, or else we create circular dependencies?

Copy link
Member Author

@enjikaka enjikaka Apr 4, 2024

Choose a reason for hiding this comment

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

For type imports it's fine!


export type EventSender = typeof _EventSender;
1 change: 1 addition & 0 deletions packages/common/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ export * from './retryableError';
export * from './tidalError';
export * from './tidalMessage';
export * from './credentialsProvider';
export * from './eventSender';
8 changes: 7 additions & 1 deletion packages/common/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@ export default defineConfig({
formats: ['es'],
},
},
plugins: [dts({ rollupTypes: true, tsconfigPath: 'tsconfig.build.json' })],
Copy link
Member Author

Choose a reason for hiding this comment

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

Had to remove rollupTypes due to:

Skärmavbild 2024-03-21 kl  14 24 48

Copy link
Member Author

Choose a reason for hiding this comment

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

plugins: [
dts({
// Bundle the event sender types from event-producer
bundledPackages: ['@tidal-music/event-producer'],
tsconfigPath: 'tsconfig.build.json',
}),
],
test: {
coverage: {
exclude: ['./src/index.ts'].concat(configDefaults.coverage.exclude ?? []), // ignore barrel file
Expand Down
13 changes: 13 additions & 0 deletions packages/player/src/internal/handlers/set-event-sender.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import type { EventSender } from '@tidal-music/common';

import { eventSenderStore } from '../index';

/**
* Set the credentials provider TIDAL Player SDK should use for getting
* session information
*
* @param {CredentialsProvider} newCredentialsProvider
andymartinwork marked this conversation as resolved.
Show resolved Hide resolved
*/
export function setEventSender(newEventSender: EventSender) {
eventSenderStore.eventSender = newEventSender;
}
17 changes: 16 additions & 1 deletion packages/player/src/internal/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
import type { CredentialsProvider } from '@tidal-music/common';
import type { CredentialsProvider, EventSender } from '@tidal-music/common';

import * as Config from '../config';

import { waitForEvent } from './helpers/wait-for';

class EventSenderStore extends EventTarget {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore - Setter
#eventSender: EventSender;

set eventSender(newEventSender: EventSender) {
this.#eventSender = newEventSender;
}

get eventSender() {
return this.#eventSender;
}
}

class CredentialsProviderStore extends EventTarget {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore - Setter
Expand Down Expand Up @@ -241,6 +255,7 @@ export async function isAuthorizedWithUser() {
}

export const credentialsProviderStore = new CredentialsProviderStore();
export const eventSenderStore = new EventSenderStore();

/**
* Starts streaming privileges and event code if the credentials allow it.
Expand Down
5 changes: 4 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.