-
-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #199 from ericblade/test
update camera and media tests, cleanup camera and media code
- Loading branch information
Showing
12 changed files
with
395 additions
and
246 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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,15 @@ | ||
export function enumerateDevices(): Promise<Array<MediaDeviceInfo>> { | ||
return navigator?.mediaDevices?.enumerateDevices?.() ?? Promise.reject(new Error('enumerateDevices is not defined')); | ||
try { | ||
return navigator.mediaDevices.enumerateDevices(); | ||
} catch (err) { | ||
return Promise.reject(new Error('enumerateDevices is not defined')); | ||
} | ||
} | ||
|
||
export function getUserMedia(constraints: MediaStreamConstraints): Promise<MediaStream> { | ||
return navigator?.mediaDevices?.getUserMedia(constraints) ?? Promise.reject(new Error('getUserMedia is not defined')); | ||
try { | ||
return navigator.mediaDevices.getUserMedia(constraints); | ||
} catch (err) { | ||
return Promise.reject(new Error('getUserMedia is not defined')); | ||
} | ||
} |
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,24 @@ | ||
import { describe, it } from 'mocha'; | ||
import { expect } from 'chai'; | ||
import { enumerateDevices, getUserMedia } from '../../mediaDevices'; | ||
|
||
describe('mediaDevices (browser)', () => { | ||
describe('enumerateDevices', () => { | ||
it('TODO: rejects with an error if enumerateDevices is not supported in browser version'); | ||
it('returns a Promise', () => { | ||
expect(enumerateDevices()).to.be.a('Promise'); | ||
}); | ||
it('resolves with an Array of InputDeviceInfo', async () => { | ||
const d = await enumerateDevices(); | ||
expect(d).to.be.an('Array').of.length.greaterThan(1); | ||
console.warn('* d=', d); | ||
expect(d[0]).to.be.an.instanceof(InputDeviceInfo); | ||
}); | ||
}); | ||
describe('getUserMedia', () => { | ||
it('TODO: rejects with an error if getUserMedia is not supported'); | ||
it('returns a Promise', () => { | ||
expect(getUserMedia({})).to.be.a('Promise'); | ||
}); | ||
}); | ||
}); |
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,24 @@ | ||
import { describe, it } from 'mocha'; | ||
import { expect } from 'chai'; | ||
import { enumerateDevices, getUserMedia } from '../../mediaDevices'; | ||
|
||
describe('mediaDevices (node)', () => { | ||
it('enumerateDevices rejects', async () => { | ||
try { | ||
const x = await enumerateDevices(); | ||
// eslint-disable-next-line @typescript-eslint/no-unused-expressions,no-unused-expressions | ||
expect(x).to.not.exist; | ||
} catch (err) { | ||
expect(err.message).to.equal('enumerateDevices is not defined'); | ||
} | ||
}); | ||
it('getUserMedia rejects', async () => { | ||
try { | ||
const x = await getUserMedia({}); | ||
// eslint-disable-next-line @typescript-eslint/no-unused-expressions,no-unused-expressions | ||
expect(x).to.not.exist; | ||
} catch (err) { | ||
expect(err.message).to.equal('getUserMedia is not defined'); | ||
} | ||
}); | ||
}); |
Oops, something went wrong.