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 isSupported check in browsers missing SourceBuffer global #2490

Merged
merged 4 commits into from Jan 6, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/is-supported.ts
Expand Up @@ -5,7 +5,7 @@ export function isSupported (): boolean {
if (!mediaSource) {
return false;
}
const sourceBuffer = SourceBuffer || (window as any).WebKitSourceBuffer;
const sourceBuffer = (self as any).SourceBuffer || (self as any).WebKitSourceBuffer as SourceBuffer;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
const sourceBuffer = (self as any).SourceBuffer || (self as any).WebKitSourceBuffer as SourceBuffer;
const sourceBuffer = self.SourceBuffer || (self as any).WebKitSourceBuffer as SourceBuffer;

self.SourceBuffer already has the correct type

Copy link
Collaborator Author

@robwalch robwalch Jan 5, 2020

Choose a reason for hiding this comment

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

Requires a TypeScript update (done 2c4f7e6). I was getting this error and went for the easy fix instead of updating deps.

$ npm run type-check

> tsc --noEmit

src/is-supported.ts:8:29 - error TS2339: Property 'SourceBuffer' does not exist on type 'Window'.

8   const sourceBuffer = self.SourceBuffer || (self as any).WebKitSourceBuffer as SourceBuffer;

Copy link
Member

Choose a reason for hiding this comment

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

Oh maybe. I just checked locally in vscode and it had the types. If it doesn’t cause any issues I think keeping typescript up to date makes sense

const isTypeSupported = mediaSource &&
typeof mediaSource.isTypeSupported === 'function' &&
mediaSource.isTypeSupported('video/mp4; codecs="avc1.42E01E,mp4a.40.2"');
Expand Down