Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
thijstriemstra committed Jan 24, 2021
1 parent 907ace2 commit f19e460
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 1 deletion.
1 change: 1 addition & 0 deletions examples/plugins/audio-only-opus-media-recorder.html
Expand Up @@ -36,6 +36,7 @@
/* eslint-disable */
var options = {
controls: true,
bigPlayButton: false,
width: 600,
height: 300,
fluid: false,
Expand Down
3 changes: 3 additions & 0 deletions karma.conf.js
Expand Up @@ -123,6 +123,9 @@ module.exports = function(config) {
{pattern: 'node_modules/opus-recorder/dist/*Worker.min.js', included: false, served: true},
{pattern: 'node_modules/opus-recorder/dist/*.wasm', included: false, served: true, type: 'wasm'},
'node_modules/opus-recorder/dist/recorder.min.js',
// opus-media-recorder
{pattern: 'node_modules/opus-media-recorder/encoderWorker.umd.js', included: false, served: true},
{pattern: 'node_modules/opus-media-recorder/*.wasm', included: false, served: true, type: 'wasm'},
// vmsg
{pattern: 'node_modules/vmsg/*.wasm', included: false, served: true, type: 'wasm'},
// web streams API polyfill to support Firefox (for webm-wasm)
Expand Down
54 changes: 54 additions & 0 deletions test/plugins/opus-media-recorder-plugin.spec.js
@@ -0,0 +1,54 @@
/**
* @since 4.2.0
*/

import TestHelpers from '../test-helpers';

import Event from '../../src/js/event';

// registers the plugin
import OpusMediaRecorderEngine from '../../src/js/plugins/opus-media-recorder-plugin';
import {OPUSMEDIARECORDER} from '../../src/js/engine/record-engine';


/** @test {OpusMediaRecorderEngine} */
describe('plugins.opus-media-recorder-plugin', () => {
let player;

afterEach(() => {
player.dispose();
});

/** @test {OpusMediaRecorderEngine} */
it('can run as an audio-only plugin', (done) => {
// create audio-only player with opus-media-recorder plugin
player = TestHelpers.makeAudioOnlyPluginPlayer(OPUSMEDIARECORDER);

player.one(Event.FINISH_RECORD, () => {
// received a blob file
expect(player.recordedData instanceof Blob).toBeTruthy();
expect(player.recordedData.name).toEndWith('.oga');

// wait till it's loaded before destroying
// (XXX: create new event for this)
setTimeout(done, 1000);
});

player.one(Event.START_RECORD, () => {
// stop recording after few seconds
setTimeout(() => {
player.record().stop();
}, 2000);
});

player.one(Event.DEVICE_READY, () => {
// record some audio
player.record().start();
});

player.one(Event.READY, () => {
// start device
player.record().getDevice();
});
});
});
11 changes: 10 additions & 1 deletion test/test-helpers.js
Expand Up @@ -8,7 +8,7 @@ import {Player, mergeOptions} from 'video.js';

import adapter from 'webrtc-adapter';

import {LIBVORBISJS, RECORDERJS, LAMEJS, OPUSRECORDER, VMSG, WEBMWASM} from '../src/js/engine/record-engine';
import {LIBVORBISJS, RECORDERJS, LAMEJS, OPUSRECORDER, VMSG, WEBMWASM, OPUSMEDIARECORDER} from '../src/js/engine/record-engine';
import {TSEBML, FFMPEGJS} from '../src/js/engine/convert-engine';

const TestHelpers = {
Expand Down Expand Up @@ -152,6 +152,15 @@ const TestHelpers = {
recordPluginOptions.audioChannels = 1;
break;

case OPUSMEDIARECORDER:
recordPluginOptions.audioEngine = OPUSMEDIARECORDER;
recordPluginOptions.audioWorkerURL = '/base/node_modules/opus-media-recorder/encoderWorker.umd.js';
recordPluginOptions.audioWebAssemblyURL = {
OggOpusEncoderWasmPath: '/base/node_modules/opus-media-recorder/OggOpusEncoder.wasm',
WebMOpusEncoderWasmPath: '/base/node_modules/opus-media-recorder/WebMOpusEncoder.wasm'
};
break;

case RECORDERJS:
recordPluginOptions.audioEngine = RECORDERJS;
break;
Expand Down

0 comments on commit f19e460

Please sign in to comment.