Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix sample 13 for wrong Speech Services region #2482

Merged
merged 4 commits into from
Oct 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Fix [#2428](https://github.com/microsoft/BotFramework-WebChat/issues/2428). Should interrupt speech synthesis after microphone button is clicked, by [@compulim](https://github.com/compulim) in PR [#2429](https://github.com/microsoft/BotFramework-WebChat/pull/2429)
- Fix [#2435](https://github.com/microsoft/BotFramework-WebChat/issues/2435). Fix microphone button getting stuck on voice-triggered expecting input hint without a speech synthesis engine, by [@compulim](https://github.com/compulim) in PR [#2445](https://github.com/microsoft/BotFramework-WebChat/pull/2445)
- Fix [#2472](https://github.com/microsoft/BotFramework-WebChat/issues/2472). Update samples to use repo's version of React, by [@corinagum](https://github.com/corinagum) in PR [#2478](https://github.com/microsoft/BotFramework-WebChat/pull/2478)
- Fix [#2473](https://github.com/microsoft/BotFramework-WebChat/issues/2473). Fix samples 13 using wrong region for Speech Services credentials, by [@compulim](https://github.com/compulim) in PR [#2482](https://github.com/microsoft/BotFramework-WebChat/pull/2482)

### Added

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions __tests__/richCards.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ test('audio card', async () => {
const audioElement = await driver.findElement(By.css('audio'));

await driver.wait(mediaBuffered(audioElement));
await pageObjects.playMediaToCompletion(audioElement);

const base64PNG = await driver.takeScreenshot();

Expand Down
2 changes: 2 additions & 0 deletions __tests__/setup/pageObjects/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import getSendBoxText from './getSendBoxText';
import getStore from './getStore';
import isDictating from './isDictating';
import pingBot from './pingBot';
import playMediaToCompletion from './playMediaToCompletion';
import putSpeechRecognitionResult from './putSpeechRecognitionResult';
import sendFile from './sendFile';
import sendMessageViaMicrophone from './sendMessageViaMicrophone';
Expand Down Expand Up @@ -48,6 +49,7 @@ export default function pageObjects(driver) {
getStore,
isDictating,
pingBot,
playMediaToCompletion,
putSpeechRecognitionResult,
sendFile,
sendMessageViaMicrophone,
Expand Down
14 changes: 14 additions & 0 deletions __tests__/setup/pageObjects/playMediaToCompletion.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import executePromiseScript from './executePromiseScript';

export default async function pingBot(driver, mediaElement) {
await executePromiseScript(
driver,
mediaElement =>
new Promise(resolve => {
mediaElement.loop = false;
mediaElement.play();
mediaElement.onended = resolve;
}),
mediaElement
);
}
8 changes: 5 additions & 3 deletions samples/13.customization-speech-ui/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ import React, { Component } from 'react';

import CustomDictationInterims from './CustomDictationInterims';
import CustomMicrophoneButton from './CustomMicrophoneButton';
import fetchSpeechServicesToken from './fetchSpeechServicesToken';
import {
region as fetchSpeechServicesRegion,
token as fetchSpeechServicesToken
} from './fetchSpeechServicesCredentials';
import LastBotActivity from './LastBotActivity';

const { Composer } = Components;
Expand All @@ -27,9 +30,8 @@ export default class App extends Component {
const res = await fetch('https://webchat-mockbot.azurewebsites.net/directline/token', { method: 'POST' });
const { token } = await res.json();
const webSpeechPonyfillFactory = await createCognitiveServicesSpeechServicesPonyfillFactory({
// TODO: [P3] Fetch token should be able to return different region
authorizationToken: fetchSpeechServicesToken,
region: 'westus'
region: await fetchSpeechServicesRegion()
});

this.setState(() => ({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,27 @@
const RENEW_EVERY = 300000;
let fetchPromise,
lastFetch = 0;
let fetchPromise;
let lastFetch = 0;

async function region() {
const { region } = await fetchCredentials();

return region;
}

async function token() {
const { token } = await fetchCredentials();

return token;
}

// This fetch function will be called every time Web Speech recognizer or synthesizer start
// You are advised to cache the token to prevent unnecessary network call and delay
export default function() {
async function fetchCredentials() {
const now = Date.now();

if (!fetchPromise || now - lastFetch > RENEW_EVERY) {
fetchPromise = fetch('https://webchat-mockbot.azurewebsites.net/speechservices/token', { method: 'POST' })
.then(res => res.json())
.then(({ token }) => token)
.catch(() => {
lastFetch = 0;
});
Expand All @@ -20,3 +31,6 @@ export default function() {

return fetchPromise;
}

export default fetchCredentials;
export { region, token };