Browse Source

get global working from index.js so page import works...

main
John-Mark Gurney 5 years ago
parent
commit
683073f7f9
5 changed files with 69 additions and 4 deletions
  1. +37
    -0
      dist/audiotest.html
  2. +2
    -2
      package.json
  3. +17
    -1
      src/index.js
  4. +12
    -0
      src/index/index.spec.js
  5. +1
    -1
      src/jamming/jamming.spec.js

+ 37
- 0
dist/audiotest.html View File

@@ -0,0 +1,37 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>Audio Test</title>

<!-- <link rel="stylesheet" type="text/css" href="css/styles.css"> -->

</head>

<body>
<p></p>
<script type="text/javascript" src="jamming.js"></script>
<script type="text/javascript">

runPage()

/* parameters */
var params = {
sampleRate: 8000,
frameSize: 100, /* in ms */
};

window.AudioContext = window.AudioContext || window.webkitAudioContext;

var audioContext = new AudioContext();

recconf = {
samplerRate: 8000,
numChannels: 1,
}

</script>
</body>
</html>

+ 2
- 2
package.json View File

@@ -6,8 +6,8 @@
"private": true,
"scripts": {
"build": "yarn run build:lib && yarn run build:webpack",
"build:lib": "babel src/ -d lib/",
"build:webpack": "webpack lib/index.js -o dist/jamming.js",
"build:lib": "rm -rf lib && babel src/ -d lib/",
"build:webpack": "webpack --mode='development' lib/index.js -o dist/jamming.js",
"test": "yarn run build:lib && nyc mocha lib/**/**.spec.js"
},
"author": "John-Mark Gurney <jmg@funkthat.com>",


+ 17
- 1
src/index.js View File

@@ -1 +1,17 @@
module.exports = require("./jamming").Jamming;
const jamming = require("./jamming");

async function runPage() {
var constraints = { audio: true };

let stream = null;

try {
stream = await navigator.mediaDevices.getUserMedia(constraints);
console.log('got stream');
} catch(err) {
console.log('got error');
}
}

// #4 of https://stackoverflow.com/questions/37656592/define-global-variable-with-webpack
global.runPage = runPage;

+ 12
- 0
src/index/index.spec.js View File

@@ -0,0 +1,12 @@
'use strict'

const index = require('../index')
const expect = require('chai').expect

describe('index module', () => {
describe('"members"', () => {
it('should be have the following members', () => {
expect(global.runPage).to.be.a('function');
})
})
})

+ 1
- 1
src/jamming/jamming.spec.js View File

@@ -1,6 +1,6 @@
'use strict'

const Jamming = require('../index')
const Jamming = require('../jamming').Jamming
const expect = require('chai').expect

describe('Jamming class', () => {


Loading…
Cancel
Save