unit test updated
parent
f65222fc73
commit
aaa272eda5
@ -1,8 +1 @@
|
||||
git clone git@gitlab.ipvisionsoft.com:ipvision-web/liveplayer.git
|
||||
|
||||
|
||||
cd liveplayer
|
||||
|
||||
npm run build
|
||||
|
||||
npm run start
|
||||
Coming soon
|
@ -0,0 +1,58 @@
|
||||
function PCMPlayer() {
|
||||
|
||||
this.samples = [];
|
||||
this.flushingTime = 200;
|
||||
this.createContext();
|
||||
this.startFlushing();
|
||||
this.flush = this.flush.bind(this);
|
||||
this.interval = setInterval(this.flush, this.flushingTime);
|
||||
|
||||
this.setConfig = function(sampleRate, channels) {
|
||||
this.sampleRate = sampleRate;
|
||||
this.channels = channels;
|
||||
}
|
||||
|
||||
this.createContext = function() {
|
||||
this.audioCtx = new (window.AudioContext || window.webkitAudioContext)();
|
||||
this.gainNode = this.audioCtx.createGain();
|
||||
this.gainNode.gain.value = 1;
|
||||
this.gainNode.connect(this.audioCtx.destination);
|
||||
};
|
||||
|
||||
this.stopFlushing = function() {
|
||||
if (this.interval) {
|
||||
clearInterval(this.interval);
|
||||
}
|
||||
}
|
||||
|
||||
this.feed = function(data) {
|
||||
let tmp = new Float32Array(this.samples.length + data.length);
|
||||
tmp.set(this.samples, 0);
|
||||
tmp.set(data, this.samples.length);
|
||||
this.samples = tmp;
|
||||
}
|
||||
|
||||
this.flush = function() {
|
||||
let bufferSource = this.audioCtx.createBufferSource(),
|
||||
length = this.samples.length,
|
||||
audioBuffer = this.audioCtx.createBuffer(this.channels, length, this.sampleRate),
|
||||
audioData,
|
||||
channel,
|
||||
offset,
|
||||
i;
|
||||
|
||||
for (channel = 0; channel < this.channels; channel++) {
|
||||
audioData = audioBuffer.getChannelData(channel);
|
||||
offset = channel;
|
||||
for (i = 0; i < length; i++) {
|
||||
audioData[i] = this.samples[offset];
|
||||
offset += this.channels;
|
||||
}
|
||||
}
|
||||
|
||||
bufferSource.buffer = audioBuffer;
|
||||
bufferSource.connect(this.gainNode);
|
||||
bufferSource.start();
|
||||
this.samples = [];
|
||||
}
|
||||
}
|
@ -0,0 +1,77 @@
|
||||
// Karma configuration
|
||||
// Generated on Fri Nov 03 2017 16:10:03 GMT+0600 (+06)
|
||||
|
||||
module.exports = function(config) {
|
||||
config.set({
|
||||
|
||||
// base path that will be used to resolve all patterns (eg. files, exclude)
|
||||
basePath: '',
|
||||
|
||||
|
||||
// frameworks to use
|
||||
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
|
||||
frameworks: ['mocha'],
|
||||
|
||||
// list of files / patterns to load in the browser
|
||||
files: [
|
||||
'test/*.js'
|
||||
],
|
||||
|
||||
// list of files to exclude
|
||||
exclude: [
|
||||
],
|
||||
|
||||
// preprocess matching files before serving them to the browser
|
||||
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
|
||||
preprocessors: {
|
||||
'test/*.js': ['rollup']
|
||||
},
|
||||
|
||||
rollupPreprocessor: {
|
||||
plugins: [
|
||||
require('rollup-plugin-node-globals')(),
|
||||
require('rollup-plugin-node-builtins')(),
|
||||
require('rollup-plugin-babel')()
|
||||
],
|
||||
format: 'iife', // Helps prevent naming collisions.
|
||||
name: 'Decoder', // Required for 'iife' format.
|
||||
sourcemap: 'inline' // Sensible for testing.
|
||||
},
|
||||
|
||||
// test results reporter to use
|
||||
// possible values: 'dots', 'progress'
|
||||
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
|
||||
reporters: ['progress'],
|
||||
|
||||
|
||||
// web server port
|
||||
port: 9876,
|
||||
|
||||
|
||||
// enable / disable colors in the output (reporters and logs)
|
||||
colors: true,
|
||||
|
||||
|
||||
// level of logging
|
||||
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
|
||||
logLevel: config.LOG_INFO,
|
||||
|
||||
|
||||
// enable / disable watching file and executing tests whenever any file changes
|
||||
autoWatch: false,
|
||||
|
||||
|
||||
// start these browsers
|
||||
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
|
||||
browsers: ['Chrome'],
|
||||
|
||||
|
||||
// Continuous Integration mode
|
||||
// if true, Karma captures browsers, runs the tests and exits
|
||||
singleRun: true,
|
||||
|
||||
// Concurrency level
|
||||
// how many browser should be started simultaneous
|
||||
concurrency: Infinity
|
||||
})
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
export default class Event {
|
||||
constructor(type) {
|
||||
this.listener = {};
|
||||
this.type = type | '';
|
||||
}
|
||||
|
||||
on(event, fn) {
|
||||
if (!this.listener[event]) {
|
||||
this.listener[event] = [];
|
||||
}
|
||||
this.listener[event].push(fn);
|
||||
return true;
|
||||
}
|
||||
|
||||
off(event, fn) {
|
||||
if (this.listener[event]) {
|
||||
var index = this.listener[event].indexOf(fn);
|
||||
if (index > -1) {
|
||||
this.listener[event].splice(index, 1);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
offAll() {
|
||||
this.listener = {};
|
||||
}
|
||||
|
||||
dispatch(event, data) {
|
||||
if (this.listener[event]) {
|
||||
this.listener[event].map((each) => {
|
||||
each.apply(null, [data]);
|
||||
});
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
import {equal, deepEqual} from 'assert';
|
||||
import Event from '../src/utils/event.js';
|
||||
|
||||
var event = new Event('XYZ');
|
||||
|
||||
var callback = function() {
|
||||
};
|
||||
|
||||
describe('event tests --', function() {
|
||||
|
||||
beforeEach(function(){
|
||||
event.offAll();
|
||||
event.on('topic1',callback);
|
||||
event.on('topic1',callback);
|
||||
event.on('topic2',callback);
|
||||
});
|
||||
|
||||
it('listener should be 2 for the topic1', function() {
|
||||
equal(event.listener.topic1.length, 2);
|
||||
});
|
||||
|
||||
it('event dispatcher should be return true for a successful dispatcher', function() {
|
||||
equal(event.dispatch('topic1', true), true);
|
||||
});
|
||||
|
||||
it('listener should be zero after removing all listeners', function() {
|
||||
event.offAll();
|
||||
deepEqual(event.listener, {});
|
||||
});
|
||||
});
|
||||
|
@ -0,0 +1,34 @@
|
||||
import {equal} from 'assert';
|
||||
import Ogg from '../src/utils/ogg.js';
|
||||
var channel = 1,
|
||||
decoder = new Ogg(channel),
|
||||
audioCtx = new (window.AudioContext || window.webkitAudioContext)(),
|
||||
sampleRate = audioCtx.sampleRate;
|
||||
|
||||
|
||||
describe('Ogg tests -- ', function() {
|
||||
it('sample rate should be same system sample rate', function() {
|
||||
equal(decoder.getSampleRate(), sampleRate);
|
||||
});
|
||||
|
||||
it('magic Signature of ID header should be Opus Head', function() {
|
||||
var idHeader = decoder.getIDHeader();
|
||||
var dv = new DataView(idHeader.buffer);
|
||||
equal(dv.getUint32(0, true), 1937076303);
|
||||
equal(dv.getUint32(4, true), 1684104520);
|
||||
});
|
||||
|
||||
it('magic Signature of comment header should be Opus Tags', function() {
|
||||
var commonHeader = decoder.getCommentHeader();
|
||||
var dv = new DataView(commonHeader.buffer);
|
||||
equal(dv.getUint32(0, true), 1937076303);
|
||||
equal(dv.getUint32(4, true), 1936154964);
|
||||
});
|
||||
|
||||
it('page header should be started with OggS', function() {
|
||||
var segmentData = new Uint8Array(20);
|
||||
var page = decoder.getPage(segmentData, 4);
|
||||
var dv = new DataView(page.buffer);
|
||||
equal(dv.getUint32(0, true), 1399285583);
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue