forked from GPII/first-discovery
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated to latest version of Infusion to get fix for FLUID-5756
- Loading branch information
Showing
3 changed files
with
117 additions
and
3 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
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
113 changes: 113 additions & 0 deletions
113
src/lib/infusion/src/components/textToSpeech/js/MockTTS.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
/* | ||
Copyright 2015 OCAD University | ||
Licensed under the Educational Community License (ECL), Version 2.0 or the New | ||
BSD license. You may not use this file except in compliance with one these | ||
Licenses. | ||
You may obtain a copy of the ECL 2.0 License and BSD License at | ||
https://github.com/fluid-project/infusion/raw/master/Infusion-LICENSE.txt | ||
*/ | ||
|
||
/* global fluid */ | ||
|
||
(function () { | ||
"use strict"; | ||
|
||
// Mocks the fluid.textToSpeech component, removing calls to the | ||
// Web Speech API. This will allow for tests to run in browsers | ||
// that don't support the Web Speech API. | ||
fluid.defaults("fluid.mock.textToSpeech", { | ||
gradeNames: ["fluid.textToSpeech", "autoInit"], | ||
members: { | ||
// An archive of all the calls to queueSpeech. | ||
// Will contain an ordered set of objects -- {text: String, options: Object}. | ||
speechRecord: [], | ||
// An archive of all the events fired | ||
// Will contain a key/value pairing where key is the name of the event and the | ||
// value is the number of times the event was fired. | ||
eventRecord: {} | ||
}, | ||
listeners: { | ||
"onStart.recordEvent": { | ||
listener: "{that}.recordEvent", | ||
args: ["onStart"] | ||
}, | ||
"onStop.recordEvent": { | ||
listener: "{that}.recordEvent", | ||
args: ["onStop"] | ||
}, | ||
"onSpeechQueued.recordEvent": { | ||
listener: "{that}.recordEvent", | ||
args: ["onSpeechQueued"] | ||
} | ||
}, | ||
invokers: { | ||
queueSpeech: { | ||
funcName: "fluid.mock.textToSpeech.queueSpeech", | ||
args: ["{that}", "{that}.handleStart", "{that}.handleEnd", "{that}.speechRecord", "{arguments}.0", "{arguments}.1", "{arguments}.2"] | ||
}, | ||
cancel: { | ||
funcName: "fluid.mock.textToSpeech.cancel", | ||
args: ["{that}", "{that}.handleEnd"] | ||
}, | ||
pause: { | ||
"this": null, // TODO: This needs to be removed once FLUID-5714 is fixed | ||
method: null, | ||
func: "{that}.events.onPause.fire" | ||
}, | ||
resume: { | ||
"this": null, | ||
method: null, | ||
func: "{that}.events.onResume.fire" | ||
}, | ||
getVoices: { | ||
"this": null, | ||
method: null, | ||
funcName: "fluid.identity", | ||
args: [] | ||
}, | ||
recordEvent: { | ||
funcName: "fluid.mock.textToSpeech.recordEvent", | ||
args: ["{that}.eventRecord", "{arguments}.0"] | ||
} | ||
} | ||
}); | ||
|
||
fluid.mock.textToSpeech.queueSpeech = function (that, handleStart, handleEnd, speechRecord, text, interrupt, options) { | ||
if (interrupt) { | ||
that.cancel(); | ||
} | ||
|
||
var record = { | ||
text: text, | ||
interrupt: !!interrupt | ||
}; | ||
|
||
if (options) { | ||
record.options = options; | ||
} | ||
|
||
speechRecord.push(record); | ||
|
||
that.queue.push(text); | ||
that.events.onSpeechQueued.fire(text); | ||
|
||
// mocking speechSynthesis speak | ||
handleStart(); | ||
// using setTimeout to preserve asynchronous behaviour | ||
setTimeout(handleEnd, 0); | ||
|
||
}; | ||
|
||
fluid.mock.textToSpeech.cancel = function (that, handleEnd) { | ||
that.queue = []; | ||
handleEnd(); | ||
}; | ||
|
||
fluid.mock.textToSpeech.recordEvent = function (eventRecord, name) { | ||
eventRecord[name] = (eventRecord[name] || 0) + 1; | ||
}; | ||
|
||
})(); |