Search code examples
javascriptweb-workervoice-recording

Can't initialize WebWorker in Chrome


I am trying to record voice in browser with the help of code at GitHub link to VoicePin Code

and it seems the worker.postMessage in recorder.js is working but there is no worker thread receiving it. I setup the recorder.js to log messages from all its methods and i see methods up to the time i try to get messages from getBuffers method. After this method is called, the recorderWorker based WebWorker has to callback the callBack method we pass. That is where i see nothing in logs. When i examine code, the recorderWorker.js starts sending back data with onmessage() call for the first time with that callback.

From this, i think the recorderWoker.js is never initialized because the location i give in both recorder.js and audioManager.js is wrong.

Here is my code..

In my page i load the three js files as...

<script type="text/javascript">
<%@include file="../scripts/voicepin/recorder.js" %>
</script>
<script type="text/javascript">
    <%@include file="../scripts/voicepin/recorderWorker.js" %>
</script>
<script type="text/javascript">
    <%@include file="../scripts/voicepin/audiomanager.js" %>
</script>

The following are the two alternative ways i tried to pass on recorder worker's path...

var recorderWorkerPath = 'recorderWorker.js';

alternatively ...

var recorderWorkerPath = 'scripts/voicepin/recorderWorker.js';

The folder scripts is under WEB-INF

Looks like i did not learn anything with passing on file location information properly in web pages. Can someone help?


Solution

  • I made a simple mistake of putting the javaScript files under WEB-INF instead of WebContent. Changing to right position solved it.