-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Share rhino_worker amongst demos * Format rhino_worker * Add pause/resume to rhino worker
- Loading branch information
David Bartle
authored
Jun 1, 2020
1 parent
d709e49
commit 091a55d
Showing
7 changed files
with
78 additions
and
113 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,4 @@ pv_porcupine.wasm | |
pv_rhino.js | ||
pv_rhino.wasm | ||
rhino.js | ||
rhino_worker.js |
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 was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
Copyright 2018-2020 Picovoice Inc. | ||
You may not use this file except in compliance with the license. A copy of the license is located in the "LICENSE" | ||
file accompanying this source. | ||
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
specific language governing permissions and limitations under the License. | ||
*/ | ||
|
||
importScripts("pv_rhino.js"); | ||
importScripts("rhino.js"); | ||
|
||
onmessage = function (e) { | ||
switch (e.data.command) { | ||
case "init": | ||
init(e.data.context); | ||
break; | ||
case "process": | ||
process(e.data.inputFrame); | ||
break; | ||
case "pause": | ||
paused = true; | ||
break; | ||
case "resume": | ||
paused = false; | ||
break; | ||
case "release": | ||
release(); | ||
break; | ||
} | ||
}; | ||
|
||
let context; | ||
let paused; | ||
let rhino = null; | ||
|
||
function init(context_) { | ||
context = context_; | ||
paused = false; | ||
|
||
if (Rhino.isLoaded()) { | ||
rhino = Rhino.create(context); | ||
} | ||
} | ||
|
||
function process(inputFrame) { | ||
if (rhino === null && Rhino.isLoaded()) { | ||
rhino = Rhino.create(context); | ||
} | ||
|
||
if (!paused) { | ||
if (rhino !== null) { | ||
let result = rhino.process(inputFrame); | ||
if ("isUnderstood" in result) { | ||
postMessage(result); | ||
} | ||
} | ||
} | ||
} | ||
|
||
function release() { | ||
if (rhino != null) { | ||
rhino.release(); | ||
} | ||
|
||
rhino = null; | ||
} |
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 |
---|---|---|
|
@@ -2,4 +2,5 @@ node_modules | |
package-lock.json | ||
pv_rhino.js | ||
pv_rhino.wasm | ||
rhino.js | ||
rhino.js | ||
rhino_worker.js |
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 was deleted.
Oops, something went wrong.