You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Register interest in the Thing Shadow named `thingName`. The thingShadow class will
339
333
subscribe to any applicable topics, and will fire events for the Thing Shadow
@@ -364,6 +358,8 @@ AWS IoT maintains version numbers for each shadow, and will reject operations wh
364
358
contain the incorrect version; in applications where multiple clients update the same
365
359
shadow, clients can use versioning to avoid overwriting each other's changes.
366
360
361
+
If the `callback` parameter is provided, it will be invoked after registration is complete (i.e., when subscription ACKs have been received for all shadow topics). Applications should wait until shadow registration is complete before performing update/get/delete operations.
Identical to the [mqtt.Client#unsubscribe()](https://github.com/mqttjs/MQTT.js/blob/master/README.md#unsubscribe)
453
449
method, with the restriction that the topic may not represent a Thing Shadow.
@@ -811,6 +807,8 @@ This SDK includes a utility script called `scripts/browserize.sh`. This script
811
807
812
808
This command will create a browser bundle in `browser/aws-iot-sdk-browser-bundle.js`. The browser bundle makes both the `aws-sdk` and `aws-iot-device-sdk` modules available so that you can `require` them from your browserified application bundle.
813
809
810
+
**IMPORTANT:** The `scripts/browserize.sh` script requires npm version 3. You can check which version of npm you have installed with `npm -v`.
811
+
814
812
#### Creating Application Bundles
815
813
You can also use the `scripts/browserize.sh` script to browserify your own applications and use them with the AWS SDK browser bundle. For example, to prepare the [temperature-monitor](#temperature-monitor-browser-example) browser example application for use, run this command in the SDK's top-level directory:
816
814
@@ -864,6 +862,7 @@ This SDK includes a browser application which demonstrates the functionality of
864
862
865
863
1. Open `examples/browser/lifecycle/index.html` in your web browser. After connecting to AWS IoT, it should display 'connected clients'.
866
864
1. Start programs which connect to AWS IoT (e.g., [the example programs in this package](#programs)). Make sure that these programs are connecting to the same AWS region that your Cognito Identity Pool was created in. The browser application will display a green box containing the client ID of each client which connects; when the client disconnects, the box will disappear.
865
+
1. If a DynamoDB table named `LifecycleEvents` exists in your account and has a primary key named `clientId`, the lifecycle event browser monitor browser application will display the client ID contained in each row. By updating this table using an [AWS IoT rule](http://docs.aws.amazon.com/iot/latest/developerguide/iot-rules.html) triggered by [lifecycle events](http://docs.aws.amazon.com/iot/latest/developerguide/life-cycle-events.html), you can maintain a persistent list of all of the currently connected clients within your account.
867
866
868
867
<a name="mqtt-explorer-browser-example"></a>
869
868
### MQTT Explorer Browser Example Application
@@ -880,8 +879,54 @@ This SDK includes a browser application which implements a simple interactive MQ
880
879
881
880
1. Open `examples/browser/mqtt-explorer/index.html` in your web browser. After connecting to AWS IoT, it should display input fields allowing you to subscribe or publish to a topic. By subscribing to '#', for example, you will be able to monitor all traffic within your AWS account as allowed by the policy associated with the unauthenticated role of your Cognito Identity Pool.
882
881
883
-
### Optimizations
884
-
If you're writing a browser application based on the examples in this SDK, you might consider creating a smaller version of the AWS SDK for JavaScript using [the AWS SDK for JavaScript Custom Builder](https://sdk.amazonaws.com/builder/js/). This tool allows you to create a version containing only the pieces of the SDK that you need (e.g., Cognito Identity), helping to reduce the size of the SDK bundle. There are also tools available for reducing the size of JavaScript application bundles (e.g. [UglifyJS](https://github.com/mishoo/UglifyJS2)), but the `browserize.sh` script does not yet make use of them; bundle optimizations are left up to the user.
882
+
### Reducing Browser Bundle Size
883
+
After your application development is complete, you will probably want to reduce the size of the browser bundle. There are a couple of easy techniques to do this, and by combining both of them you can create much smaller browser bundles.
884
+
885
+
#### Eliminate unused features from the AWS SDK
886
+
887
+
1. The [AWS SDK for JavaScript](https://github.com/aws/aws-sdk-js) allows you to install only the features you use in your application. In order to use this feature when preparing a browser bundle, first you'll need to remove any existing bundle that you've already created:
888
+
889
+
```sh
890
+
rm browser/aws-iot-sdk-browser-bundle.js
891
+
```
892
+
893
+
2. Define the AWS features your application uses as a comma-separated list in the `AWS_SERVICES` environment variable. For example, the [MQTT Explorer example](#mqtt-explorer-browser-example) uses only AWS Cognito Identity, so to create a bundle containing only this feature, do:
894
+
895
+
```sh
896
+
exportAWS_SERVICES=cognitoidentity
897
+
```
898
+
For a list of the AWS SDK feature names, refer to the [_features subdirectory_ of the AWS SDK for JavaScript](https://github.com/aws/aws-sdk-js/tree/master/features). As another example, if your application uses Cognito Identity, DynamoDB, S3, and SQS, you would do:
[Uglify](https://www.npmjs.com/package/uglify) is an npm utility for minimizing the size of JavaScript source files. To use it, first install it as a global npm package:
913
+
914
+
```sh
915
+
npm install -g uglify
916
+
```
917
+
918
+
Once installed, you can use it to reduce the bundle size:
After you've created the minimized bundle, you'll need to make sure that your application loads this version rather than the non-minimized version, e.g:
By using both of the above techniques for the [MQTT Explorer example](#mqtt-explorer-browser-example), the bundle size can be reduced from 2.4MB to 615KB.
885
930
886
931
<a name="troubleshooting"></a>
887
932
## Troubleshooting
@@ -900,6 +945,7 @@ specify a client ID, the example programs will generate random client IDs,
900
945
but if you are using a [JSON configuration file](#configurationFile), you'll
901
946
need to explictly specify client IDs for both programs using the '-i' command
902
947
line option.
948
+
* _Invalid NPM Version_: To run the browserize.sh script which prepares the browser example applications, you'll need to use npm version 3. This is because browserize.sh expects package dependencies to be handled using the npm version 3 strategy, which is [different than the strategy used in npm version 2](https://docs.npmjs.com/how-npm-works/npm3). If you're having trouble running the browser application examples, make sure that you're using npm version 3. You can check your npm version with `npm -v`.
0 commit comments