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
Merged
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed

- Fix `AbortError` when turning video ON in Safari.
- `MessagingSession` reconnects with refreshed endpoint and credentials if needed. `EndpointUrl` on `MessagingSessionConfiguration` is deprecated as it is resolved by calling `getMessagingSessionEndpoint` internally.

## [3.6.0] - 2022-06-23

Expand Down
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ The value of the MediaRegion parameter in the createMeeting() should ideally be
Create a messaging session in your client application to receive messages from Amazon Chime SDK for Messaging.

```js
import { ChimeSDKMessagingClient, GetMessagingSessionEndpointCommand } from '@aws-sdk/client-chime-sdk-messaging';
import { ChimeSDKMessagingClient } from '@aws-sdk/client-chime-sdk-messaging';

import {
ConsoleLogger,
Expand All @@ -243,11 +243,10 @@ const logger = new ConsoleLogger('SDK', LogLevel.INFO);

// You will need AWS credentials configured before calling AWS or Amazon Chime APIs.
const chime = new ChimeSDKMessagingClient({ region: 'us-east-1'});
const endpoint = await chime.send(new GetMessagingSessionEndpointCommand());

const userArn = /* The userArn */;
const sessionId = /* The sessionId */;
const configuration = new MessagingSessionConfiguration(userArn, sessionId, endpoint.Endpoint.Url, chime);
const configuration = new MessagingSessionConfiguration(userArn, sessionId, undefined, chime);
const messagingSession = new DefaultMessagingSession(configuration, logger);
```
If you would like to enable prefetch feature when connecting to a messaging session, you can follow the code below.
Expand Down
5 changes: 2 additions & 3 deletions demos/browser/app/messagingSession/messagingSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
Versioning,
} from 'amazon-chime-sdk-js';

import {ChimeSDKMessagingClient, GetMessagingSessionEndpointCommand} from '@aws-sdk/client-chime-sdk-messaging';
import { ChimeSDKMessagingClient } from '@aws-sdk/client-chime-sdk-messaging';

