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

fix:accept CurrentPlayheadPosition with 0 value #638

Merged
Merged
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
5 changes: 3 additions & 2 deletions src/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,9 @@
options: Options = {},
): MediaEvent {
// Set event option based on options or current state
this.currentPlayheadPosition =
options?.currentPlayheadPosition || this.currentPlayheadPosition;
if (options?.currentPlayheadPosition !== undefined) {
this.currentPlayheadPosition = options?.currentPlayheadPosition;
}
Copy link
Member

@rmi22186 rmi22186 Sep 10, 2024

Choose a reason for hiding this comment

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

Actually, since this is TS, i think you can do ?? instead of ||.
https://stackoverflow.com/questions/61480993/when-should-i-use-nullish-coalescing-vs-logical-or

Try that and see if your tests pass. Yay ts!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@rmi22186 - tested the suggested change and confirmed its working and pushed the new code, thanks!


// Merge Session Attributes with any other optional Event Attributes.
// Event-Level Custom Attributes will override Session Custom Attributes if there is a collison.
Expand Down Expand Up @@ -692,7 +693,7 @@
this.mediaSessionEndTimestamp = Date.now();
}
// tslint:disable-next-line: no-any
const customAttributes: Record<string, any> = {};

Check warning on line 696 in src/session.ts

View workflow job for this annotation

GitHub Actions / Build and Test (14.x)

Unexpected any. Specify a different type

Check warning on line 696 in src/session.ts

View workflow job for this annotation

GitHub Actions / Build and Test (14.x)

Unexpected any. Specify a different type
customAttributes[
ValidMediaAttributeKeys.mediaSessionIdKey
] = this.sessionId;
Expand Down Expand Up @@ -754,7 +755,7 @@
}

// tslint:disable-next-line: no-any
const customAttributes: Record<string, any> = {};

Check warning on line 758 in src/session.ts

View workflow job for this annotation

GitHub Actions / Build and Test (14.x)

Unexpected any. Specify a different type

Check warning on line 758 in src/session.ts

View workflow job for this annotation

GitHub Actions / Build and Test (14.x)

Unexpected any. Specify a different type
customAttributes[
ValidMediaAttributeKeys.mediaSessionIdKey
] = this.sessionId;
Expand Down Expand Up @@ -810,7 +811,7 @@
}

// tslint:disable-next-line: no-any
const customAttributes: Record<string, any> = {};

Check warning on line 814 in src/session.ts

View workflow job for this annotation

GitHub Actions / Build and Test (14.x)

Unexpected any. Specify a different type

Check warning on line 814 in src/session.ts

View workflow job for this annotation

GitHub Actions / Build and Test (14.x)

Unexpected any. Specify a different type
customAttributes[
ValidMediaAttributeKeys.mediaSessionIdKey
] = this.sessionId;
Expand Down
18 changes: 18 additions & 0 deletions test/session.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
beforeEach(() => {
sandbox = sinon.createSandbox();
mp = {
logBaseEvent: (event: MediaEvent) => {},

Check warning on line 29 in test/session.test.ts

View workflow job for this annotation

GitHub Actions / Build and Test (14.x)

'event' is defined but never used

Check warning on line 29 in test/session.test.ts

View workflow job for this annotation

GitHub Actions / Build and Test (14.x)

'event' is defined but never used
logger: (message: string) => {},

Check warning on line 30 in test/session.test.ts

View workflow job for this annotation

GitHub Actions / Build and Test (14.x)

'message' is defined but never used

Check warning on line 30 in test/session.test.ts

View workflow job for this annotation

GitHub Actions / Build and Test (14.x)

'message' is defined but never used
};

song = {
Expand Down Expand Up @@ -746,6 +746,24 @@
);
expect(bond.args[0][0].options.currentPlayheadPosition).to.eq(32);
});

it('accepts currentPlayheadPosition with a value of 0', () => {
const bond = sinon.spy(mp, 'logBaseEvent');

const options = {
currentPlayheadPosition: 0,
customAttributes: {
content_rating: 'epic',
},
};

mpMedia.logMediaSessionStart(options);

expect(bond.args[0][0].options.customAttributes).to.eqls(
options.customAttributes,
);
expect(bond.args[0][0].options.currentPlayheadPosition).to.eq(0);
});
});

describe('#logMediaSessionEnd', () => {
Expand Down
Loading