├── .github
├── ISSUE_TEMPLATE
│ ├── bug-report.yml
│ ├── config.yml
│ ├── documentation.yml
│ └── feature-request.yml
├── PULL_REQUEST_TEMPLATE.md
└── workflows
│ ├── ci.yml
│ ├── closed-issue-message.yml
│ ├── handle-stale-discussions.yml
│ ├── issue-regression-labeler.yml
│ └── stale_issue.yml
├── .gitignore
├── .jscsrc
├── .jshintrc
├── .npmignore
├── CHANGELOG.md
├── LICENSE.txt
├── NOTICE.txt
├── README.md
├── browser
├── index.js
└── package.json
├── common
└── lib
│ ├── exceptions.js
│ ├── is-undefined.js
│ └── tls-reader.js
├── continuous-delivery
├── publish.yml
├── test-version-exists.sh
├── test-version-exists.yml
└── update-version.sh
├── device
├── index.js
└── lib
│ ├── exceptions.js
│ ├── tls.js
│ └── ws.js
├── examples
├── browser
│ ├── lifecycle
│ │ ├── aws-configuration.js
│ │ ├── example.css
│ │ ├── index.html
│ │ └── index.js
│ ├── mqtt-explorer
│ │ ├── aws-configuration.js
│ │ ├── example.css
│ │ ├── index.html
│ │ └── index.js
│ ├── mqtt-webpack
│ │ ├── aws-configuration.js
│ │ ├── entry.js
│ │ ├── example.css
│ │ ├── index.html
│ │ ├── package.json
│ │ └── webpack.config.js
│ └── temperature-monitor
│ │ ├── aws-configuration.js
│ │ ├── example.css
│ │ ├── index.html
│ │ └── index.js
├── device-example.js
├── echo-example.js
├── jobs-agent.js
├── jobs-example.js
├── lib
│ ├── cmdline.js
│ ├── copy-file.js
│ └── download-file.js
├── temperature-control
│ ├── package.json
│ └── temperature-control.js
├── thing-example.js
└── thing-passthrough-example.js
├── gulpfile.js
├── index.js
├── integration-testing
├── integration-tests
│ ├── device-integration-test.js
│ ├── jobs-integration-test.js
│ ├── offline-publishing-test.js
│ ├── run-device-integration-test.sh
│ ├── run-jobs-integration-test.sh
│ ├── run-offline-publishing-test.sh
│ ├── run-thing-integration-test.sh
│ └── thing-integration-test.js
├── run-integration-tests.sh
└── run-tests.sh
├── jobs
└── index.js
├── package.json
├── scripts
├── browserize.sh
├── exclude_list.txt
└── windows-browserize.bat
├── test
├── data
│ ├── README.txt
│ ├── certificate.pem.crt
│ ├── credentials
│ ├── invalid_credentials
│ ├── private.pem.key
│ └── root-CA.crt
├── device-unit-tests.js
├── jobs-agent-unit-tests.js
├── jobs-unit-tests.js
├── mock
│ ├── mockMQTTClient.js
│ └── mockTls.js
└── thing-unit-tests.js
└── thing
└── index.js
/.github/ISSUE_TEMPLATE/bug-report.yml:
--------------------------------------------------------------------------------
1 | ---
2 | name: "🐛 Bug Report"
3 | description: Report a bug
4 | title: "(short issue description)"
5 | labels: [bug, needs-triage]
6 | assignees: []
7 | body:
8 | - type: textarea
9 | id: description
10 | attributes:
11 | label: Describe the bug
12 | description: What is the problem? A clear and concise description of the bug.
13 | validations:
14 | required: true
15 | - type: checkboxes
16 | id: regression
17 | attributes:
18 | label: Regression Issue
19 | description: What is a regression? If it worked in a previous version but doesn't in the latest version, it's considered a regression. In this case, please provide specific version number in the report.
20 | options:
21 | - label: Select this option if this issue appears to be a regression.
22 | required: false
23 | - type: textarea
24 | id: expected
25 | attributes:
26 | label: Expected Behavior
27 | description: |
28 | What did you expect to happen?
29 | validations:
30 | required: true
31 | - type: textarea
32 | id: current
33 | attributes:
34 | label: Current Behavior
35 | description: |
36 | What actually happened?
37 |
38 | Please include full errors, uncaught exceptions, stack traces, and relevant logs.
39 | If service responses are relevant, please include wire logs.
40 | validations:
41 | required: true
42 | - type: textarea
43 | id: reproduction
44 | attributes:
45 | label: Reproduction Steps
46 | description: |
47 | Provide a self-contained, concise snippet of code that can be used to reproduce the issue.
48 | For more complex issues provide a repo with the smallest sample that reproduces the bug.
49 |
50 | Avoid including business logic or unrelated code, it makes diagnosis more difficult.
51 | The code sample should be an SSCCE. See http://sscce.org/ for details. In short, please provide a code sample that we can copy/paste, run and reproduce.
52 | validations:
53 | required: true
54 | - type: textarea
55 | id: solution
56 | attributes:
57 | label: Possible Solution
58 | description: |
59 | Suggest a fix/reason for the bug
60 | validations:
61 | required: false
62 | - type: textarea
63 | id: context
64 | attributes:
65 | label: Additional Information/Context
66 | description: |
67 | Anything else that might be relevant for troubleshooting this bug. Providing context helps us come up with a solution that is most useful in the real world.
68 | validations:
69 | required: false
70 | - type: input
71 | id: sdk-version
72 | attributes:
73 | label: SDK version used
74 | validations:
75 | required: true
76 | - type: input
77 | id: environment
78 | attributes:
79 | label: Environment details (OS name and version, etc.)
80 | validations:
81 | required: true
82 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/config.yml:
--------------------------------------------------------------------------------
1 | ---
2 | blank_issues_enabled: false
3 | contact_links:
4 | - name: 💬 General Question
5 | url: https://github.com/aws/aws-iot-device-sdk-js/discussions/categories/q-a
6 | about: Please ask and answer questions as a discussion thread
7 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/documentation.yml:
--------------------------------------------------------------------------------
1 | name: "📕 Documentation Issue"
2 | description: Report an issue in the API Reference documentation or Developer Guide
3 | title: "(short issue description)"
4 | labels: [documentation, needs-triage]
5 | assignees: []
6 | body:
7 | - type: textarea
8 | id: description
9 | attributes:
10 | label: Describe the issue
11 | description: A clear and concise description of the issue.
12 | validations:
13 | required: true
14 |
15 | - type: textarea
16 | id: links
17 | attributes:
18 | label: Links
19 | description: |
20 | Include links to affected documentation page(s).
21 | validations:
22 | required: true
23 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/feature-request.yml:
--------------------------------------------------------------------------------
1 | ---
2 | name: 🚀 Feature Request
3 | description: Suggest an idea for this project
4 | title: "(short issue description)"
5 | labels: [feature-request, needs-triage]
6 | assignees: []
7 | body:
8 | - type: textarea
9 | id: description
10 | attributes:
11 | label: Describe the feature
12 | description: A clear and concise description of the feature you are proposing.
13 | validations:
14 | required: true
15 | - type: textarea
16 | id: use-case
17 | attributes:
18 | label: Use Case
19 | description: |
20 | Why do you need this feature? For example: "I'm always frustrated when..."
21 | validations:
22 | required: true
23 | - type: textarea
24 | id: solution
25 | attributes:
26 | label: Proposed Solution
27 | description: |
28 | Suggest how to implement the addition or change. Please include prototype/workaround/sketch/reference implementation.
29 | validations:
30 | required: false
31 | - type: textarea
32 | id: other
33 | attributes:
34 | label: Other Information
35 | description: |
36 | Any alternative solutions or features you considered, a more detailed explanation, stack traces, related issues, links for context, etc.
37 | validations:
38 | required: false
39 | - type: checkboxes
40 | id: ack
41 | attributes:
42 | label: Acknowledgements
43 | options:
44 | - label: I may be able to implement this feature request
45 | required: false
46 | - label: This feature might incur a breaking change
47 | required: false
48 | - type: input
49 | id: sdk-version
50 | attributes:
51 | label: SDK version used
52 | validations:
53 | required: true
54 | - type: input
55 | id: environment
56 | attributes:
57 | label: Environment details (OS name and version, etc.)
58 | validations:
59 | required: true
60 |
--------------------------------------------------------------------------------
/.github/PULL_REQUEST_TEMPLATE.md:
--------------------------------------------------------------------------------
1 | *Issue #, if available:*
2 |
3 | *Description of changes:*
4 |
5 |
6 | By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
7 |
--------------------------------------------------------------------------------
/.github/workflows/ci.yml:
--------------------------------------------------------------------------------
1 | name: CI
2 |
3 | on:
4 | push:
5 | branches:
6 | - '*'
7 | - '!main'
8 |
9 | env:
10 | RUN: ${{ github.run_id }}-${{ github.run_number }}
11 | AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
12 | AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
13 | PACKAGE_NAME: aws-iot-device-sdk-js
14 | AWS_EC2_METADATA_DISABLED: true
15 |
16 | jobs:
17 | unit-tests:
18 | runs-on: ubuntu-latest
19 | strategy:
20 | fail-fast: false
21 | matrix:
22 | node-version: [10.x]
23 |
24 | steps:
25 | - uses: actions/checkout@v2
26 | - name: Unit Tests - Node.js ${{ matrix.node-version }}
27 | uses: actions/setup-node@v2
28 | with:
29 | node-version: ${{ matrix.node-version }}
30 | - run: npm install
31 | - run: npm test
32 |
33 | integration-tests:
34 | runs-on: ubuntu-latest
35 | strategy:
36 | fail-fast: false
37 | matrix:
38 | node-version: [10.x]
39 | test-type: [websocket, certificate, custom-auth]
40 |
41 | steps:
42 | - uses: actions/checkout@v2
43 | - name: ${{ matrix.test-type }} Integration Tests - Node.js ${{ matrix.node-version }}
44 | uses: actions/setup-node@v2
45 | with:
46 | node-version: ${{ matrix.node-version }}
47 | - run: cd integration-testing && ./run-tests.sh ${{ matrix.test-type }}
48 |
--------------------------------------------------------------------------------
/.github/workflows/closed-issue-message.yml:
--------------------------------------------------------------------------------
1 | name: Closed Issue Message
2 | on:
3 | issues:
4 | types: [closed]
5 | jobs:
6 | auto_comment:
7 | runs-on: ubuntu-latest
8 | permissions:
9 | issues: write
10 | steps:
11 | - uses: aws-actions/closed-issue-message@v1
12 | with:
13 | # These inputs are both required
14 | repo-token: "${{ secrets.GITHUB_TOKEN }}"
15 | message: |
16 | This issue is now closed. Comments on closed issues are hard for our team to see.
17 | If you need more assistance, please open a new issue that references this one.
18 |
--------------------------------------------------------------------------------
/.github/workflows/handle-stale-discussions.yml:
--------------------------------------------------------------------------------
1 | name: HandleStaleDiscussions
2 | on:
3 | schedule:
4 | - cron: '0 */4 * * *'
5 | discussion_comment:
6 | types: [created]
7 |
8 | jobs:
9 | handle-stale-discussions:
10 | name: Handle stale discussions
11 | runs-on: ubuntu-latest
12 | permissions:
13 | discussions: write
14 | steps:
15 | - name: Stale discussions action
16 | uses: aws-github-ops/handle-stale-discussions@v1
17 | env:
18 | GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
--------------------------------------------------------------------------------
/.github/workflows/issue-regression-labeler.yml:
--------------------------------------------------------------------------------
1 | # Apply potential regression label on issues
2 | name: issue-regression-label
3 | on:
4 | issues:
5 | types: [opened, edited]
6 | jobs:
7 | add-regression-label:
8 | runs-on: ubuntu-latest
9 | permissions:
10 | issues: write
11 | steps:
12 | - name: Fetch template body
13 | id: check_regression
14 | uses: actions/github-script@v7
15 | env:
16 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
17 | TEMPLATE_BODY: ${{ github.event.issue.body }}
18 | with:
19 | script: |
20 | const regressionPattern = /\[x\] Select this option if this issue appears to be a regression\./i;
21 | const template = `${process.env.TEMPLATE_BODY}`
22 | const match = regressionPattern.test(template);
23 | core.setOutput('is_regression', match);
24 | - name: Manage regression label
25 | env:
26 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
27 | run: |
28 | if [ "${{ steps.check_regression.outputs.is_regression }}" == "true" ]; then
29 | gh issue edit ${{ github.event.issue.number }} --add-label "potential-regression" -R ${{ github.repository }}
30 | else
31 | gh issue edit ${{ github.event.issue.number }} --remove-label "potential-regression" -R ${{ github.repository }}
32 | fi
33 |
--------------------------------------------------------------------------------
/.github/workflows/stale_issue.yml:
--------------------------------------------------------------------------------
1 | name: "Close stale issues"
2 |
3 | # Controls when the action will run.
4 | on:
5 | schedule:
6 | - cron: "*/60 * * * *"
7 |
8 | jobs:
9 | cleanup:
10 | runs-on: ubuntu-latest
11 | name: Stale issue job
12 | steps:
13 | - uses: aws-actions/stale-issue-cleanup@v3
14 | with:
15 | # Setting messages to an empty string will cause the automation to skip
16 | # that category
17 | ancient-issue-message: Greetings! Sorry to say but this is a very old issue that is probably not getting as much attention as it deserves. We encourage you to check if this is still an issue in the latest release and if you find that this is still a problem, please feel free to open a new one.
18 | stale-issue-message: Greetings! It looks like this issue hasn’t been active in a few days. We encourage you to check if this is still an issue in the latest release. Because it has been a few days since the last update on this, and in the absence of more information, we will be closing this issue soon. If you find that this is still a problem, please feel free to provide a comment or add an upvote to prevent automatic closure, or if the issue is already closed, please feel free to open a new one.
19 | stale-pr-message: Greetings! It looks like this PR hasn’t been active in a few days, add a comment or an upvote to prevent automatic closure, or if the issue is already closed, please feel free to open a new one.
20 |
21 | # These labels are required
22 | stale-issue-label: closing-soon
23 | exempt-issue-label: automation-exempt
24 | stale-pr-label: closing-soon
25 | exempt-pr-label: pr/needs-review
26 | response-requested-label: response-requested
27 |
28 | # Don't set closed-for-staleness label to skip closing very old issues
29 | # regardless of label
30 | closed-for-staleness-label: closed-for-staleness
31 |
32 | # Issue timing
33 | days-before-stale: 10
34 | days-before-close: 4
35 | days-before-ancient: 36500
36 |
37 | # If you don't want to mark a issue as being ancient based on a
38 | # threshold of "upvotes", you can set this here. An "upvote" is
39 | # the total number of +1, heart, hooray, and rocket reactions
40 | # on an issue.
41 | minimum-upvotes-to-exempt: 1
42 |
43 | repo-token: ${{ secrets.GITHUB_TOKEN }}
44 | loglevel: DEBUG
45 | # Set dry-run to true to not perform label or close actions.
46 | dry-run: false
47 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # npm subdirectories #
2 | ######################
3 | node_modules
4 |
5 | # OS generated files #
6 | ######################
7 | .DS_Store
8 | .DS_Store?
9 | ._*
10 | .Spotlight-V100
11 | .Trashes
12 |
13 | # editor save files #
14 | ######################
15 | .*.swp
16 |
17 | # unit test/reports #
18 | ######################
19 | .coverdata
20 | .coverrun
21 | reports
22 |
23 | # debugging #
24 | ######################
25 | debug
26 |
27 | # browser bundles #
28 | ######################
29 | *bundle.js
30 |
31 | # misc #
32 | .npmrc
33 | *.tgz
34 | .idea
35 |
--------------------------------------------------------------------------------
/.jscsrc:
--------------------------------------------------------------------------------
1 | {
2 | "disallowAnonymousFunctions": null,
3 | "disallowCapitalizedComments": null,
4 | "disallowCommaBeforeLineBreak": null,
5 | "disallowDanglingUnderscores": null,
6 | "disallowEmptyBlocks": true,
7 | "disallowFunctionDeclarations": null,
8 | "disallowImplicitTypeConversion": null,
9 | "disallowKeywordsOnNewLine": null,
10 | "disallowKeywords": ["with"],
11 | "disallowMixedSpacesAndTabs": null,
12 | "disallowMultipleLineBreaks": true,
13 | "disallowMultipleLineStrings": true,
14 | "disallowMultipleVarDecl": null,
15 | "disallowNewlineBeforeBlockStatements": null,
16 | "disallowOperatorBeforeLineBreak": ["."],
17 | "disallowPaddingNewlinesBeforeKeywords": null,
18 | "disallowPaddingNewlinesInBlocks": null,
19 | "disallowPaddingNewLinesInObjects": null,
20 | "disallowQuotedKeysInObjects": null,
21 | "disallowSemicolons": null,
22 | "disallowSpaceAfterBinaryOperators": null,
23 | "disallowSpaceAfterKeywords": null,
24 | "disallowSpaceAfterLineComment": null,
25 | "disallowSpaceAfterObjectKeys": null,
26 | "disallowSpaceAfterPrefixUnaryOperators": null,
27 | "disallowSpaceBeforeBinaryOperators": null,
28 | "disallowSpaceBeforeBlockStatements": null,
29 | "disallowSpaceBeforeKeywords": null,
30 | "disallowSpaceBeforeObjectValues": null,
31 | "disallowSpaceBeforePostfixUnaryOperators": null,
32 | "disallowSpaceBetweenArguments": null,
33 | "disallowSpacesInAnonymousFunctionExpression": {
34 | "beforeOpeningRoundBrace": true
35 | },
36 | "disallowSpacesInCallExpression": null,
37 | "disallowSpacesInConditionalExpression": null,
38 | "disallowSpacesInForStatement": null,
39 | "disallowSpacesInFunctionDeclaration": null,
40 | "disallowSpacesInFunctionExpression": null,
41 | "disallowSpacesInFunction": null,
42 | "disallowSpacesInNamedFunctionExpression": null,
43 | "disallowSpacesInsideArrayBrackets": null,
44 | "disallowSpacesInsideObjectBrackets": null,
45 | "disallowSpacesInsideObjectBrackets": null,
46 | "disallowSpacesInsideParentheses": null,
47 | "disallowTrailingComma": true,
48 | "disallowTrailingWhitespace": null,
49 | "disallowYodaConditions": true,
50 | "maximumLineLength": {
51 | "value": 140,
52 | "allowRegex": true
53 | },
54 | "requireAlignedObjectValues": null,
55 | "requireAnonymousFunctions": null,
56 | "requireBlocksOnNewline": 1,
57 | "requireCamelCaseOrUpperCaseIdentifiers": true,
58 | "requireCapitalizedComments": null,
59 | "requireCapitalizedConstructors": true,
60 | "requireCommaBeforeLineBreak": true,
61 | "requireCurlyBraces": [
62 | "if",
63 | "else",
64 | "for",
65 | "while",
66 | "do",
67 | "try",
68 | "catch"
69 | ],
70 | "requireDotNotation": "except_snake_case",
71 | "requireFunctionDeclarations": null,
72 | "requireKeywordsOnNewLine": null,
73 | "requireLineBreakAfterVariableAssignment": null,
74 | "requireLineFeedAtFileEnd": true,
75 | "requireMultipleVarDecl": null,
76 | "requireNewlineBeforeBlockStatements": null,
77 | "requireOperatorBeforeLineBreak": true,
78 | "requirePaddingNewlinesBeforeKeywords": null,
79 | "requirePaddingNewlinesInBlocks": null,
80 | "requirePaddingNewLinesInObjects": null,
81 | "requireParenthesesAroundIIFE": true,
82 | "requireQuotedKeysInObjects": null,
83 | "requireSpaceAfterBinaryOperators": null,
84 | "requireSpaceAfterKeywords": [
85 | "if",
86 | "for",
87 | "while",
88 | "do",
89 | "switch",
90 | "return",
91 | "try"
92 | ],
93 | "requireSpaceAfterLineComment": null,
94 | "requireSpaceAfterObjectKeys": null,
95 | "requireSpaceAfterPrefixUnaryOperators": null,
96 | "requireSpaceBeforeBinaryOperators": null,
97 | "requireSpaceBeforeBlockStatements": null,
98 | "requireSpaceBeforeKeywords": [
99 | "else", "while", "catch"
100 | ],
101 | "requireSpaceBeforeObjectValues": null,
102 | "requireSpaceBeforePostfixUnaryOperators": null,
103 | "requireSpaceBetweenArguments": null,
104 | "requireSpacesInAnonymousFunctionExpression": null,
105 | "requireSpacesInCallExpression": null,
106 | "requireSpacesInConditionalExpression": null,
107 | "requireSpacesInForStatement": null,
108 | "requireSpacesInFunctionDeclaration": {
109 | "beforeOpeningCurlyBrace": true
110 | },
111 | "requireSpacesInFunctionExpression": {
112 | "beforeOpeningCurlyBrace": true
113 | },
114 | "requireSpacesInFunction": null,
115 | "requireSpacesInNamedFunctionExpression": null,
116 | "requireSpacesInsideArrayBrackets": null,
117 | "requireSpacesInsideObjectBrackets": null,
118 | "requireSpacesInsideParentheses": null,
119 | "requireTrailingComma": null,
120 | "requireYodaConditions": null,
121 | "safeContextKeyword": null,
122 | "validateJSDoc": {
123 | "checkParamNames": true,
124 | "requireParamTypes": true
125 | },
126 | "validateLineBreaks": "LF",
127 | "validateParameterSeparator": ", ",
128 | "validateQuoteMarks": { "mark": "'", "escape": true }
129 | }
130 |
--------------------------------------------------------------------------------
/.jshintrc:
--------------------------------------------------------------------------------
1 | {
2 | // JSHint Default Configuration File (as on JSHint website)
3 | // See http://jshint.com/docs/ for more details
4 |
5 | "maxerr" : 100, // {int} Maximum error before stopping
6 |
7 | // Enforcing
8 | "bitwise" : true, // true: Prohibit bitwise operators (&, |, ^, etc.)
9 | "camelcase" : false, // true: Identifiers must be in camelCase
10 | "curly" : true, // true: Require {} for every new block or scope
11 | "eqeqeq" : true, // true: Require triple equals (===) for comparison
12 | "forin" : true, // true: Require filtering for..in loops with obj.hasOwnProperty()
13 | "freeze" : false, // true: prohibits overwriting prototypes of native objects such as Array, Date etc.
14 | "immed" : false, // true: Require immediate invocations to be wrapped in parens e.g. `(function () { } ());`
15 | "latedef" : false, // true: Require variables/functions to be defined before being used
16 | "newcap" : false, // true: Require capitalization of all constructor functions e.g. `new F()`
17 | "noarg" : true, // true: Prohibit use of `arguments.caller` and `arguments.callee`
18 | "noempty" : true, // true: Prohibit use of empty blocks
19 | "nonbsp" : true, // true: Prohibit "non-breaking whitespace" characters.
20 | "nonew" : false, // true: Prohibit use of constructors for side-effects (without assignment)
21 | "plusplus" : false, // true: Prohibit use of `++` & `--`
22 | "quotmark" : false, // Quotation mark consistency:
23 | // false : do nothing (default)
24 | // true : ensure whatever is used is consistent
25 | // "single" : require single quotes
26 | // "double" : require double quotes
27 | "undef" : true, // true: Require all non-global variables to be declared (prevents global leaks)
28 | "unused" : "vars", // Unused variables:
29 | // true : all variables, last function parameter
30 | // "vars" : all variables only
31 | // "strict" : all variables, all function parameters
32 | "strict" : false, // true: Requires all functions run in ES5 Strict Mode
33 | "maxparams" : false, // {int} Max number of formal params allowed per function
34 | "maxdepth" : false, // {int} Max depth of nested blocks (within functions)
35 | "maxstatements" : false, // {int} Max number statements per function
36 | "maxcomplexity" : false, // {int} Max cyclomatic complexity per function
37 | "maxlen" : false, // {int} Max number of characters per line
38 |
39 | // Relaxing
40 | "asi" : false, // true: Tolerate Automatic Semicolon Insertion (no semicolons)
41 | "boss" : false, // true: Tolerate assignments where comparisons would be expected
42 | "debug" : false, // true: Allow debugger statements e.g. browser breakpoints.
43 | "eqnull" : false, // true: Tolerate use of `== null`
44 | "es5" : false, // true: Allow ES5 syntax (ex: getters and setters)
45 | "esnext" : true, // true: Allow ES.next (ES6) syntax (ex: `const`)
46 | "moz" : false, // true: Allow Mozilla specific syntax (extends and overrides esnext features)
47 | // (ex: `for each`, multiple try/catch, function expression…)
48 | "evil" : false, // true: Tolerate use of `eval` and `new Function()`
49 | "expr" : false, // true: Tolerate `ExpressionStatement` as Programs
50 | "funcscope" : false, // true: Tolerate defining variables inside control statements
51 | "globalstrict" : false, // true: Allow global "use strict" (also enables 'strict')
52 | "iterator" : false, // true: Tolerate using the `__iterator__` property
53 | "lastsemic" : false, // true: Tolerate omitting a semicolon for the last statement of a 1-line block
54 | "laxbreak" : false, // true: Tolerate possibly unsafe line breakings
55 | "laxcomma" : false, // true: Tolerate comma-first style coding
56 | "loopfunc" : false, // true: Tolerate functions being defined in loops
57 | "multistr" : false, // true: Tolerate multi-line strings
58 | "noyield" : false, // true: Tolerate generator functions with no yield statement in them.
59 | "notypeof" : false, // true: Tolerate invalid typeof operator values
60 | "proto" : false, // true: Tolerate using the `__proto__` property
61 | "scripturl" : false, // true: Tolerate script-targeted URLs
62 | "shadow" : false, // true: Allows re-define variables later in code e.g. `var x=1; x=2;`
63 | "sub" : false, // true: Tolerate using `[]` notation when it can still be expressed in dot notation
64 | "supernew" : false, // true: Tolerate `new function () { ... };` and `new Object;`
65 | "validthis" : false, // true: Tolerate using this in a non-constructor function
66 |
67 | // Environments
68 | "browser" : true, // Web Browser (window, document, etc)
69 | "browserify" : false, // Browserify (node.js code in the browser)
70 | "couch" : false, // CouchDB
71 | "devel" : true, // Development/debugging (alert, confirm, etc)
72 | "dojo" : false, // Dojo Toolkit
73 | "jasmine" : false, // Jasmine
74 | "jquery" : false, // jQuery
75 | "mocha" : true, // Mocha
76 | "mootools" : false, // MooTools
77 | "node" : true, // Node.js
78 | "nonstandard" : false, // Widely adopted globals (escape, unescape, etc)
79 | "phantom" : false, // PhantomJS
80 | "prototypejs" : false, // Prototype and Scriptaculous
81 | "qunit" : false, // QUnit
82 | "rhino" : false, // Rhino
83 | "shelljs" : false, // ShellJS
84 | "typed" : false, // Globals for typed array constructions
85 | "worker" : false, // Web Workers
86 | "wsh" : false, // Windows Scripting Host
87 | "yui" : false, // Yahoo User Interface
88 |
89 | // Custom Globals
90 | "globals" : {} // additional predefined global variables
91 | }
92 |
--------------------------------------------------------------------------------
/.npmignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | debug
3 | .coverdata
4 | .coverrun
5 | .git
6 | .github
7 | continuous-delivery
8 | integration-testing
9 | test
10 | reports
11 | .npmrc
12 | .idea
13 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | ## [2.2.12](https://github.com/aws/aws-iot-device-sdk-js/releases/tag/v2.2.12) (July 30 2021)
2 |
3 | Bugfixes/Improvements
4 | - Updated minimist version
5 |
6 | ## [2.2.11](https://github.com/aws/aws-iot-device-sdk-js/releases/tag/v2.2.11) (July 30 2021)
7 |
8 | Bugfixes/Improvements
9 | - Added examples back into npm package
10 |
11 | ## [2.2.10](https://github.com/aws/aws-iot-device-sdk-js/releases/tag/v2.2.10) (July 9 2021)
12 |
13 | Bugfixes/Improvements
14 | - Merged support for custom auth connections via query parameters
15 | - Bound/propagated the mqtt-js 'end' event
16 | - Unit test reliability and wording updates
17 |
18 | ## [2.2.9](https://github.com/aws/aws-iot-device-sdk-js/releases/tag/v2.2.9) (July 8, 2021)
19 |
20 | Bugfixes/Improvements
21 | - Updated crypto-js version
22 | - Updated mqtt-js version
23 | - Removed reserved topic checks from subscribe calls
24 |
25 | ## [2.2.8](https://github.com/aws/aws-iot-device-sdk-js/releases/tag/v2.2.8) (May 20, 2021)
26 |
27 | Bugfixes/Improvements
28 | - Updated mqtt dependency to latest version
29 |
30 | ## [2.2.7](https://github.com/aws/aws-iot-device-sdk-js/releases/tag/v2.2.7) (Sep 15, 2020)
31 |
32 | Bugfixes/Improvements
33 | - send SNI string while connecting to AWS IoT
34 | - README warns about MacOS storing certificate in keychain
35 |
36 | ## [2.2.6](https://github.com/aws/aws-iot-device-sdk-js/releases/tag/v2.2.6) (May 18, 2020)
37 |
38 | Bugfixes/Improvements
39 | - Require only the necessary modules from crypto-js to optimize bundle
40 |
41 | ## [2.2.5](https://github.com/aws/aws-iot-device-sdk-js/releases/tag/v2.2.5) (Apr 7, 2020)
42 |
43 | Bugfixes/Improvements
44 | - Re-adding github related templates and readme change.
45 |
46 | ## [2.2.4](https://github.com/aws/aws-iot-device-sdk-js/releases/tag/v2.2.4) (Mar 31, 2020)
47 |
48 | Bugfixes/Improvements
49 | - Bumping minimist version to 1.2.5 to address security issue
50 |
51 | ## [2.2.3](https://github.com/aws/aws-iot-device-sdk-js/releases/tag/v2.2.3) (Jan 20, 2020)
52 |
53 | Bugfixes/Improvements
54 | - Upgrade MQTT.js to 3.0.0 to incorporate important bug fixes
55 |
56 | ## [2.2.2](https://github.com/aws/aws-iot-device-sdk-js/releases/tag/v2.2.2) (Sep 24, 2019)
57 |
58 | Bugfixes/Improvements
59 | - Reorder timeout state cleanup in order to support invoking update from a timeout callback
60 |
61 | ## [2.2.1](https://github.com/aws/aws-iot-device-sdk-js/releases/tag/v2.2.1) (Jan 24, 2018)
62 |
63 | Bugfixes/Improvements
64 | - Upgrade MQTT.js to 2.15.1 to address security issue
65 |
66 | ## [2.2.0](https://github.com/aws/aws-iot-device-sdk-js/releases/tag/v2.2.0) (Nov 29, 2017)
67 |
68 | Features
69 | - Added AWS IoT Job API
70 | - Added options to enable AWS IoT Custom Auth
71 | - Added options to enalbe/disable AWS IoT metrics collection
72 | - Added new API to support packetsend and packetreceive events
73 |
74 | Bugfixes/Improvements
75 | - Modify Keepalive defaults to 300 secs to maintain consistency across SDKs
76 | - Expose shadow version from raw json object
77 | - Added samples to demonstrate AWS IoT Job API
78 | - Disabled MQTT.js default resubscribe.
79 |
80 | ## [2.1.0](https://github.com/aws/aws-iot-device-sdk-js/releases/tag/v2.0.1) (Sep 28, 2017)
81 |
82 | Features
83 | - Update MQTT.js to 2.13.0. [MQTT.js](https://github.com/mqttjs/MQTT.js/releases/tag/v2.13.0)
84 |
85 | Bugfixes/Improvements
86 | - Propagated 'error' from 'close' event. [#131](https://github.com/aws/aws-iot-device-sdk-js/pull/131)
87 | - Fixed method of handleMessage to be overridden rather than pass-through. [#129](https://github.com/aws/aws-iot-device-sdk-js/pull/129)
88 | - Pass 'connack' parameter in 'connect' event [#99](https://github.com/aws/aws-iot-device-sdk-js/pull/99)
89 | - Update iot service name to 'iotdevicegateway'
90 |
91 | ## [2.0.1](https://github.com/aws/aws-iot-device-sdk-js/releases/tag/v2.0.1) (Jul 2, 2017)
92 |
93 | Bugfixes/Improvements
94 | - Removed validation against .com in websocket connection.
95 |
96 | ## [2.0.0](https://github.com/aws/aws-iot-device-sdk-js/releases/tag/v2.0.0) (Mar 21, 2017)
97 |
98 | API Changes
99 | - Deprecated region option(-g) in device configuration.
100 | - Added host endpoint option(-H) to connect to custom host endpoint
101 |
102 | Features
103 | - Added support for browserify on Windows CMD. [#74](https://github.com/aws/aws-iot-device-sdk-js/issues/74)
104 | - Added support for loading IAM credentials from aws credential files.
105 | - Added sample for using Node.js SDK with webpack.
106 |
107 | Bugfixes/Improvements
108 | - Fixed README.md typo [#101](https://github.com/aws/aws-iot-device-sdk-js/issues/101)
109 | - Fixed thing.register() API to have independent optional parameters.[#106](https://github.com/aws/aws-iot-device-sdk-js/issues/106)
110 | - Upgrade MQTT.js to v2.2.1 and gulp dependencies.
111 | - Fixed npm test failure in node version above 4.
112 |
113 | ## [1.0.14](https://github.com/aws/aws-iot-device-sdk-js/releases/tag/v1.0.14) (Dec 7, 2016)
114 |
115 | Bugfixes/Improvements
116 | - Fixes for GitHub issues [#67]( https://github.com/aws/aws-iot-device-sdk-js/issues/67), [#95](https://github.com/aws/aws-iot-device-sdk-js/issues/95), [#96](https://github.com/aws/aws-iot-device-sdk-js/issues/96).
117 |
118 | ## [1.0.13](https://github.com/aws/aws-iot-device-sdk-js/releases/tag/v1.0.13) (July 11, 2016)
119 |
120 | Bugfixes/Improvements
121 | - Addressed pull request[#83](https://github.com/aws/aws-iot-device-sdk-js/pull/83) Credits given to [Torsph](https://github.com/Torsph)
122 | - Updated lifecycle events browser demo to read from DynamoDB table of connected clients if available
123 | - Addresses pull request [#60](https://github.com/aws/aws-iot-device-sdk-js/pull/60)
124 | - Fixes for GitHub issues [#66](https://github.com/aws/aws-iot-device-sdk-js/issues/66), [#61](https://github.com/aws/aws-iot-device-sdk-js/issues/61), [#53](https://github.com/aws/aws-iot-device-sdk-js/issues/53), [#48](https://github.com/aws/aws-iot-device-sdk-js/issues/48), and [#44](https://github.com/aws/aws-iot-device-sdk-js/issues/44).
125 |
126 | ## [1.0.12](https://github.com/aws/aws-iot-device-sdk-js/releases/tag/v1.0.12) (April 19, 2016)
127 |
128 | Features
129 | - Added support for use in browser applications
130 |
131 | Bugfixes/Improvements
132 | - Incorporated GitHub pull request [#49](https://github.com/aws/aws-iot-device-sdk-js/pull/49)
133 | - Fixes for GitHub issues [#41](https://github.com/aws/aws-iot-device-sdk-js/issues/41), [#47](https://github.com/aws/aws-iot-device-sdk-js/issues/47), and [#50](https://github.com/aws/aws-iot-device-sdk-js/issues/50).
134 |
135 | ## [1.0.11](https://github.com/aws/aws-iot-device-sdk-js/releases/tag/v1.0.11) (March 4, 2016)
136 |
137 | Features:
138 | - Configurable exponential backoff retries after connection loss
139 | - Configurable offline publish message queueing
140 | - Added option for automatic re-subscription after reconnect
141 | - Added shadow option for versioning disable
142 | - Added session token support
143 |
144 | Bugfixes/Improvements
145 | - Incorporated github pull requests [#33](https://github.com/aws/aws-iot-device-sdk-js/pull/33), [#34](https://github.com/aws/aws-iot-device-sdk-js/pull/34), and [#39](https://github.com/aws/aws-iot-device-sdk-js/pull/39)
146 | - Fixes for github issue [#36](https://github.com/aws/aws-iot-device-sdk-js/issues/36)
147 | - Updated unit tests
148 | - Updated documentation
149 |
150 | ## [1.0.10](https://github.com/aws/aws-iot-device-sdk-js/releases/tag/v1.0.10) (January 28, 2016)
151 |
152 | Features:
153 | - Added support for WebSocket connections to AWS IoT
154 |
155 | Bugfixes/Improvements
156 | - Incorporated github pull requests [#28](https://github.com/aws/aws-iot-device-sdk-js/pull/28) and [#29](https://github.com/aws/aws-iot-device-sdk-js/pull/29)
157 | - Fixes for github issues [#30](https://github.com/aws/aws-iot-device-sdk-js/issues/30)
158 | - Added unit tests to release
159 | - Updated documentation
160 |
161 | ## [1.0.7](https://github.com/aws/aws-iot-device-sdk-js/releases/tag/v1.0.7) (October 30, 2015)
162 |
163 | Bugfixes/Improvements:
164 | - Incorporated github pull requests [#7](https://github.com/aws/aws-iot-device-sdk-js/pull/7), [#9](https://github.com/aws/aws-iot-device-sdk-js/pull/9), and [#14.](https://github.com/aws/aws-iot-device-sdk-js/pull/14)
165 | - Fixes for github issues [#8](https://github.com/aws/aws-iot-device-sdk-js/issues/8) and [#16.](https://github.com/aws/aws-iot-device-sdk-js/issues/16)
166 | - Updated documentation
167 | - JSHint cleanup
168 |
169 | ## [1.0.6](https://github.com/aws/aws-iot-device-sdk-js/releases/tag/v1.0.6) (October 14, 2015)
170 |
171 | Features:
172 | - Added support for AWS Console JSON configuration in example programs
173 | - Added thing-passthrough-example.js example program
174 |
175 | Bugfixes/Improvements:
176 | - Fixes for github issues [#4](https://github.com/aws/aws-iot-device-sdk-js/issues/4), [#5](https://github.com/aws/aws-iot-device-sdk-js/issues/5), and [#6.](https://github.com/aws/aws-iot-device-sdk-js/issues/4)
177 | - Updated documentation
178 |
--------------------------------------------------------------------------------
/NOTICE.txt:
--------------------------------------------------------------------------------
1 | AWS IoT JavaScript SDK for Embedded Devices
2 | Copyright 2012-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 |
--------------------------------------------------------------------------------
/browser/index.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License").
5 | * You may not use this file except in compliance with the License.
6 | * A copy of the License is located at
7 | *
8 | * http://aws.amazon.com/apache2.0
9 | *
10 | * or in the "license" file accompanying this file. This file is distributed
11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12 | * express or implied. See the License for the specific language governing
13 | * permissions and limitations under the License.
14 | */
15 | var AWS = require('aws-sdk');
16 | var AWSIoTData = require('aws-iot-device-sdk');
17 |
18 | module.exports.AWS = AWS;
19 | module.exports.AWSIoTData = AWSIoTData;
20 |
--------------------------------------------------------------------------------
/browser/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "aws-iot-sdk-browser-bundle",
3 | "version": "1.0.0",
4 | "description": "",
5 | "main": "index.js",
6 | "scripts": {
7 | "test": "echo \"bundle exists\" && exit 0"
8 | },
9 | "author": "",
10 | "license": "Apache-2.0",
11 | "dependencies": {
12 | "aws-iot-device-sdk": "^1.0.11",
13 | "aws-sdk": "^2.3.0"
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/common/lib/exceptions.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2010-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License").
5 | * You may not use this file except in compliance with the License.
6 | * A copy of the License is located at
7 | *
8 | * http://aws.amazon.com/apache2.0
9 | *
10 | * or in the "license" file accompanying this file. This file is distributed
11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12 | * express or implied. See the License for the specific language governing
13 | * permissions and limitations under the License.
14 | */
15 |
16 | //node.js deps
17 |
18 | //npm deps
19 |
20 | //app deps
21 |
22 | //begin module
23 | module.exports = {
24 | NO_KEY_OPTION: 'No "keyPath" or "privateKey" option supplied.',
25 | NO_CERT_OPTION: 'No "certPath" or "clientCert" option supplied.',
26 | NO_CA_OPTION: 'No "caPath" or "caCert" option supplied.',
27 | INVALID_KEY_PATH_OPTION: 'Invalid "keyPath" option supplied.',
28 | INVALID_CERT_PATH_OPTION: 'Invalid "certPath" option supplied.',
29 | INVALID_CA_PATH_OPTION: 'Invalid "caPath" option supplied.',
30 | INVALID_CLIENT_CERT_OPTION: 'Invalid "clientCert" option supplied.',
31 | INVALID_PRIVATE_KEY_OPTION: 'Invalid "privateKey" option supplied.',
32 | INVALID_CA_CERT_OPTION: 'Invalid "caCert" option supplied.'
33 | };
34 |
--------------------------------------------------------------------------------
/common/lib/is-undefined.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2010-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License").
5 | * You may not use this file except in compliance with the License.
6 | * A copy of the License is located at
7 | *
8 | * http://aws.amazon.com/apache2.0
9 | *
10 | * or in the "license" file accompanying this file. This file is distributed
11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12 | * express or implied. See the License for the specific language governing
13 | * permissions and limitations under the License.
14 | */
15 |
16 | //node.js deps
17 |
18 | //npm deps
19 |
20 | //app deps
21 |
22 | //begin module
23 | /**
24 | * This is the exposed module.
25 | * This method determines if an object is undefined.
26 | *
27 | * @param {Object} value
28 | * @access public
29 | */
30 | module.exports = function(value) {
31 | return typeof value === 'undefined' || value === null;
32 | };
33 |
--------------------------------------------------------------------------------
/common/lib/tls-reader.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2010-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License").
5 | * You may not use this file except in compliance with the License.
6 | * A copy of the License is located at
7 | *
8 | * http://aws.amazon.com/apache2.0
9 | *
10 | * or in the "license" file accompanying this file. This file is distributed
11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12 | * express or implied. See the License for the specific language governing
13 | * permissions and limitations under the License.
14 | */
15 |
16 | //node.js deps
17 | var filesys = require('fs');
18 |
19 | //npm deps
20 |
21 | //app deps
22 | var isUndefined = require('./is-undefined');
23 | var exceptions = require('./exceptions');
24 |
25 | //begin module
26 | /**
27 | * This method is the exposed module; it validates and prepares the tls
28 | * options as required for connection to the AWS IoT service.
29 | *
30 | * @param {Object} options
31 | * @access public
32 | */
33 | module.exports = function(options) {
34 |
35 | // verify certificate paths
36 | if (isUndefined(options.keyPath) && isUndefined(options.privateKey)) {
37 | throw new Error(exceptions.NO_KEY_OPTION);
38 | }
39 | if (isUndefined(options.certPath) && isUndefined(options.clientCert)) {
40 | throw new Error(exceptions.NO_CERT_OPTION);
41 | }
42 | if (isUndefined(options.caPath) && isUndefined(options.caCert)) {
43 | throw new Error(exceptions.NO_CA_OPTION);
44 | }
45 | //
46 | // Certificates and private keys may be passed in files using options
47 | // ending in 'Path', e.g. 'keyPath', 'certPath', and 'caPath'. In addition,
48 | // they can also be passed in as buffers or files using the options
49 | // 'privateKey', 'clientCert', and 'caCert'. This second set is the one
50 | // that the AWS Console generates a JSON configuration document for.
51 | //
52 | if (!isUndefined(options.caCert)) {
53 | if (Buffer.isBuffer(options.caCert)) {
54 | options.ca = options.caCert;
55 | } else {
56 | if (filesys.existsSync(options.caCert)) {
57 | options.ca = filesys.readFileSync(options.caCert);
58 | } else {
59 | throw new Error(exceptions.INVALID_CA_CERT_OPTION);
60 | }
61 | }
62 | }
63 | if (!isUndefined(options.privateKey)) {
64 | if (Buffer.isBuffer(options.privateKey)) {
65 | options.key = options.privateKey;
66 | } else {
67 | if (filesys.existsSync(options.privateKey)) {
68 | options.key = filesys.readFileSync(options.privateKey);
69 | } else {
70 | throw new Error(exceptions.INVALID_PRIVATE_KEY_OPTION);
71 | }
72 | }
73 | }
74 | if (!isUndefined(options.clientCert)) {
75 | if (Buffer.isBuffer(options.clientCert)) {
76 | options.cert = options.clientCert;
77 | } else {
78 | if (filesys.existsSync(options.clientCert)) {
79 | options.cert = filesys.readFileSync(options.clientCert);
80 | } else {
81 | throw new Error(exceptions.INVALID_CLIENT_CERT_OPTION);
82 | }
83 | }
84 | }
85 |
86 | // Parse PEM files. Options ending in 'Path' must be files
87 | // and will override options which do not end in 'Path'.
88 |
89 | if (filesys.existsSync(options.keyPath)) {
90 | options.key = filesys.readFileSync(options.keyPath);
91 | } else if (!isUndefined(options.keyPath)) {
92 | throw new Error(exceptions.INVALID_KEY_PATH_OPTION);
93 | }
94 | if (filesys.existsSync(options.certPath)) {
95 | options.cert = filesys.readFileSync(options.certPath);
96 | } else if (!isUndefined(options.certPath)) {
97 | throw new Error(exceptions.INVALID_CERT_PATH_OPTION);
98 | }
99 | if (filesys.existsSync(options.caPath)) {
100 | options.ca = filesys.readFileSync(options.caPath);
101 | } else if (!isUndefined(options.caPath)) {
102 | throw new Error(exceptions.INVALID_CA_PATH_OPTION);
103 | }
104 |
105 | // request certificate from partner
106 | options.requestCert = true;
107 |
108 | // require certificate authentication
109 | options.rejectUnauthorized = true;
110 |
111 | };
112 |
--------------------------------------------------------------------------------
/continuous-delivery/publish.yml:
--------------------------------------------------------------------------------
1 | version: 0.2
2 | phases:
3 | install:
4 | runtime-versions:
5 | nodejs: 10
6 | pre_build:
7 | commands:
8 | - cd $CODEBUILD_SRC_DIR/aws-iot-device-sdk-js
9 | - bash ./continuous-delivery/update-version.sh
10 | build:
11 | commands:
12 | - aws secretsmanager get-secret-value --secret-id V1JavascriptNpmAuthToken --region us-east-1 | jq -r .SecretString > .npmrc
13 | - npm install
14 | - npm pack
15 | - npm --userconfig ./.npmrc publish aws-iot-device-sdk-*.tgz
16 |
--------------------------------------------------------------------------------
/continuous-delivery/test-version-exists.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 | set -ex
3 |
4 | # force a failure if there's no tag
5 | git describe --tags
6 | # now get the tag
7 | CURRENT_TAG=$(git describe --tags | cut -f2 -dv)
8 | # convert v0.2.12-2-g50254a9 to 0.2.12
9 | CURRENT_TAG_VERSION=$(git describe --tags | cut -f1 -d'-' | cut -f2 -dv)
10 | # if there's a hash on the tag, then this is not a release tagged commit
11 | if [ "$CURRENT_TAG" != "$CURRENT_TAG_VERSION" ]; then
12 | echo "Current tag version is not a release tag, cut a new release if you want to publish."
13 | exit 1
14 | fi
15 |
16 | PUBLISHED_TAG_VERSION=`npm show aws-iot-device-sdk version`
17 | if [ "$PUBLISHED_TAG_VERSION" == "$CURRENT_TAG_VERSION" ]; then
18 | echo "$CURRENT_TAG_VERSION is already in npm, cut a new tag if you want to upload another version."
19 | exit 1
20 | fi
21 |
22 | echo "$CURRENT_TAG_VERSION currently does not exist in npm, allowing pipeline to continue."
23 | exit 0
24 |
--------------------------------------------------------------------------------
/continuous-delivery/test-version-exists.yml:
--------------------------------------------------------------------------------
1 | version: 0.2
2 | phases:
3 | install:
4 | runtime-versions:
5 | nodejs: 10
6 | build:
7 | commands:
8 | - cd $CODEBUILD_SRC_DIR/aws-iot-device-sdk-js
9 | - bash ./continuous-delivery/test-version-exists.sh
10 |
11 |
--------------------------------------------------------------------------------
/continuous-delivery/update-version.sh:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 | set -ex
3 |
4 | # force a failure if there's no tag
5 | git describe --tags
6 | # now get the tag
7 | CURRENT_TAG=$(git describe --tags | cut -f2 -dv)
8 | # convert v0.2.12-2-g50254a9 to 0.2.12
9 | CURRENT_TAG_VERSION=$(git describe --tags | cut -f1 -d'-' | cut -f2 -dv)
10 | # if there's a hash on the tag, then this is not a release tagged commit
11 | if [ "$CURRENT_TAG" != "$CURRENT_TAG_VERSION" ]; then
12 | echo "Current tag version is not a release tag, cut a new release if you want to publish."
13 | exit 1
14 | fi
15 |
16 | sed --in-place -E "s/\"version\": \".+\"/\"version\": \"${CURRENT_TAG_VERSION}\"/" package.json
17 |
18 | exit 0
19 |
--------------------------------------------------------------------------------
/device/lib/exceptions.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2010-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License").
5 | * You may not use this file except in compliance with the License.
6 | * A copy of the License is located at
7 | *
8 | * http://aws.amazon.com/apache2.0
9 | *
10 | * or in the "license" file accompanying this file. This file is distributed
11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12 | * express or implied. See the License for the specific language governing
13 | * permissions and limitations under the License.
14 | */
15 |
16 | //node.js deps
17 |
18 | //npm deps
19 |
20 | //app deps
21 |
22 | //begin module
23 | module.exports = {
24 | INVALID_CONNECT_OPTIONS: 'Invalid connect options supplied.',
25 | INVALID_CLIENT_ID_OPTION: 'Invalid "clientId" (mqtt client id) option supplied.',
26 | INVALID_RECONNECT_TIMING: 'Invalid reconnect timing options supplied.',
27 | INVALID_OFFLINE_QUEUEING_PARAMETERS: 'Invalid offline queueing options supplied.'
28 | };
29 |
--------------------------------------------------------------------------------
/device/lib/tls.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2010-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License").
5 | * You may not use this file except in compliance with the License.
6 | * A copy of the License is located at
7 | *
8 | * http://aws.amazon.com/apache2.0
9 | *
10 | * or in the "license" file accompanying this file. This file is distributed
11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12 | * express or implied. See the License for the specific language governing
13 | * permissions and limitations under the License.
14 | */
15 |
16 | //node.js deps
17 | var tls = require('tls');
18 |
19 | //npm deps
20 |
21 | //app deps
22 |
23 | function buildBuilder(mqttClient, opts) {
24 | var connection;
25 |
26 | connection = tls.connect(opts);
27 |
28 | function handleTLSerrors(err) {
29 | mqttClient.emit('error', err);
30 | connection.end();
31 | }
32 |
33 | connection.on('secureConnect', function() {
34 | if (!connection.authorized) {
35 | connection.emit('error', new Error('TLS not authorized'));
36 | } else {
37 | connection.removeListener('error', handleTLSerrors);
38 | }
39 | });
40 |
41 | connection.on('error', handleTLSerrors);
42 | return connection;
43 | }
44 |
45 | module.exports = buildBuilder;
46 |
--------------------------------------------------------------------------------
/device/lib/ws.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2010-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License").
5 | * You may not use this file except in compliance with the License.
6 | * A copy of the License is located at
7 | *
8 | * http://aws.amazon.com/apache2.0
9 | *
10 | * or in the "license" file accompanying this file. This file is distributed
11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12 | * express or implied. See the License for the specific language governing
13 | * permissions and limitations under the License.
14 | */
15 |
16 | //node.js deps
17 |
18 | //npm deps
19 | var websocket = require('@httptoolkit/websocket-stream');
20 |
21 | //app deps
22 |
23 | function buildBuilder(client, opts) {
24 | return websocket(opts.url, ['mqttv3.1'], opts.websocketOptions);
25 | }
26 |
27 | module.exports = buildBuilder;
28 |
--------------------------------------------------------------------------------
/examples/browser/lifecycle/aws-configuration.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License").
5 | * You may not use this file except in compliance with the License.
6 | * A copy of the License is located at
7 | *
8 | * http://aws.amazon.com/apache2.0
9 | *
10 | * or in the "license" file accompanying this file. This file is distributed
11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12 | * express or implied. See the License for the specific language governing
13 | * permissions and limitations under the License.
14 | */
15 |
16 | /*
17 | * NOTE: You must set the following string constants prior to running this
18 | * example application.
19 | */
20 | var awsConfiguration = {
21 | poolId: YOUR_COGNITO_IDENTITY_POOL_ID_GOES_HERE, // 'YourCognitoIdentityPoolId'
22 | host: YOUR_AWS_IOT_ENDPOINT_GOES_HERE, // 'YourAWSIoTEndpoint', e.g. 'prefix.iot.us-east-1.amazonaws.com'
23 | region: YOUR_AWS_REGION_GOES_HERE // 'YourAwsRegion', e.g. 'us-east-1'
24 | };
25 | module.exports = awsConfiguration;
26 |
27 |
--------------------------------------------------------------------------------
/examples/browser/lifecycle/example.css:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License").
5 | * You may not use this file except in compliance with the License.
6 | * A copy of the License is located at
7 | *
8 | * http://aws.amazon.com/apache2.0
9 | *
10 | * or in the "license" file accompanying this file. This file is distributed
11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12 | * express or implied. See the License for the specific language governing
13 | * permissions and limitations under the License.
14 | */
15 |
16 | .spacer {
17 | height: 125px ;
18 | }
19 |
20 | .block {
21 | position: relative ;
22 | width:450px ;
23 | margin-left: auto ;
24 | margin-right: auto ;
25 | text-align: center ;
26 | }
27 |
28 | .stack {
29 | background-color:#32CD32 ;
30 | width: 400px ;
31 | margin-left: auto ;
32 | margin-right: auto ;
33 | margin-bottom: 2px ;
34 | padding-top: 2px ;
35 | padding-bottom: 2px ;
36 | text-align: center ;
37 | color: #ffffff ;
38 | display: block ;
39 | clear: both ;
40 | }
41 |
--------------------------------------------------------------------------------
/examples/browser/lifecycle/index.html:
--------------------------------------------------------------------------------
1 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/examples/browser/mqtt-explorer/aws-configuration.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License").
5 | * You may not use this file except in compliance with the License.
6 | * A copy of the License is located at
7 | *
8 | * http://aws.amazon.com/apache2.0
9 | *
10 | * or in the "license" file accompanying this file. This file is distributed
11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12 | * express or implied. See the License for the specific language governing
13 | * permissions and limitations under the License.
14 | */
15 |
16 | /*
17 | * NOTE: You must set the following string constants prior to running this
18 | * example application.
19 | */
20 | var awsConfiguration = {
21 | poolId: YOUR_COGNITO_IDENTITY_POOL_ID_GOES_HERE, // 'YourCognitoIdentityPoolId'
22 | host: YOUR_AWS_IOT_ENDPOINT_GOES_HERE, // 'YourAwsIoTEndpoint', e.g. 'prefix.iot.us-east-1.amazonaws.com'
23 | region: YOUR_AWS_REGION_GOES_HERE // 'YourAwsRegion', e.g. 'us-east-1'
24 | };
25 | module.exports = awsConfiguration;
26 |
27 |
--------------------------------------------------------------------------------
/examples/browser/mqtt-explorer/example.css:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License").
5 | * You may not use this file except in compliance with the License.
6 | * A copy of the License is located at
7 | *
8 | * http://aws.amazon.com/apache2.0
9 | *
10 | * or in the "license" file accompanying this file. This file is distributed
11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12 | * express or implied. See the License for the specific language governing
13 | * permissions and limitations under the License.
14 | */
15 |
16 | .spacer {
17 | height: 125px ;
18 | }
19 |
20 | .block {
21 | position: relative ;
22 | width:900px ;
23 | margin-left: auto ;
24 | margin-right: auto ;
25 | text-align: center ;
26 | }
27 |
28 | .subscribe {
29 | background-color:#303030 ;
30 | width: 850px ;
31 | text-align: left ;
32 | margin-left: auto ;
33 | margin-right: auto ;
34 | margin-bottom: 2px ;
35 | padding-top: 2px ;
36 | padding-bottom: 2px ;
37 | display: block ;
38 | color: #ffffff ;
39 | }
40 |
41 | .settings {
42 | background-color:#32CD32 ;
43 | width: 500px ;
44 | text-align: left ;
45 | margin-left: auto ;
46 | margin-right: auto ;
47 | margin-bottom: 2px ;
48 | padding-top: 2px ;
49 | padding-bottom: 2px ;
50 | display: block ;
51 | color: #ffffff ;
52 | }
53 |
54 | p {
55 | margin-left: 10px ;
56 | margin-right: 10px ;
57 | }
58 |
--------------------------------------------------------------------------------
/examples/browser/mqtt-explorer/index.html:
--------------------------------------------------------------------------------
1 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
publish to topic:
28 |
29 |
30 |
string:
31 |
32 |
33 |
subscribe to topic:
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
--------------------------------------------------------------------------------
/examples/browser/mqtt-explorer/index.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License").
5 | * You may not use this file except in compliance with the License.
6 | * A copy of the License is located at
7 | *
8 | * http://aws.amazon.com/apache2.0
9 | *
10 | * or in the "license" file accompanying this file. This file is distributed
11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12 | * express or implied. See the License for the specific language governing
13 | * permissions and limitations under the License.
14 | */
15 |
16 | //
17 | // Instantiate the AWS SDK and configuration objects. The AWS SDK for
18 | // JavaScript (aws-sdk) is used for Cognito Identity/Authentication, and
19 | // the AWS IoT SDK for JavaScript (aws-iot-device-sdk) is used for the
20 | // WebSocket connection to AWS IoT and device shadow APIs.
21 | //
22 | var AWS = require('aws-sdk');
23 | var AWSIoTData = require('aws-iot-device-sdk');
24 | var AWSConfiguration = require('./aws-configuration.js');
25 |
26 | console.log('Loaded AWS SDK for JavaScript and AWS IoT SDK for Node.js');
27 |
28 | //
29 | // Remember our current subscription topic here.
30 | //
31 | var currentlySubscribedTopic = 'subscribe-topic';
32 |
33 | //
34 | // Remember our message history here.
35 | //
36 | var messageHistory = '';
37 |
38 | //
39 | // Create a client id to use when connecting to AWS IoT.
40 | //
41 | var clientId = 'mqtt-explorer-' + (Math.floor((Math.random() * 100000) + 1));
42 |
43 | //
44 | // Initialize our configuration.
45 | //
46 | AWS.config.region = AWSConfiguration.region;
47 |
48 | AWS.config.credentials = new AWS.CognitoIdentityCredentials({
49 | IdentityPoolId: AWSConfiguration.poolId
50 | });
51 |
52 | //
53 | // Create the AWS IoT device object. Note that the credentials must be
54 | // initialized with empty strings; when we successfully authenticate to
55 | // the Cognito Identity Pool, the credentials will be dynamically updated.
56 | //
57 | const mqttClient = AWSIoTData.device({
58 | //
59 | // Set the AWS region we will operate in.
60 | //
61 | region: AWS.config.region,
62 | //
63 | ////Set the AWS IoT Host Endpoint
64 | host:AWSConfiguration.host,
65 | //
66 | // Use the clientId created earlier.
67 | //
68 | clientId: clientId,
69 | //
70 | // Connect via secure WebSocket
71 | //
72 | protocol: 'wss',
73 | //
74 | // Set the maximum reconnect time to 8 seconds; this is a browser application
75 | // so we don't want to leave the user waiting too long for reconnection after
76 | // re-connecting to the network/re-opening their laptop/etc...
77 | //
78 | maximumReconnectTimeMs: 8000,
79 | //
80 | // Enable console debugging information (optional)
81 | //
82 | debug: true,
83 | //
84 | // IMPORTANT: the AWS access key ID, secret key, and sesion token must be
85 | // initialized with empty strings.
86 | //
87 | accessKeyId: '',
88 | secretKey: '',
89 | sessionToken: ''
90 | });
91 |
92 | //
93 | // Attempt to authenticate to the Cognito Identity Pool. Note that this
94 | // example only supports use of a pool which allows unauthenticated
95 | // identities.
96 | //
97 | var cognitoIdentity = new AWS.CognitoIdentity();
98 | AWS.config.credentials.get(function(err, data) {
99 | if (!err) {
100 | console.log('retrieved identity: ' + AWS.config.credentials.identityId);
101 | var params = {
102 | IdentityId: AWS.config.credentials.identityId
103 | };
104 | cognitoIdentity.getCredentialsForIdentity(params, function(err, data) {
105 | if (!err) {
106 | //
107 | // Update our latest AWS credentials; the MQTT client will use these
108 | // during its next reconnect attempt.
109 | //
110 | mqttClient.updateWebSocketCredentials(data.Credentials.AccessKeyId,
111 | data.Credentials.SecretKey,
112 | data.Credentials.SessionToken);
113 | } else {
114 | console.log('error retrieving credentials: ' + err);
115 | alert('error retrieving credentials: ' + err);
116 | }
117 | });
118 | } else {
119 | console.log('error retrieving identity:' + err);
120 | alert('error retrieving identity: ' + err);
121 | }
122 | });
123 |
124 | //
125 | // Connect handler; update div visibility and fetch latest shadow documents.
126 | // Subscribe to lifecycle events on the first connect event.
127 | //
128 | window.mqttClientConnectHandler = function() {
129 | console.log('connect');
130 | document.getElementById("connecting-div").style.visibility = 'hidden';
131 | document.getElementById("explorer-div").style.visibility = 'visible';
132 | document.getElementById('subscribe-div').innerHTML = '
';
194 |
--------------------------------------------------------------------------------
/examples/browser/mqtt-webpack/example.css:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License").
5 | * You may not use this file except in compliance with the License.
6 | * A copy of the License is located at
7 | *
8 | * http://aws.amazon.com/apache2.0
9 | *
10 | * or in the "license" file accompanying this file. This file is distributed
11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12 | * express or implied. See the License for the specific language governing
13 | * permissions and limitations under the License.
14 | */
15 |
16 | .spacer {
17 | height: 125px ;
18 | }
19 |
20 | .block {
21 | position: relative ;
22 | width:900px ;
23 | margin-left: auto ;
24 | margin-right: auto ;
25 | text-align: center ;
26 | }
27 |
28 | .subscribe {
29 | background-color:#303030 ;
30 | width: 850px ;
31 | text-align: left ;
32 | margin-left: auto ;
33 | margin-right: auto ;
34 | margin-bottom: 2px ;
35 | padding-top: 2px ;
36 | padding-bottom: 2px ;
37 | display: block ;
38 | color: #ffffff ;
39 | }
40 |
41 | .settings {
42 | background-color:#32CD32 ;
43 | width: 500px ;
44 | text-align: left ;
45 | margin-left: auto ;
46 | margin-right: auto ;
47 | margin-bottom: 2px ;
48 | padding-top: 2px ;
49 | padding-bottom: 2px ;
50 | display: block ;
51 | color: #ffffff ;
52 | }
53 |
54 | p {
55 | margin-left: 10px ;
56 | margin-right: 10px ;
57 | }
58 |
--------------------------------------------------------------------------------
/examples/browser/mqtt-webpack/index.html:
--------------------------------------------------------------------------------
1 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
publish to topic:
28 |
29 |
30 |
string:
31 |
32 |
33 |
subscribe to topic:
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/examples/browser/mqtt-webpack/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "mqtt-webpack",
3 | "version": "1.0.0",
4 | "description": "Amazon AWS IoT Javascript Device SDK with WebPack",
5 | "scripts": {
6 | "test": "echo \"Error: no test specified\" && exit 1"
7 | },
8 | "author": {
9 | "name":"Amazon Web Services",
10 | "email":"",
11 | "url":"http://aws.amazon.com"
12 | },
13 | "dependencies": {
14 | "aws-iot-device-sdk": "^2.0.0",
15 | "aws-sdk": "^2.10.0",
16 | "webpack":"^2.2.1"
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/examples/browser/mqtt-webpack/webpack.config.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | entry: "./entry.js",
3 | output: {
4 | path: __dirname,
5 | filename: "bundle.js"
6 | },
7 | node: {
8 | fs: 'empty',
9 | tls: 'empty'
10 | }
11 | };
12 |
--------------------------------------------------------------------------------
/examples/browser/temperature-monitor/aws-configuration.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License").
5 | * You may not use this file except in compliance with the License.
6 | * A copy of the License is located at
7 | *
8 | * http://aws.amazon.com/apache2.0
9 | *
10 | * or in the "license" file accompanying this file. This file is distributed
11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12 | * express or implied. See the License for the specific language governing
13 | * permissions and limitations under the License.
14 | */
15 |
16 | /*
17 | * NOTE: You must set the following string constants prior to running this
18 | * example application.
19 | */
20 | var awsConfiguration = {
21 | poolId: YOUR_COGNITO_IDENTITY_POOL_ID_GOES_HERE, // 'YourCognitoIdentityPoolId'
22 | host: YOUR_AWS_IOT_ENDPOINT_GOES_HERE, // 'YourAWSIoTEndpoint', e.g. 'prefix.iot.us-east-1.amazonaws.com'
23 | region: YOUR_AWS_REGION_GOES_HERE // 'YourAwsRegion', e.g. 'us-east-1'
24 | };
25 | module.exports = awsConfiguration;
26 |
27 |
--------------------------------------------------------------------------------
/examples/browser/temperature-monitor/example.css:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License").
5 | * You may not use this file except in compliance with the License.
6 | * A copy of the License is located at
7 | *
8 | * http://aws.amazon.com/apache2.0
9 | *
10 | * or in the "license" file accompanying this file. This file is distributed
11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12 | * express or implied. See the License for the specific language governing
13 | * permissions and limitations under the License.
14 | */
15 |
16 | .spacer {
17 | height: 125px ;
18 | }
19 |
20 | .block {
21 | width:250px ;
22 | margin-left: auto ;
23 | margin-right: auto ;
24 | }
25 |
--------------------------------------------------------------------------------
/examples/browser/temperature-monitor/index.html:
--------------------------------------------------------------------------------
1 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/examples/browser/temperature-monitor/index.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2015-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License").
5 | * You may not use this file except in compliance with the License.
6 | * A copy of the License is located at
7 | *
8 | * http://aws.amazon.com/apache2.0
9 | *
10 | * or in the "license" file accompanying this file. This file is distributed
11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12 | * express or implied. See the License for the specific language governing
13 | * permissions and limitations under the License.
14 | */
15 |
16 | //
17 | // Instantiate the AWS SDK and configuration objects. The AWS SDK for
18 | // JavaScript (aws-sdk) is used for Cognito Identity/Authentication, and
19 | // the AWS IoT SDK for JavaScript (aws-iot-device-sdk) is used for the
20 | // WebSocket connection to AWS IoT and device shadow APIs.
21 | //
22 | var AWS = require('aws-sdk');
23 | var AWSIoTData = require('aws-iot-device-sdk');
24 | var AWSConfiguration = require('./aws-configuration.js');
25 |
26 | console.log('Loaded AWS SDK for JavaScript and AWS IoT SDK for Node.js');
27 |
28 | //
29 | // Initialize our configuration.
30 | //
31 | AWS.config.region = AWSConfiguration.region;
32 |
33 | AWS.config.credentials = new AWS.CognitoIdentityCredentials({
34 | IdentityPoolId: AWSConfiguration.poolId
35 | });
36 |
37 | //
38 | // Keep track of whether or not we've registered the shadows used by this
39 | // example.
40 | //
41 | var shadowsRegistered = false;
42 |
43 | //
44 | // Create the AWS IoT shadows object. Note that the credentials must be
45 | // initialized with empty strings; when we successfully authenticate to
46 | // the Cognito Identity Pool, the credentials will be dynamically updated.
47 | //
48 | const shadows = AWSIoTData.thingShadow({
49 | //
50 | // Set the AWS region we will operate in.
51 | //
52 | region: AWS.config.region,
53 | //
54 | //Set the AWS IoT Host Endpoint
55 | //
56 | host:AWSConfiguration.host,
57 | //
58 | // Use a random client ID.
59 | //
60 | clientId: 'temperature-control-browser-' + (Math.floor((Math.random() * 100000) + 1)),
61 | //
62 | // Connect via secure WebSocket
63 | //
64 | protocol: 'wss',
65 | //
66 | // Set the maximum reconnect time to 8 seconds; this is a browser application
67 | // so we don't want to leave the user waiting too long for reconnection after
68 | // re-connecting to the network/re-opening their laptop/etc...
69 | //
70 | maximumReconnectTimeMs: 8000,
71 | //
72 | // Enable console debugging information (optional)
73 | //
74 | debug: true,
75 | //
76 | // IMPORTANT: the AWS access key ID, secret key, and sesion token must be
77 | // initialized with empty strings.
78 | //
79 | accessKeyId: '',
80 | secretKey: '',
81 | sessionToken: ''
82 | });
83 |
84 | //
85 | // Update divs whenever we receive delta events from the shadows.
86 | //
87 | shadows.on('delta', function(name, stateObject) {
88 | if (name === 'TemperatureStatus') {
89 | document.getElementById('temperature-monitor-div').innerHTML = '
';
96 | }
97 | });
98 |
99 | //
100 | // Update divs whenever we receive status events from the shadows.
101 | //
102 | shadows.on('status', function(name, statusType, clientToken, stateObject) {
103 | if (statusType === 'rejected') {
104 | //
105 | // If an operation is rejected it is likely due to a version conflict;
106 | // request the latest version so that we synchronize with the shadow
107 | // The most notable exception to this is if the thing shadow has not
108 | // yet been created or has been deleted.
109 | //
110 | if (stateObject.code !== 404) {
111 | console.log('resync with thing shadow');
112 | var opClientToken = shadows.get(name);
113 | if (opClientToken === null) {
114 | console.log('operation in progress');
115 | }
116 | }
117 | } else { // statusType === 'accepted'
118 | if (name === 'TemperatureStatus') {
119 | document.getElementById('temperature-monitor-div').innerHTML = '