export class DemoMessagingSessionApp implements MessagingSessionObserver {
static readonly BASE_URL: string = [
Expand Down Expand Up @@ -57,12 +57,11 @@ export class DemoMessagingSessionApp implements MessagingSessionObserver {
try {
const response = await this.fetchCredentials();
const chime = new ChimeSDKMessagingClient({ region: 'us-east-1', credentials: response });
const endpoint = await chime.send(new GetMessagingSessionEndpointCommand());
this.userArn = (document.getElementById('userArn') as HTMLInputElement).value;
this.sessionId = (document.getElementById('sessionId') as HTMLInputElement).value;
this.prefetchSortByUnread = (document.getElementById('prefetchSortByUnread') as HTMLInputElement).checked;
this.prefetchSortByLastMessageTimestamp = (document.getElementById('prefetchSortByLastMessageTimestamp') as HTMLInputElement).checked;
this.configuration = new MessagingSessionConfiguration(this.userArn, this.sessionId, endpoint.Endpoint.Url, chime);
this.configuration = new MessagingSessionConfiguration(this.userArn, this.sessionId, undefined, chime);
if (this.prefetchSortByUnread) {
this.configuration.prefetchOn = PrefetchOn.Connect;
this.configuration.prefetchSortBy = PrefetchSortBy.Unread
Expand Down
2 changes: 2 additions & 0 deletions demos/browser/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions docs/classes/defaultmessagingsession.html
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ <h3>constructor</h3>
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/aws/amazon-chime-sdk-js/blob/main/src/messagingsession/DefaultMessagingSession.ts#L24">src/messagingsession/DefaultMessagingSession.ts:24</a></li>
<li>Defined in <a href="https://github.com/aws/amazon-chime-sdk-js/blob/main/src/messagingsession/DefaultMessagingSession.ts#L26">src/messagingsession/DefaultMessagingSession.ts:26</a></li>
</ul>
</aside>
<h4 class="tsd-parameters-title">Parameters</h4>
Expand Down Expand Up @@ -153,7 +153,7 @@ <h3>add<wbr>Observer</h3>
<aside class="tsd-sources">
<p>Implementation of <a href="../interfaces/messagingsession.html">MessagingSession</a>.<a href="../interfaces/messagingsession.html#addobserver">addObserver</a></p>
<ul>
<li>Defined in <a href="https://github.com/aws/amazon-chime-sdk-js/blob/main/src/messagingsession/DefaultMessagingSession.ts#L54">src/messagingsession/DefaultMessagingSession.ts:54</a></li>
<li>Defined in <a href="https://github.com/aws/amazon-chime-sdk-js/blob/main/src/messagingsession/DefaultMessagingSession.ts#L56">src/messagingsession/DefaultMessagingSession.ts:56</a></li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
Expand Down Expand Up @@ -182,7 +182,7 @@ <h3>for<wbr>Each<wbr>Observer</h3>
<aside class="tsd-sources">
<p>Implementation of <a href="../interfaces/messagingsession.html">MessagingSession</a>.<a href="../interfaces/messagingsession.html#foreachobserver">forEachObserver</a></p>
<ul>
<li>Defined in <a href="https://github.com/aws/amazon-chime-sdk-js/blob/main/src/messagingsession/DefaultMessagingSession.ts#L82">src/messagingsession/DefaultMessagingSession.ts:82</a></li>
<li>Defined in <a href="https://github.com/aws/amazon-chime-sdk-js/blob/main/src/messagingsession/DefaultMessagingSession.ts#L84">src/messagingsession/DefaultMessagingSession.ts:84</a></li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
Expand Down Expand Up @@ -230,7 +230,7 @@ <h3>remove<wbr>Observer</h3>
<aside class="tsd-sources">
<p>Implementation of <a href="../interfaces/messagingsession.html">MessagingSession</a>.<a href="../interfaces/messagingsession.html#removeobserver">removeObserver</a></p>
<ul>
<li>Defined in <a href="https://github.com/aws/amazon-chime-sdk-js/blob/main/src/messagingsession/DefaultMessagingSession.ts#L59">src/messagingsession/DefaultMessagingSession.ts:59</a></li>
<li>Defined in <a href="https://github.com/aws/amazon-chime-sdk-js/blob/main/src/messagingsession/DefaultMessagingSession.ts#L61">src/messagingsession/DefaultMessagingSession.ts:61</a></li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
Expand Down Expand Up @@ -259,7 +259,7 @@ <h3>start</h3>
<aside class="tsd-sources">
<p>Implementation of <a href="../interfaces/messagingsession.html">MessagingSession</a>.<a href="../interfaces/messagingsession.html#start">start</a></p>
<ul>
<li>Defined in <a href="https://github.com/aws/amazon-chime-sdk-js/blob/main/src/messagingsession/DefaultMessagingSession.ts#L64">src/messagingsession/DefaultMessagingSession.ts:64</a></li>
<li>Defined in <a href="https://github.com/aws/amazon-chime-sdk-js/blob/main/src/messagingsession/DefaultMessagingSession.ts#L66">src/messagingsession/DefaultMessagingSession.ts:66</a></li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
Expand All @@ -282,7 +282,7 @@ <h3>stop</h3>
<aside class="tsd-sources">
<p>Implementation of <a href="../interfaces/messagingsession.html">MessagingSession</a>.<a href="../interfaces/messagingsession.html#stop">stop</a></p>
<ul>
<li>Defined in <a href="https://github.com/aws/amazon-chime-sdk-js/blob/main/src/messagingsession/DefaultMessagingSession.ts#L72">src/messagingsession/DefaultMessagingSession.ts:72</a></li>
<li>Defined in <a href="https://github.com/aws/amazon-chime-sdk-js/blob/main/src/messagingsession/DefaultMessagingSession.ts#L74">src/messagingsession/DefaultMessagingSession.ts:74</a></li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
Expand Down
8 changes: 5 additions & 3 deletions docs/classes/messagingsessionconfiguration.html
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,12 @@ <h3>constructor</h3>
<div class="tsd-comment tsd-typography">
<div class="lead">
<p>Constructs a MessagingSessionConfiguration optionally with userArn, messaging session id, a messaging session
endpoint URL, and the chimeClient.
The messaging session id is to uniquely identify this messaging session for the userArn.
If messaging session id is passed in as null, it will be automatically generated.</p>
endpoint URL, and the chimeClient.</p>
</div>
<p>endpointUrl is deprecated and should not be used. Internally it is resolved on connect via chimeClient if undefined, and
always re-resolved on reconnect.</p>
<p>The messaging session id is to uniquely identify this messaging session for the userArn.
If messaging session id is passed in as null, it will be automatically generated.</p>
</div>
<h4 class="tsd-parameters-title">Parameters</h4>
<ul class="tsd-parameters">
Expand Down
5 changes: 2 additions & 3 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ <h4>Getting responses from your server application</h4>
<h3>Messaging session</h3>
</a>
<p>Create a messaging session in your client application to receive messages from Amazon Chime SDK for Messaging.</p>
<pre><code class="language-js"><span style="color: #AF00DB">import</span><span style="color: #000000"> { </span><span style="color: #001080">ChimeSDKMessagingClient</span><span style="color: #000000">, </span><span style="color: #001080">GetMessagingSessionEndpointCommand</span><span style="color: #000000"> } </span><span style="color: #AF00DB">from</span><span style="color: #000000"> </span><span style="color: #A31515">&#039;@aws-sdk/client-chime-sdk-messaging&#039;</span><span style="color: #000000">;</span>
<pre><code class="language-js"><span style="color: #AF00DB">import</span><span style="color: #000000"> { </span><span style="color: #001080">ChimeSDKMessagingClient</span><span style="color: #000000"> } </span><span style="color: #AF00DB">from</span><span style="color: #000000"> </span><span style="color: #A31515">&#039;@aws-sdk/client-chime-sdk-messaging&#039;</span><span style="color: #000000">;</span>

<span style="color: #AF00DB">import</span><span style="color: #000000"> {</span>
<span style="color: #000000"> </span><span style="color: #001080">ConsoleLogger</span><span style="color: #000000">,</span>
Expand All @@ -307,11 +307,10 @@ <h3>Messaging session</h3>

<span style="color: #008000">// You will need AWS credentials configured before calling AWS or Amazon Chime APIs.</span>
<span style="color: #0000FF">const</span><span style="color: #000000"> </span><span style="color: #0070C1">chime</span><span style="color: #000000"> = </span><span style="color: #0000FF">new</span><span style="color: #000000"> </span><span style="color: #795E26">ChimeSDKMessagingClient</span><span style="color: #000000">({ </span><span style="color: #001080">region:</span><span style="color: #000000"> </span><span style="color: #A31515">&#039;us-east-1&#039;</span><span style="color: #000000">});</span>
<span style="color: #0000FF">const</span><span style="color: #000000"> </span><span style="color: #0070C1">endpoint</span><span style="color: #000000"> = </span><span style="color: #AF00DB">await</span><span style="color: #000000"> </span><span style="color: #001080">chime</span><span style="color: #000000">.</span><span style="color: #795E26">send</span><span style="color: #000000">(</span><span style="color: #0000FF">new</span><span style="color: #000000"> </span><span style="color: #795E26">GetMessagingSessionEndpointCommand</span><span style="color: #000000">());</span>

<span style="color: #0000FF">const</span><span style="color: #000000"> </span><span style="color: #0070C1">userArn</span><span style="color: #000000"> = </span><span style="color: #008000">/* The userArn */</span><span style="color: #000000">;</span>
<span style="color: #0000FF">const</span><span style="color: #000000"> </span><span style="color: #0070C1">sessionId</span><span style="color: #000000"> = </span><span style="color: #008000">/* The sessionId */</span><span style="color: #000000">;</span>
<span style="color: #0000FF">const</span><span style="color: #000000"> </span><span style="color: #0070C1">configuration</span><span style="color: #000000"> = </span><span style="color: #0000FF">new</span><span style="color: #000000"> </span><span style="color: #795E26">MessagingSessionConfiguration</span><span style="color: #000000">(</span><span style="color: #001080">userArn</span><span style="color: #000000">, </span><span style="color: #001080">sessionId</span><span style="color: #000000">, </span><span style="color: #001080">endpoint</span><span style="color: #000000">.</span><span style="color: #001080">Endpoint</span><span style="color: #000000">.</span><span style="color: #001080">Url</span><span style="color: #000000">, </span><span style="color: #001080">chime</span><span style="color: #000000">);</span>
<span style="color: #0000FF">const</span><span style="color: #000000"> </span><span style="color: #0070C1">configuration</span><span style="color: #000000"> = </span><span style="color: #0000FF">new</span><span style="color: #000000"> </span><span style="color: #795E26">MessagingSessionConfiguration</span><span style="color: #000000">(</span><span style="color: #001080">userArn</span><span style="color: #000000">, </span><span style="color: #001080">sessionId</span><span style="color: #000000">, </span><span style="color: #0000FF">undefined</span><span style="color: #000000">, </span><span style="color: #001080">chime</span><span style="color: #000000">);</span>
<span style="color: #0000FF">const</span><span style="color: #000000"> </span><span style="color: #0070C1">messagingSession</span><span style="color: #000000"> = </span><span style="color: #0000FF">new</span><span style="color: #000000"> </span><span style="color: #795E26">DefaultMessagingSession</span><span style="color: #000000">(</span><span style="color: #001080">configuration</span><span style="color: #000000">, </span><span style="color: #001080">logger</span><span style="color: #000000">);</span>
</code></pre>
<p>If you would like to enable prefetch feature when connecting to a messaging session, you can follow the code below.
Expand Down
4 changes: 2 additions & 2 deletions docs/modules/migrationto_3_0.html
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,10 @@ <h3>Remove AWS global object from <code>MessagingSessionConfiguration.ts</code><
<p><code>MessagingSessionConfiguration</code> used to require to pass in the AWS global object for sigV4 signing which does not
work for aws-sdk v3. Starting with Amazon Chime SDK for JavaScript V3, you no longer have to pass in the global AWS object.</p>
<pre><code class="language-js"><span style="color: #008000">// Before</span>
<span style="color: #0000FF">this</span><span style="color: #000000">.</span><span style="color: #001080">configuration</span><span style="color: #000000"> = </span><span style="color: #0000FF">new</span><span style="color: #000000"> </span><span style="color: #795E26">MessagingSessionConfiguration</span><span style="color: #000000">(</span><span style="color: #0000FF">this</span><span style="color: #000000">.</span><span style="color: #001080">userArn</span><span style="color: #000000">, </span><span style="color: #0000FF">this</span><span style="color: #000000">.</span><span style="color: #001080">sessionId</span><span style="color: #000000">, </span><span style="color: #001080">endpoint</span><span style="color: #000000">.</span><span style="color: #001080">Endpoint</span><span style="color: #000000">.</span><span style="color: #001080">Url</span><span style="color: #000000">, </span><span style="color: #001080">chime</span><span style="color: #000000">, </span><span style="color: #0070C1">AWS</span><span style="color: #000000">);</span>
<span style="color: #0000FF">this</span><span style="color: #000000">.</span><span style="color: #001080">configuration</span><span style="color: #000000"> = </span><span style="color: #0000FF">new</span><span style="color: #000000"> </span><span style="color: #795E26">MessagingSessionConfiguration</span><span style="color: #000000">(</span><span style="color: #0000FF">this</span><span style="color: #000000">.</span><span style="color: #001080">userArn</span><span style="color: #000000">, </span><span style="color: #0000FF">this</span><span style="color: #000000">.</span><span style="color: #001080">sessionId</span><span style="color: #000000">, </span><span style="color: #0000FF">undefined</span><span style="color: #000000">, </span><span style="color: #001080">chime</span><span style="color: #000000">, </span><span style="color: #0070C1">AWS</span><span style="color: #000000">);</span>

<span style="color: #008000">// After</span>
<span style="color: #0000FF">this</span><span style="color: #000000">.</span><span style="color: #001080">configuration</span><span style="color: #000000"> = </span><span style="color: #0000FF">new</span><span style="color: #000000"> </span><span style="color: #795E26">MessagingSessionConfiguration</span><span style="color: #000000">(</span><span style="color: #0000FF">this</span><span style="color: #000000">.</span><span style="color: #001080">userArn</span><span style="color: #000000">, </span><span style="color: #0000FF">this</span><span style="color: #000000">.</span><span style="color: #001080">sessionId</span><span style="color: #000000">, </span><span style="color: #001080">endpoint</span><span style="color: #000000">.</span><span style="color: #001080">Endpoint</span><span style="color: #000000">.</span><span style="color: #001080">Url</span><span style="color: #000000">, </span><span style="color: #001080">chime</span><span style="color: #000000">);</span>
<span style="color: #0000FF">this</span><span style="color: #000000">.</span><span style="color: #001080">configuration</span><span style="color: #000000"> = </span><span style="color: #0000FF">new</span><span style="color: #000000"> </span><span style="color: #795E26">MessagingSessionConfiguration</span><span style="color: #000000">(</span><span style="color: #0000FF">this</span><span style="color: #000000">.</span><span style="color: #001080">userArn</span><span style="color: #000000">, </span><span style="color: #0000FF">this</span><span style="color: #000000">.</span><span style="color: #001080">sessionId</span><span style="color: #000000">, </span><span style="color: #0000FF">undefined</span><span style="color: #000000">, </span><span style="color: #001080">chime</span><span style="color: #000000">);</span>
</code></pre>
<a href="#update-messagingsessionstart-to-return-promiseltvoidgt-instead-of-void" id="update-messagingsessionstart-to-return-promiseltvoidgt-instead-of-void" style="color: inherit; text-decoration: none;">
<h3>Update <code>messagingSession.start</code> to return <code>Promise&lt;void&gt;</code> instead of <code>void</code></h3>
Expand Down
4 changes: 2 additions & 2 deletions guides/17_Migration_to_3_0.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,10 @@ work for aws-sdk v3. Starting with Amazon Chime SDK for JavaScript V3, you no lo

```js
// Before
this.configuration = new MessagingSessionConfiguration(this.userArn, this.sessionId, endpoint.Endpoint.Url, chime, AWS);
this.configuration = new MessagingSessionConfiguration(this.userArn, this.sessionId, undefined, chime, AWS);

// After
this.configuration = new MessagingSessionConfiguration(this.userArn, this.sessionId, endpoint.Endpoint.Url, chime);
this.configuration = new MessagingSessionConfiguration(this.userArn, this.sessionId, undefined, chime);
```

### Update `messagingSession.start` to return `Promise<void>` instead of `void`
Expand Down
Loading