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

MessagingSession reconnects with refreshed endpoint and credentials if needed #2400

Merged
merged 12 commits into from
Aug 17, 2022

Conversation

dpwspoon
Copy link
Contributor

@dpwspoon dpwspoon commented Aug 15, 2022

Issue #:

Fixs 4401 from #2372

Description of changes:

MessagingSession reconnects with refreshed endpoint and credentials if needed. This is an updated version of #2180 that was reverted

Testing:

Tested with demo app (see below)

Can these tested using a demo application? Please provide reproducible step-by-step instructions.

  1. Run the messagingSession demo here: https://github.com/aws/amazon-chime-sdk-js/tree/main/demos/browser. npm run start --app=messagingSession
  2. connect with an app instance user
  3. Disconnect Wifi
  4. wait ~20 secs
  5. Reconnect Wifi and see reconnect

Then test again with the following diff to see working on v2 version of client:

diff --git a/demos/browser/app/messagingSession/messagingSession.ts b/demos/browser/app/messagingSession/messagingSession.ts
index 2757af4d..9f408593 100644
--- a/demos/browser/app/messagingSession/messagingSession.ts
+++ b/demos/browser/app/messagingSession/messagingSession.ts
@@ -20,7 +20,7 @@ import {
   Versioning,
 } from 'amazon-chime-sdk-js';
 
-import { ChimeSDKMessagingClient } from '@aws-sdk/client-chime-sdk-messaging';
+import { ChimeSDKMessaging } from '@aws-sdk/client-chime-sdk-messaging';
 
 export class DemoMessagingSessionApp implements MessagingSessionObserver {
   static readonly BASE_URL: string = [
@@ -56,7 +56,7 @@ export class DemoMessagingSessionApp implements MessagingSessionObserver {
     document.getElementById('connect').addEventListener('click', async () => {
       try {
         const response = await this.fetchCredentials();
-        const chime = new ChimeSDKMessagingClient({ region: 'us-east-1', credentials: response });
+        const chime = new ChimeSDKMessaging({ region: 'us-east-1', credentials: response });
         this.userArn = (document.getElementById('userArn') as HTMLInputElement).value;
         this.sessionId = (document.getElementById('sessionId') as HTMLInputElement).value;
         this.prefetchSortByUnread = (document.getElementById('prefetchSortByUnread') as HTMLInputElement).checked;

During the testing suggest looking at networking console to see disconnect, retries, and retry success when wifi comes back up

Checklist:

  1. Have you successfully run npm run build:release locally?

yes

  1. Do you add, modify, or delete public API definitions? If yes, has that been reviewed and approved?

yes these have been reviewed

  1. Do you change the wire protocol, e.g. the request method? If yes, has that been reviewed and approved?

no

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@dpwspoon dpwspoon requested a review from a team as a code owner August 15, 2022 22:16
duh17
duh17 previously approved these changes Aug 15, 2022
@@ -47,13 +47,17 @@ export default class MessagingSessionConfiguration {
/**
* Constructs a MessagingSessionConfiguration optionally with userArn, messaging session id, a messaging session
* endpoint URL, and the chimeClient.
*
* endpointUrl is deprecated and should not be used. Internally it is resolved on connect via chimeClient if undefined, and
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const closeEvent = new CloseEvent('close', {
wasClean: false,
code: 4999,
reason: 'Failed to getMessagingSessionEndpoint',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since getMessagingSessionEndpoint is an function on AWS SDK v2, this would be irrelevant to AWS SDK v3. So should we change it to just 'Failed to get messaging session endpoint URL'?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thx will update

@@ -105,7 +107,32 @@ export default class DefaultMessagingSession implements MessagingSession {
}

private async startConnecting(reconnecting: boolean): Promise<void> {
const signedUrl = await this.prepareWebSocketUrl();
// reconnect needs to re-resolve endpoint url, which will also refresh credentials on client if they are expired
let endpointUrl = !reconnecting ? this.configuration.endpointUrl : undefined;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: is this better to read?

let endpointUrl = this.configuration.endpointUrl;
// reconnect needs to re-resolve endpoint url, which will also refresh credentials on client if they are expired
if (reconnecting || endpointUrl === undefined) {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, think so. Will update thx

@ltrung
Copy link
Contributor

ltrung commented Aug 16, 2022

Can we verify with both v2 and v3 (different importing) to make sure it works ?

@dpwspoon
Copy link
Contributor Author

Can we verify with both v2 and v3 (different importing) to make sure it works ?

Done, and updated directions on pr on how to do

done();
},
});
messagingSession.start();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With v3, you have to use await as the messagingSession.start returns a promise now:
https://github.com/aws/amazon-chime-sdk-js/blob/main/guides/17_Migration_to_3_0.md#remove-aws-global-object-from-messagingsessionconfigurationts

Also could you please update the migration doc for the same and make the endpointUrl undefined there as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also could you please update the migration doc for the same and make the endpointUrl undefined there as well?

Done

ltrung
ltrung previously approved these changes Aug 17, 2022
CHANGELOG.md Outdated Show resolved Hide resolved
@devalevenkatesh devalevenkatesh merged commit bce872c into main Aug 17, 2022
@devalevenkatesh devalevenkatesh deleted the feature/reconnect branch August 17, 2022 21:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants