-
Notifications
You must be signed in to change notification settings - Fork 756
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
Update Emulator to Use New Cognitive Service API #1878
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add tests.
if (!this.msaAppId || !this.msaPassword) { | ||
throw new Error('bot must have Microsoft App ID and password'); | ||
} | ||
private isTokenExpired(): boolean { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't duplicate code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With which one? Its not duplacted. If you mean with isTokenExpiringSoon
then it is not. They are different.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean the isTokenExpired
and isTokenExpiringSoon
is too similar.
It may make sense to return the expiry, or building a function named willTokenExpireWithin(durationInMs: number = 0)
.
|
||
const query = new URLSearchParams({ goodForInMinutes: duration } as any); | ||
const res = await this.fetchWithAuth(new URL(`?${query.toString()}`, speechEndpoint.tokenEndpoint).toString()); | ||
private renewTokenBeforeExpiry() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't use then
, use async/await.
@@ -0,0 +1,38 @@ | |||
// |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why there is a dupe file in /sdk/
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should just choose one -- I vote for sdk -- and delete the other one. There should be minimal code churn because the type SpeechTokenInfo
is only used in one place
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After you finish resolving PR feedback, please run the command npm run lint:fix
from the root of the project. This should fix issues like import sorting, however it might not alphabetize them.
@@ -0,0 +1,38 @@ | |||
// |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should just choose one -- I vote for sdk -- and delete the other one. There should be minimal code churn because the type SpeechTokenInfo
is only used in one place
} | ||
|
||
if (!this.msaAppId || !this.msaPassword) { | ||
throw new Error('bot must have Microsoft App ID and password'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean it looks a bit late to throw here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pulled it down and tested it. Looks good to me, but you should address the comments William left. 👍
} | ||
|
||
if (this.speechRegionToken && !refresh && !this.willTokenExpireWithin(0)) { | ||
if (this.willTokenExpireWithin(this.speechRegionToken.tokenLife * 0.5)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (this.willTokenExpireWithin(this.speechRegionToken.tokenLife * 0.5)) { | |
if (this.willTokenExpireWithin(this.speechRegionToken.tokenLife / 2)) { |
} | ||
private willTokenExpireWithin(millisecondsToExpire: number): boolean { | ||
const currentDateTime = new Date(); | ||
const timeFromNowMilliseconds = currentDateTime.getTime() + millisecondsToExpire; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const timeFromNowMilliseconds = currentDateTime.getTime() + millisecondsToExpire; | |
const timeFromNowMilliseconds = Date.now() + millisecondsToExpire; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In addition for comments below, there are couple of things that are still unanswered in previous reviews.
|
||
if (speechAuthenticationToken && speechAuthenticationToken.access_Token && speechAuthenticationToken.region) { | ||
const factory = yield call(createCognitiveServicesSpeechServicesPonyfillFactory, { | ||
authorizationToken: () => Promise.resolve(speechAuthenticationToken.access_Token), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should a Promise function. When called, will fetch the token from the server. And the token need to be cached for its half-life.
9e4d7f5
to
505fd53
Compare
505fd53
to
da0ef01
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me.
If the speech token call is taking too much time, and the user keep clicking on the microphone button. It may end up having multiple ongoing "get token call". I am okay with this for now.
Love your tests. AFAIR, people said test code is statistically 3 times the size of production code.
Let's wait for Chris to test it out.
Nice work @edwin4microsoft & @tonyanziano. Let's resolve conflicts and get it in. |
da0ef01
to
06b0443
Compare
06b0443
to
e2ccb9a
Compare
Update Emulator to Use New Cognitive Service API
Add token refresh 5 minutes before it expires.