Skip to content

Commit

Permalink
Prefetch feature adoption 3.x (#2266)
Browse files Browse the repository at this point in the history
* Add in support for prefetch-on for websocket connection on messaging session
  • Loading branch information
jingwy authored Jun 2, 2022
1 parent 64f3a4a commit dd49fd7
Show file tree
Hide file tree
Showing 16 changed files with 622 additions and 352 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added
- Add the reserved status code AudioDisconnectAudio.
- Add support in `MessagingSession` to allow websocket connection for messaging service to enable Prefetch feature.

### Removed

Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,13 @@ const sessionId = /* The sessionId */;
const configuration = new MessagingSessionConfiguration(userArn, sessionId, endpoint.Endpoint.Url, 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.
Prefetch feature will send out CHANNEL_DETAILS event upon websocket connection, which includes information about channel,
channel messages, channel memberships etc.

```js
configuration.prefetchOn = PrefetchOn.Connect;
```

## Building and testing

Expand Down
6 changes: 5 additions & 1 deletion demos/browser/app/messagingSession/messagingSession.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ <h1 class="h3 mb-3 font-weight-normal">Messaging Session</h1>
<label for="sessionId" class="sr-only">SessionId(optional):</label>
<input type="text" id="sessionId" name="sessionId" class="form-control" placeholder="SessionId">
</div>
<div class="custom-control custom-checkbox" style="text-align: left;">
<input type="checkbox" id="prefetchOn" class="custom-control-input">
<label for="prefetchOn" class="custom-control-label">Connect with prefetch on</label>
</div>
<div class="row mt-3">
<button id="connect" type="button" class="btn btn-lg btn-primary btn-block">
Connect
Expand Down Expand Up @@ -57,4 +61,4 @@ <h1 class="h3 mb-3 font-weight-normal">Messaging Session</h1>
</div>
</div>
</body>
</html>
</html>
6 changes: 6 additions & 0 deletions demos/browser/app/messagingSession/messagingSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
MessagingSessionObserver,
MessagingSession,
MessagingSessionConfiguration,
PrefetchOn,
Versioning,
} from 'amazon-chime-sdk-js';

Expand All @@ -33,6 +34,7 @@ export class DemoMessagingSessionApp implements MessagingSessionObserver {
configuration: MessagingSessionConfiguration;
session: MessagingSession;
sessionId: string;
prefetchOn = false;

constructor() {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand All @@ -57,7 +59,11 @@ export class DemoMessagingSessionApp implements MessagingSessionObserver {
const endpoint = await chime.send(new GetMessagingSessionEndpointCommand());
this.userArn = (document.getElementById('userArn') as HTMLInputElement).value;
this.sessionId = (document.getElementById('sessionId') as HTMLInputElement).value;
this.prefetchOn = (document.getElementById('prefetchOn') as HTMLInputElement).checked;
this.configuration = new MessagingSessionConfiguration(this.userArn, this.sessionId, endpoint.Endpoint.Url, chime);
if (this.prefetchOn) {
this.configuration.prefetchOn = PrefetchOn.Connect;
}
this.session = new DefaultMessagingSession(this.configuration, this.logger);
this.session.addObserver(this);
this.session.start();
Expand Down
679 changes: 345 additions & 334 deletions docs/assets/js/search.json

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions docs/classes/defaultmessagingsession.html
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,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#L23">src/messagingsession/DefaultMessagingSession.ts:23</a></li>
<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>
</ul>
</aside>
<h4 class="tsd-parameters-title">Parameters</h4>
Expand Down Expand Up @@ -154,7 +154,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#L53">src/messagingsession/DefaultMessagingSession.ts:53</a></li>
<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>
</ul>
</aside>
<h4 class="tsd-parameters-title">Parameters</h4>
Expand All @@ -177,7 +177,7 @@ <h3>for<wbr>Each<wbr>Observer</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#L81">src/messagingsession/DefaultMessagingSession.ts:81</a></li>
<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>
</ul>
</aside>
<h4 class="tsd-parameters-title">Parameters</h4>
Expand Down Expand Up @@ -219,7 +219,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#L58">src/messagingsession/DefaultMessagingSession.ts:58</a></li>
<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>
</ul>
</aside>
<h4 class="tsd-parameters-title">Parameters</h4>
Expand All @@ -243,7 +243,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#L63">src/messagingsession/DefaultMessagingSession.ts:63</a></li>
<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>
</ul>
</aside>
<h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">Promise</span><span class="tsd-signature-symbol">&lt;</span><span class="tsd-signature-type">void</span><span class="tsd-signature-symbol">&gt;</span></h4>
Expand All @@ -261,7 +261,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#L71">src/messagingsession/DefaultMessagingSession.ts:71</a></li>
<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>
</ul>
</aside>
<h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">void</span></h4>
Expand Down
38 changes: 29 additions & 9 deletions docs/classes/messagingsessionconfiguration.html
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ <h3>Properties</h3>
<li class="tsd-kind-property tsd-parent-kind-class"><a href="messagingsessionconfiguration.html#chimeclient" class="tsd-kind-icon">chime<wbr>Client</a></li>
<li class="tsd-kind-property tsd-parent-kind-class"><a href="messagingsessionconfiguration.html#endpointurl" class="tsd-kind-icon">endpoint<wbr>Url</a></li>
<li class="tsd-kind-property tsd-parent-kind-class"><a href="messagingsessionconfiguration.html#messagingsessionid" class="tsd-kind-icon">messaging<wbr>Session<wbr>Id</a></li>
<li class="tsd-kind-property tsd-parent-kind-class"><a href="messagingsessionconfiguration.html#prefetchon" class="tsd-kind-icon">prefetch<wbr>On</a></li>
<li class="tsd-kind-property tsd-parent-kind-class"><a href="messagingsessionconfiguration.html#reconnectfixedwaitms" class="tsd-kind-icon">reconnect<wbr>Fixed<wbr>Wait<wbr>Ms</a></li>
<li class="tsd-kind-property tsd-parent-kind-class"><a href="messagingsessionconfiguration.html#reconnectlongbackoffms" class="tsd-kind-icon">reconnect<wbr>Long<wbr>Backoff<wbr>Ms</a></li>
<li class="tsd-kind-property tsd-parent-kind-class"><a href="messagingsessionconfiguration.html#reconnectshortbackoffms" class="tsd-kind-icon">reconnect<wbr>Short<wbr>Backoff<wbr>Ms</a></li>
Expand All @@ -120,7 +121,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/MessagingSessionConfiguration.ts#L28">src/messagingsession/MessagingSessionConfiguration.ts:28</a></li>
<li>Defined in <a href="https://github.com/aws/amazon-chime-sdk-js/blob/main/src/messagingsession/MessagingSessionConfiguration.ts#L36">src/messagingsession/MessagingSessionConfiguration.ts:36</a></li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
Expand Down Expand Up @@ -159,7 +160,7 @@ <h3>chime<wbr>Client</h3>
<div class="tsd-signature tsd-kind-icon">chime<wbr>Client<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">any</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/aws/amazon-chime-sdk-js/blob/main/src/messagingsession/MessagingSessionConfiguration.ts#L40">src/messagingsession/MessagingSessionConfiguration.ts:40</a></li>
<li>Defined in <a href="https://github.com/aws/amazon-chime-sdk-js/blob/main/src/messagingsession/MessagingSessionConfiguration.ts#L48">src/messagingsession/MessagingSessionConfiguration.ts:48</a></li>
</ul>
</aside>
</section>
Expand All @@ -169,7 +170,7 @@ <h3>endpoint<wbr>Url</h3>
<div class="tsd-signature tsd-kind-icon">endpoint<wbr>Url<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">string</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/aws/amazon-chime-sdk-js/blob/main/src/messagingsession/MessagingSessionConfiguration.ts#L39">src/messagingsession/MessagingSessionConfiguration.ts:39</a></li>
<li>Defined in <a href="https://github.com/aws/amazon-chime-sdk-js/blob/main/src/messagingsession/MessagingSessionConfiguration.ts#L47">src/messagingsession/MessagingSessionConfiguration.ts:47</a></li>
</ul>
</aside>
</section>
Expand All @@ -179,17 +180,33 @@ <h3>messaging<wbr>Session<wbr>Id</h3>
<div class="tsd-signature tsd-kind-icon">messaging<wbr>Session<wbr>Id<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">string</span><span class="tsd-signature-symbol"> | </span><span class="tsd-signature-type">null</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/aws/amazon-chime-sdk-js/blob/main/src/messagingsession/MessagingSessionConfiguration.ts#L38">src/messagingsession/MessagingSessionConfiguration.ts:38</a></li>
<li>Defined in <a href="https://github.com/aws/amazon-chime-sdk-js/blob/main/src/messagingsession/MessagingSessionConfiguration.ts#L46">src/messagingsession/MessagingSessionConfiguration.ts:46</a></li>
</ul>
</aside>
</section>
<section class="tsd-panel tsd-member tsd-kind-property tsd-parent-kind-class">
<a name="prefetchon" class="tsd-anchor"></a>
<h3>prefetch<wbr>On</h3>
<div class="tsd-signature tsd-kind-icon">prefetch<wbr>On<span class="tsd-signature-symbol">:</span> <a href="../enums/prefetchon.html" class="tsd-signature-type">PrefetchOn</a><span class="tsd-signature-symbol"> | </span><span class="tsd-signature-type">undefined</span><span class="tsd-signature-symbol"> = undefined</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/aws/amazon-chime-sdk-js/blob/main/src/messagingsession/MessagingSessionConfiguration.ts#L36">src/messagingsession/MessagingSessionConfiguration.ts:36</a></li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
<div class="lead">
<p>The enum to indicate if we want to turn on prefetch feature. Prefetch feature will send out CHANNEL_DETAILS event
upon websocket connection, which includes information about channel, channel messages, channel memberships etc.</p>
</div>
</div>
</section>
<section class="tsd-panel tsd-member tsd-kind-property tsd-parent-kind-class">
<a name="reconnectfixedwaitms" class="tsd-anchor"></a>
<h3>reconnect<wbr>Fixed<wbr>Wait<wbr>Ms</h3>
<div class="tsd-signature tsd-kind-icon">reconnect<wbr>Fixed<wbr>Wait<wbr>Ms<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">number</span><span class="tsd-signature-symbol"> = 0</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/aws/amazon-chime-sdk-js/blob/main/src/messagingsession/MessagingSessionConfiguration.ts#L18">src/messagingsession/MessagingSessionConfiguration.ts:18</a></li>
<li>Defined in <a href="https://github.com/aws/amazon-chime-sdk-js/blob/main/src/messagingsession/MessagingSessionConfiguration.ts#L20">src/messagingsession/MessagingSessionConfiguration.ts:20</a></li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
Expand All @@ -204,7 +221,7 @@ <h3>reconnect<wbr>Long<wbr>Backoff<wbr>Ms</h3>
<div class="tsd-signature tsd-kind-icon">reconnect<wbr>Long<wbr>Backoff<wbr>Ms<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">number</span><span class="tsd-signature-symbol"> = 5 * 1000</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/aws/amazon-chime-sdk-js/blob/main/src/messagingsession/MessagingSessionConfiguration.ts#L28">src/messagingsession/MessagingSessionConfiguration.ts:28</a></li>
<li>Defined in <a href="https://github.com/aws/amazon-chime-sdk-js/blob/main/src/messagingsession/MessagingSessionConfiguration.ts#L30">src/messagingsession/MessagingSessionConfiguration.ts:30</a></li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
Expand All @@ -219,7 +236,7 @@ <h3>reconnect<wbr>Short<wbr>Backoff<wbr>Ms</h3>
<div class="tsd-signature tsd-kind-icon">reconnect<wbr>Short<wbr>Backoff<wbr>Ms<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">number</span><span class="tsd-signature-symbol"> = 1 * 1000</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/aws/amazon-chime-sdk-js/blob/main/src/messagingsession/MessagingSessionConfiguration.ts#L23">src/messagingsession/MessagingSessionConfiguration.ts:23</a></li>
<li>Defined in <a href="https://github.com/aws/amazon-chime-sdk-js/blob/main/src/messagingsession/MessagingSessionConfiguration.ts#L25">src/messagingsession/MessagingSessionConfiguration.ts:25</a></li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
Expand All @@ -234,7 +251,7 @@ <h3>reconnect<wbr>Timeout<wbr>Ms</h3>
<div class="tsd-signature tsd-kind-icon">reconnect<wbr>Timeout<wbr>Ms<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">number</span><span class="tsd-signature-symbol"> = 10 * 1000</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/aws/amazon-chime-sdk-js/blob/main/src/messagingsession/MessagingSessionConfiguration.ts#L13">src/messagingsession/MessagingSessionConfiguration.ts:13</a></li>
<li>Defined in <a href="https://github.com/aws/amazon-chime-sdk-js/blob/main/src/messagingsession/MessagingSessionConfiguration.ts#L15">src/messagingsession/MessagingSessionConfiguration.ts:15</a></li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
Expand All @@ -249,7 +266,7 @@ <h3>user<wbr>Arn</h3>
<div class="tsd-signature tsd-kind-icon">user<wbr>Arn<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">string</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/aws/amazon-chime-sdk-js/blob/main/src/messagingsession/MessagingSessionConfiguration.ts#L37">src/messagingsession/MessagingSessionConfiguration.ts:37</a></li>
<li>Defined in <a href="https://github.com/aws/amazon-chime-sdk-js/blob/main/src/messagingsession/MessagingSessionConfiguration.ts#L45">src/messagingsession/MessagingSessionConfiguration.ts:45</a></li>
</ul>
</aside>
</section>
Expand Down Expand Up @@ -282,6 +299,9 @@ <h3>user<wbr>Arn</h3>
<li class=" tsd-kind-property tsd-parent-kind-class">
<a href="messagingsessionconfiguration.html#messagingsessionid" class="tsd-kind-icon">messaging<wbr>Session<wbr>Id</a>
</li>
<li class=" tsd-kind-property tsd-parent-kind-class">
<a href="messagingsessionconfiguration.html#prefetchon" class="tsd-kind-icon">prefetch<wbr>On</a>
</li>
<li class=" tsd-kind-property tsd-parent-kind-class">
<a href="messagingsessionconfiguration.html#reconnectfixedwaitms" class="tsd-kind-icon">reconnect<wbr>Fixed<wbr>Wait<wbr>Ms</a>
</li>
Expand Down
Loading

0 comments on commit dd49fd7

Please sign in to comment.