├── .gitmodules ├── .gitignore ├── examples └── mqtt-shadows-cognitopool │ ├── .watchmanconfig │ ├── .gitignore │ ├── app.json │ ├── .babelrc │ ├── App.test.js │ ├── package.json │ ├── .flowconfig │ ├── App.js │ └── README.md ├── entry.js ├── .eslintrc.json ├── webpack.config.js ├── package.json ├── index.js ├── README.md └── aws-iot-device-sdk-js-react-native.js /.gitmodules: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules -------------------------------------------------------------------------------- /examples/mqtt-shadows-cognitopool/.watchmanconfig: -------------------------------------------------------------------------------- 1 | {} 2 | -------------------------------------------------------------------------------- /examples/mqtt-shadows-cognitopool/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | .expo/ 3 | npm-debug.* 4 | -------------------------------------------------------------------------------- /examples/mqtt-shadows-cognitopool/app.json: -------------------------------------------------------------------------------- 1 | { 2 | "expo": { 3 | "sdkVersion": "20.0.0" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /entry.js: -------------------------------------------------------------------------------- 1 | const AWSIoTData = require('aws-iot-device-sdk'); 2 | 3 | module.exports = { 4 | AWSIoTData: AWSIoTData 5 | }; 6 | 7 | -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "google", 3 | "parser": "babel-eslint", 4 | "rules": { 5 | "max-len": [1,180] 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /examples/mqtt-shadows-cognitopool/.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": ["babel-preset-expo"], 3 | "env": { 4 | "development": { 5 | "plugins": ["transform-react-jsx-source"] 6 | } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /examples/mqtt-shadows-cognitopool/App.test.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import App from './App'; 3 | 4 | import renderer from 'react-test-renderer'; 5 | 6 | it('renders without crashing', () => { 7 | const rendered = renderer.create().toJSON(); 8 | expect(rendered).toBeTruthy(); 9 | }); 10 | -------------------------------------------------------------------------------- /webpack.config.js: -------------------------------------------------------------------------------- 1 | var Webpack = require('webpack'); 2 | 3 | module.exports = { 4 | entry: "./entry.js", 5 | output: { 6 | path: __dirname, 7 | filename: "aws-iot-device-sdk-js-react-native.js", 8 | libraryTarget: 'umd', 9 | library: 'pro1' 10 | }, 11 | node: { 12 | fs: 'empty', 13 | tls: 'empty' 14 | }, 15 | plugins: [ 16 | new Webpack.optimize.UglifyJsPlugin({ 17 | compress: { 18 | drop_console: true 19 | } 20 | }) 21 | ] 22 | }; 23 | -------------------------------------------------------------------------------- /examples/mqtt-shadows-cognitopool/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "mqtt-shadows-cognitopool", 3 | "version": "0.1.0", 4 | "private": true, 5 | "devDependencies": { 6 | "react-native-scripts": "1.3.1", 7 | "jest-expo": "~20.0.0", 8 | "react-test-renderer": "16.0.0-alpha.12" 9 | }, 10 | "main": "./node_modules/react-native-scripts/build/bin/crna-entry.js", 11 | "scripts": { 12 | "start": "react-native-scripts start", 13 | "eject": "react-native-scripts eject", 14 | "android": "react-native-scripts android", 15 | "ios": "react-native-scripts ios", 16 | "test": "node node_modules/jest/bin/jest.js --watch" 17 | }, 18 | "jest": { 19 | "preset": "jest-expo" 20 | }, 21 | "dependencies": { 22 | "expo": "^20.0.0", 23 | "react": "16.0.0-alpha.12", 24 | "react-native": "^0.47.0", 25 | "react-native-aws-cognito-js": "0.0.7" 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-native-aws-iot-device-shadows", 3 | "version": "1.0.3", 4 | "description": "React Native Component for connecting to AWS IoT from a device using SDK JavaScript bundle", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1", 8 | "build": "webpack --config webpack.config.js" 9 | }, 10 | "repository": { 11 | "type": "git", 12 | "url": "git+https://github.com/jamesjara/react-native-aws-iot-device-shadows.git" 13 | }, 14 | "author": "jamesjara", 15 | "license": "Apache", 16 | "bugs": { 17 | "url": "https://github.com/jamesjara/react-native-aws-iot-device-shadows/issues" 18 | }, 19 | "homepage": "https://github.com/jamesjara/react-native-aws-iot-device-shadows#readme", 20 | "dependencies": { 21 | "aws-iot-device-sdk": "*", 22 | "aws-sdk": "*", 23 | "uglify-js": "^3.0.28", 24 | "webpack": "^2.7.0" 25 | }, 26 | "devDependencies": { 27 | "babel-eslint": "^8.2.1", 28 | "eslint": "^4.18.0", 29 | "eslint-config-google": "^0.9.1" 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /examples/mqtt-shadows-cognitopool/.flowconfig: -------------------------------------------------------------------------------- 1 | [ignore] 2 | ; We fork some components by platform 3 | .*/*[.]android.js 4 | 5 | ; Ignore "BUCK" generated dirs 6 | /\.buckd/ 7 | 8 | ; Ignore unexpected extra "@providesModule" 9 | .*/node_modules/.*/node_modules/fbjs/.* 10 | 11 | ; Ignore duplicate module providers 12 | ; For RN Apps installed via npm, "Libraries" folder is inside 13 | ; "node_modules/react-native" but in the source repo it is in the root 14 | .*/Libraries/react-native/React.js 15 | .*/Libraries/react-native/ReactNative.js 16 | 17 | ; Additional create-react-native-app ignores 18 | 19 | ; Ignore duplicate module providers 20 | .*/node_modules/fbemitter/lib/* 21 | 22 | ; Ignore misbehaving dev-dependencies 23 | .*/node_modules/xdl/build/* 24 | .*/node_modules/reqwest/tests/* 25 | 26 | ; Ignore missing expo-sdk dependencies (temporarily) 27 | ; https://github.com/expo/expo/issues/162 28 | .*/node_modules/expo/src/* 29 | 30 | ; Ignore react-native-fbads dependency of the expo sdk 31 | .*/node_modules/react-native-fbads/* 32 | 33 | [include] 34 | 35 | [libs] 36 | node_modules/react-native/Libraries/react-native/react-native-interface.js 37 | node_modules/react-native/flow 38 | flow/ 39 | 40 | [options] 41 | module.system=haste 42 | 43 | emoji=true 44 | 45 | experimental.strict_type_args=true 46 | 47 | munge_underscores=true 48 | 49 | module.name_mapper='^[./a-zA-Z0-9$_-]+\.\(bmp\|gif\|jpg\|jpeg\|png\|psd\|svg\|webp\|m4v\|mov\|mp4\|mpeg\|mpg\|webm\|aac\|aiff\|caf\|m4a\|mp3\|wav\|html\|pdf\)$' -> 'RelativeImageStub' 50 | 51 | suppress_type=$FlowIssue 52 | suppress_type=$FlowFixMe 53 | suppress_type=$FixMe 54 | 55 | suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(>=0\\.\\(4[0-9]\\|[1-3][0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\) 56 | suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(>=0\\.\\(4[0-9]\\|[1-3][0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)?:? #[0-9]+ 57 | suppress_comment=\\(.\\|\n\\)*\\$FlowFixedInNextDeploy 58 | suppress_comment=\\(.\\|\n\\)*\\$FlowExpectedError 59 | 60 | unsafe.enable_getters_and_setters=true 61 | 62 | [version] 63 | ^0.49.1 64 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | // import AWS from 'aws-sdk/dist/aws-sdk-react-native'; 2 | import {AWSIoTData} from './aws-iot-device-sdk-js-react-native.js'; 3 | 4 | /** 5 | * Use this class with redux 6 | * 7 | * @param {Object} configuration 8 | * @return {{ AWSIoTMQTTClient }} 9 | * @constructor 10 | */ 11 | export function AWSIoTMQTTClient(configuration) { 12 | const self = { }; 13 | self.service = null; 14 | self.store = null; 15 | configuration.type = configuration.type === 'shadow' ? 'thingShadow' : 'device'; 16 | 17 | const config = { 18 | // 19 | // Set the AWS region we will operate in. 20 | // 21 | region: configuration.region, 22 | host: configuration.host, 23 | // 24 | // Connect via secure WebSocket 25 | // 26 | protocol: 'wss', 27 | // 28 | // Set the maximum reconnect time to 8 seconds; this is a browser application 29 | // so we don't want to leave the user waiting too long for reconnection after 30 | // re-connecting to the network/re-opening their laptop/etc... 31 | // 32 | maximumReconnectTimeMs: 1000, 33 | // 34 | // Enable console debugging information (optional) 35 | // 36 | debug: true, 37 | // 38 | // IMPORTANT: the AWS access key ID, secret key, and sesion token must be 39 | // initialized with empty strings. 40 | // 41 | accessKeyId: '', 42 | secretKey: '', 43 | sessionToken: '', 44 | }; 45 | 46 | if (configuration) { 47 | Object.assign(config, configuration); 48 | } 49 | 50 | self.connect = function(accessKeyId, secretAccessKey, sessionToken) { 51 | config.accessKeyId = accessKeyId; 52 | config.secretKey = secretAccessKey; 53 | config.sessionToken = sessionToken; 54 | self.service = AWSIoTData[config.type](config); 55 | self.config = config; 56 | self.service.on('connect', self.onConnect); 57 | self.service.on('reconnect', self.onReconnect); 58 | self.service.on('offline', self.onOffline); 59 | self.service.on('error', self.onError); 60 | self.service.on('message', self.onMessage); 61 | self.service.on('status', self.onStatus); 62 | self.service.on('delta', self.onDelta); 63 | self.service.on('close', self.onClose); 64 | self.service.on('timeout', self.onTimeout); 65 | }; 66 | 67 | self.setStore = function(store) { 68 | self.store = store; 69 | }; 70 | 71 | self.onConnect = function() { 72 | self.store.dispatch({type: 'MQTT_ON_CONNECT'}); 73 | }; 74 | 75 | self.onReconnect = function() { 76 | self.store.dispatch({type: 'MQTT_ON_RECONNECT'}); 77 | }; 78 | 79 | self.onOffline = function() { 80 | self.store.dispatch({type: 'MQTT_ON_OFFLINE'}); 81 | }; 82 | 83 | self.onError = function(error) { 84 | self.store.dispatch({type: 'MQTT_ON_ERROR', error}); 85 | }; 86 | 87 | self.onMessage = function(topic, payload) { 88 | self.store.dispatch({type: 'MQTT_ON_MESSAGE', topic, payload}); 89 | }; 90 | 91 | self.onStatus = function(thingId, statusType, clientToken, stateObject) { 92 | self.store.dispatch({type: 'MQTT_ON_STATUS', thingId, statusType, clientToken, stateObject}); 93 | }; 94 | 95 | self.onDelta = function(thingName, stateObject) { 96 | self.store.dispatch({type: 'MQTT_ON_DELTA', thingName, stateObject}); 97 | }; 98 | 99 | self.onClose = function() { 100 | self.store.dispatch({type: 'MQTT_ON_CLOSE'}); 101 | }; 102 | 103 | self.onTimeout = function(thingName, clientToken) { 104 | self.store.dispatch({type: 'MQTT_ON_TIMEOUT', thingName, clientToken}); 105 | }; 106 | 107 | return self; 108 | } 109 | 110 | export default AWSIoTMQTTClient; 111 | -------------------------------------------------------------------------------- /examples/mqtt-shadows-cognitopool/App.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { StyleSheet, Text, View } from 'react-native'; 3 | import AWS from 'aws-sdk/dist/aws-sdk-react-native'; 4 | import AWSIoTMQTT from '../../../react-native-aws-iot-device-shadows/index.js'; 5 | 6 | export default class App extends React.Component { 7 | 8 | constructor(props) { 9 | super(props); 10 | this.state = { 11 | device: { 12 | deviceId: "smartDevice1", 13 | temp: 80 14 | } 15 | }; 16 | this.AWSIoTMQTT = null; 17 | } 18 | 19 | componentDidMount() { 20 | // trigger STS credentials from Cognito Pool 21 | this.AWSIoTMQTT.shadow.updateWebSocketCredentials( 22 | accessKeyId, 23 | secretAccessKey, 24 | sessionToken 25 | ); 26 | } 27 | 28 | 29 | 30 | onConnect() { 31 | this.AWSIoTMQTT.addThing(this.device.deviceId); 32 | } 33 | 34 | onDelta(thingId, stateObject) { 35 | if (stateObject.state.device && stateObject.state.device.temp) { 36 | this.updateState(thingId, { 37 | temp: stateObject.state.temp 38 | }); 39 | } 40 | } 41 | 42 | onStatus(thingId, statusType, clientToken, stateObject) { 43 | if (statusType === 'rejected') { 44 | // 45 | // If an operation is rejected it is likely due to a version conflict; 46 | // request the latest version so that we synchronize with the shadow 47 | // The most notable exception to this is if the thing shadow has not 48 | // yet been created or has been deleted. 49 | // if gets still in progress client token of the will be null 50 | // 51 | if (stateObject.code !== 404) { 52 | this.AWSIoTMQTT.shadow.get(thingId); 53 | } 54 | } else if (statusType === 'accepted') { 55 | if (stateObject.state && stateObject.state.desired && stateObject.state.desired.temp) { 56 | this.updateState(thingId, { 57 | temp: stateObject.state.desired.temp 58 | }); 59 | } 60 | } 61 | } 62 | 63 | onThingConnected(thingId) { 64 | this.AWSIoTMQTT.shadow.get(thingId); 65 | } 66 | 67 | updateState(thingId, sensors) { 68 | Object.assign(this.device, sensors); 69 | 70 | this.setState({ 71 | device 72 | }); 73 | } 74 | 75 | updateShadow(key) { 76 | const current = this.data.device; 77 | 78 | const update = { 79 | [key]: ((Math.floor(Math.random() * (99 - 1)) + 1)) 80 | }; 81 | 82 | this.AWSIoTMQTT.shadow.update(current.deviceId, { 83 | state: { 84 | desired: update 85 | } 86 | }); 87 | } 88 | 89 | render() { 90 | return ( 91 | 92 | { this.AWSIoTMQTT = ref; }} 94 | region="us-west-2" 95 | host="asdasd.iot.aws.com" 96 | type="shadows" 97 | onConnect={() => this.onConnect()} 98 | onDelta={(thingId, stateObject) => this.onDelta(thingId, stateObject)} 99 | onStatus={(thingId, statusType, clientToken, stateObject) => 100 | this.onStatus(thingId, statusType, clientToken, stateObject)} 101 | onThingConnected={(thingId) => { this.onThingConnected(thingId); }} 102 | /> 103 | {this.state.device.temp} 104 | 109 | 110 | ); 111 | } 112 | } 113 | 114 | const styles = StyleSheet.create({ 115 | container: { 116 | flex: 1, 117 | backgroundColor: '#fff', 118 | alignItems: 'center', 119 | justifyContent: 'center', 120 | }, 121 | }); 122 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # aws-iot-device-sdk-js-react-native 2 | React Native Component wrapper for connecting to AWS IoT from a device using SDK JavaScript bundle 3 | 4 | Allows developers to use the AWS IOT shadow support from a React Native component. 5 | 6 | * [Overview](#overview) 7 | * [Installation](#install) 8 | * [Examples](#examples) 9 | * [API Documentation](#api) 10 | * [Connection Types](#connections) 11 | * [AWS bundle](#bundle) 12 | * [Debugging mode](#debug) 13 | * [Unit Tests](#unittests) 14 | * [License](#license) 15 | * [Support](#support) 16 | 17 | 18 | ## Overview 19 | This document provides instructions on how to install and configure the AWS 20 | IoT device/Shadow in React Native. 21 | 22 | ### AWS SDK Dependency 23 | This package is built on top of the AWS SDK [aws-sdk.js](https://github.com/aws/aws-iot-device-sdk-js) which provides two classes: 'device' 24 | and 'thingShadow'. 25 | 26 | #### Thing Shadows 27 | The 'thingShadow' class implements additional functionality for accessing Thing Shadows via the AWS IoT 28 | API; the thingShadow class allows devices to update, be notified of changes to, 29 | get the current state of, or delete Thing Shadows from AWS IoT. Thing 30 | Shadows allow applications and devices to synchronize their state on the AWS IoT platform. 31 | 32 | #### Device 33 | The 'device' class wraps [mqtt.js](https://github.com/mqttjs/MQTT.js/blob/master/README.md) to provide a 34 | secure connection to the AWS IoT platform and expose the [mqtt.js](https://github.com/mqttjs/MQTT.js/blob/master/README.md) interfaces upward. It provides features to simplify handling of intermittent connections, including progressive backoff retries, automatic re-subscription upon connection, and queued offline publishing with configurable drain rate. 35 | 36 | 37 | ## Installation 38 | 39 | Installing with npm: 40 | 41 | ```sh 42 | npm install react-native-aws-iot-device-shadows 43 | ``` 44 | 45 | 46 | ## Examples 47 | 48 | ### MQTT React Native IoT Shadow Class 49 | ```js 50 | { this.AWSIoTMQTT = ref; }} 52 | type="shadow" 53 | region="us-west-2" 54 | host="asdasd.iot.aws.com" 55 | onReconnect={() => this.onConnect()} 56 | onConnect={() => this.onConnect()} 57 | onDelta={(thingId, stateObject) => this.onDelta(thingId, stateObject)} 58 | onStatus={(thingId, statusType, clientToken, stateObject) => 59 | this.onStatus(thingId, statusType, clientToken, stateObject)} 60 | onThingConnected={(thingId) => { this.onThingConnected(thingId); }} 61 | /> 62 | ``` 63 | 64 | ### MQTT React Native IoT device Class 65 | ```js 66 | { this.AWSIoTMQTT = ref; }} 68 | type="device" 69 | region="us-west-2" 70 | host="asdasd.iot.aws.com" 71 | onReconnect={() => this.onConnect()} 72 | onConnect={() => this.onConnect()} 73 | /> 74 | ``` 75 | 76 | 77 | ## AWSIoTMQTT 78 | 79 | Returns a React Native component whichs wraps xxxxxxxx 80 | 81 | 82 | 83 | ## API Documentation 84 | 85 | * `type`: use 'device' for device type and 'shadows' for ShadowThing 86 | * `host`: the AWS IoT endpoint you will use to connect 87 | * `region`: the AWS IoT region you will use to connect 88 | * `config`: extra configuration for the thingShadow 89 | * `onConnect`: callback for when the websockets connects 90 | * `onReconnect`: callback for when the websockets reconnects 91 | * `onDelta`: callback for delta msg 92 | * `onStatus`: callback for status msg 93 | * `onThingConnected`: callback for each registered thing 94 | 95 | 96 | ## Connection Types 97 | 98 | This react native component only supports one type of connections to the AWS IoT platform: 99 | 100 | * MQTT over WebSocket/TLS with SigV4 authentication using port 443 101 | 102 | 103 | 104 | ## Debug 105 | 106 | The enable debug mode for display logging information just pass a object with debug:true 107 | 108 | ```js 109 | 113 | ``` 114 | 115 | 116 | ## Re-Creating the bundle with webpack 117 | This IOT JS SDK is packaged with[webpack](https://webpack.js.org/), because currently there is not official support for AWS IOT react native. This is already bundle it for you using the last version. 118 | 119 | ```sh 120 | npm run build 121 | ``` 122 | 123 | 124 | ## Unit Tests 125 | 126 | This package includes unit tests which can be run as follows: 127 | 128 | ```sh 129 | npm test 130 | ``` 131 | 132 | Running the unit tests will also generate code coverage data in the 'reports' 133 | directory. 134 | 135 | 136 | ## License 137 | This react native component is distributed under the [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0), see LICENSE.txt and NOTICE.txt for more information. 138 | 139 | 140 | ## Support 141 | feel free to open any ticket in github issues 142 | -------------------------------------------------------------------------------- /examples/mqtt-shadows-cognitopool/README.md: -------------------------------------------------------------------------------- 1 | This project was bootstrapped with [Create React Native App](https://github.com/react-community/create-react-native-app). 2 | 3 | Below you'll find information about performing common tasks. The most recent version of this guide is available [here](https://github.com/react-community/create-react-native-app/blob/master/react-native-scripts/template/README.md). 4 | 5 | ## Table of Contents 6 | 7 | * [Updating to New Releases](#updating-to-new-releases) 8 | * [Available Scripts](#available-scripts) 9 | * [npm start](#npm-start) 10 | * [npm test](#npm-test) 11 | * [npm run ios](#npm-run-ios) 12 | * [npm run android](#npm-run-android) 13 | * [npm run eject](#npm-run-eject) 14 | * [Writing and Running Tests](#writing-and-running-tests) 15 | * [Environment Variables](#environment-variables) 16 | * [Configuring Packager IP Address](#configuring-packager-ip-address) 17 | * [Adding Flow](#adding-flow) 18 | * [Customizing App Display Name and Icon](#customizing-app-display-name-and-icon) 19 | * [Sharing and Deployment](#sharing-and-deployment) 20 | * [Publishing to Expo's React Native Community](#publishing-to-expos-react-native-community) 21 | * [Building an Expo "standalone" app](#building-an-expo-standalone-app) 22 | * [Ejecting from Create React Native App](#ejecting-from-create-react-native-app) 23 | * [Build Dependencies (Xcode & Android Studio)](#build-dependencies-xcode-android-studio) 24 | * [Should I Use ExpoKit?](#should-i-use-expokit) 25 | * [Troubleshooting](#troubleshooting) 26 | * [Networking](#networking) 27 | * [iOS Simulator won't open](#ios-simulator-wont-open) 28 | * [QR Code does not scan](#qr-code-does-not-scan) 29 | 30 | ## Updating to New Releases 31 | 32 | You should only need to update the global installation of `create-react-native-app` very rarely, ideally never. 33 | 34 | Updating the `react-native-scripts` dependency of your app should be as simple as bumping the version number in `package.json` and reinstalling your project's dependencies. 35 | 36 | Upgrading to a new version of React Native requires updating the `react-native`, `react`, and `expo` package versions, and setting the correct `sdkVersion` in `app.json`. See the [versioning guide](https://github.com/react-community/create-react-native-app/blob/master/VERSIONS.md) for up-to-date information about package version compatibility. 37 | 38 | ## Available Scripts 39 | 40 | If Yarn was installed when the project was initialized, then dependencies will have been installed via Yarn, and you should probably use it to run these commands as well. Unlike dependency installation, command running syntax is identical for Yarn and NPM at the time of this writing. 41 | 42 | ### `npm start` 43 | 44 | Runs your app in development mode. 45 | 46 | Open it in the [Expo app](https://expo.io) on your phone to view it. It will reload if you save edits to your files, and you will see build errors and logs in the terminal. 47 | 48 | Sometimes you may need to reset or clear the React Native packager's cache. To do so, you can pass the `--reset-cache` flag to the start script: 49 | 50 | ``` 51 | npm start -- --reset-cache 52 | # or 53 | yarn start -- --reset-cache 54 | ``` 55 | 56 | #### `npm test` 57 | 58 | Runs the [jest](https://github.com/facebook/jest) test runner on your tests. 59 | 60 | #### `npm run ios` 61 | 62 | Like `npm start`, but also attempts to open your app in the iOS Simulator if you're on a Mac and have it installed. 63 | 64 | #### `npm run android` 65 | 66 | Like `npm start`, but also attempts to open your app on a connected Android device or emulator. Requires an installation of Android build tools (see [React Native docs](https://facebook.github.io/react-native/docs/getting-started.html) for detailed setup). We also recommend installing Genymotion as your Android emulator. Once you've finished setting up the native build environment, there are two options for making the right copy of `adb` available to Create React Native App: 67 | 68 | ##### Using Android Studio's `adb` 69 | 70 | 1. Make sure that you can run adb from your terminal. 71 | 2. Open Genymotion and navigate to `Settings -> ADB`. Select “Use custom Android SDK tools” and update with your [Android SDK directory](https://stackoverflow.com/questions/25176594/android-sdk-location). 72 | 73 | ##### Using Genymotion's `adb` 74 | 75 | 1. Find Genymotion’s copy of adb. On macOS for example, this is normally `/Applications/Genymotion.app/Contents/MacOS/tools/`. 76 | 2. Add the Genymotion tools directory to your path (instructions for [Mac](http://osxdaily.com/2014/08/14/add-new-path-to-path-command-line/), [Linux](http://www.computerhope.com/issues/ch001647.htm), and [Windows](https://www.howtogeek.com/118594/how-to-edit-your-system-path-for-easy-command-line-access/)). 77 | 3. Make sure that you can run adb from your terminal. 78 | 79 | #### `npm run eject` 80 | 81 | This will start the process of "ejecting" from Create React Native App's build scripts. You'll be asked a couple of questions about how you'd like to build your project. 82 | 83 | **Warning:** Running eject is a permanent action (aside from whatever version control system you use). An ejected app will require you to have an [Xcode and/or Android Studio environment](https://facebook.github.io/react-native/docs/getting-started.html) set up. 84 | 85 | ## Customizing App Display Name and Icon 86 | 87 | You can edit `app.json` to include [configuration keys](https://docs.expo.io/versions/latest/guides/configuration.html) under the `expo` key. 88 | 89 | To change your app's display name, set the `expo.name` key in `app.json` to an appropriate string. 90 | 91 | To set an app icon, set the `expo.icon` key in `app.json` to be either a local path or a URL. It's recommended that you use a 512x512 png file with transparency. 92 | 93 | ## Writing and Running Tests 94 | 95 | This project is set up to use [jest](https://facebook.github.io/jest/) for tests. You can configure whatever testing strategy you like, but jest works out of the box. Create test files in directories called `__tests__` or with the `.test` extension to have the files loaded by jest. See the [the template project](https://github.com/react-community/create-react-native-app/blob/master/react-native-scripts/template/App.test.js) for an example test. The [jest documentation](https://facebook.github.io/jest/docs/getting-started.html) is also a wonderful resource, as is the [React Native testing tutorial](https://facebook.github.io/jest/docs/tutorial-react-native.html). 96 | 97 | ## Environment Variables 98 | 99 | You can configure some of Create React Native App's behavior using environment variables. 100 | 101 | ### Configuring Packager IP Address 102 | 103 | When starting your project, you'll see something like this for your project URL: 104 | 105 | ``` 106 | exp://192.168.0.2:19000 107 | ``` 108 | 109 | The "manifest" at that URL tells the Expo app how to retrieve and load your app's JavaScript bundle, so even if you load it in the app via a URL like `exp://localhost:19000`, the Expo client app will still try to retrieve your app at the IP address that the start script provides. 110 | 111 | In some cases, this is less than ideal. This might be the case if you need to run your project inside of a virtual machine and you have to access the packager via a different IP address than the one which prints by default. In order to override the IP address or hostname that is detected by Create React Native App, you can specify your own hostname via the `REACT_NATIVE_PACKAGER_HOSTNAME` environment variable: 112 | 113 | Mac and Linux: 114 | 115 | ``` 116 | REACT_NATIVE_PACKAGER_HOSTNAME='my-custom-ip-address-or-hostname' npm start 117 | ``` 118 | 119 | Windows: 120 | ``` 121 | set REACT_NATIVE_PACKAGER_HOSTNAME='my-custom-ip-address-or-hostname' 122 | npm start 123 | ``` 124 | 125 | The above example would cause the development server to listen on `exp://my-custom-ip-address-or-hostname:19000`. 126 | 127 | ## Adding Flow 128 | 129 | Flow is a static type checker that helps you write code with fewer bugs. Check out this [introduction to using static types in JavaScript](https://medium.com/@preethikasireddy/why-use-static-types-in-javascript-part-1-8382da1e0adb) if you are new to this concept. 130 | 131 | React Native works with [Flow](http://flowtype.org/) out of the box, as long as your Flow version matches the one used in the version of React Native. 132 | 133 | To add a local dependency to the correct Flow version to a Create React Native App project, follow these steps: 134 | 135 | 1. Find the Flow `[version]` at the bottom of the included [.flowconfig](.flowconfig) 136 | 2. Run `npm install --save-dev flow-bin@x.y.z` (or `yarn add --dev flow-bin@x.y.z`), where `x.y.z` is the .flowconfig version number. 137 | 3. Add `"flow": "flow"` to the `scripts` section of your `package.json`. 138 | 4. Add `// @flow` to any files you want to type check (for example, to `App.js`). 139 | 140 | Now you can run `npm run flow` (or `yarn flow`) to check the files for type errors. 141 | You can optionally use a [plugin for your IDE or editor](https://flow.org/en/docs/editors/) for a better integrated experience. 142 | 143 | To learn more about Flow, check out [its documentation](https://flow.org/). 144 | 145 | ## Sharing and Deployment 146 | 147 | Create React Native App does a lot of work to make app setup and development simple and straightforward, but it's very difficult to do the same for deploying to Apple's App Store or Google's Play Store without relying on a hosted service. 148 | 149 | ### Publishing to Expo's React Native Community 150 | 151 | Expo provides free hosting for the JS-only apps created by CRNA, allowing you to share your app through the Expo client app. This requires registration for an Expo account. 152 | 153 | Install the `exp` command-line tool, and run the publish command: 154 | 155 | ``` 156 | $ npm i -g exp 157 | $ exp publish 158 | ``` 159 | 160 | ### Building an Expo "standalone" app 161 | 162 | You can also use a service like [Expo's standalone builds](https://docs.expo.io/versions/latest/guides/building-standalone-apps.html) if you want to get an IPA/APK for distribution without having to build the native code yourself. 163 | 164 | ### Ejecting from Create React Native App 165 | 166 | If you want to build and deploy your app yourself, you'll need to eject from CRNA and use Xcode and Android Studio. 167 | 168 | This is usually as simple as running `npm run eject` in your project, which will walk you through the process. Make sure to install `react-native-cli` and follow the [native code getting started guide for React Native](https://facebook.github.io/react-native/docs/getting-started.html). 169 | 170 | #### Should I Use ExpoKit? 171 | 172 | If you have made use of Expo APIs while working on your project, then those API calls will stop working if you eject to a regular React Native project. If you want to continue using those APIs, you can eject to "React Native + ExpoKit" which will still allow you to build your own native code and continue using the Expo APIs. See the [ejecting guide](https://github.com/react-community/create-react-native-app/blob/master/EJECTING.md) for more details about this option. 173 | 174 | ## Troubleshooting 175 | 176 | ### Networking 177 | 178 | If you're unable to load your app on your phone due to a network timeout or a refused connection, a good first step is to verify that your phone and computer are on the same network and that they can reach each other. Create React Native App needs access to ports 19000 and 19001 so ensure that your network and firewall settings allow access from your device to your computer on both of these ports. 179 | 180 | Try opening a web browser on your phone and opening the URL that the packager script prints, replacing `exp://` with `http://`. So, for example, if underneath the QR code in your terminal you see: 181 | 182 | ``` 183 | exp://192.168.0.1:19000 184 | ``` 185 | 186 | Try opening Safari or Chrome on your phone and loading 187 | 188 | ``` 189 | http://192.168.0.1:19000 190 | ``` 191 | 192 | and 193 | 194 | ``` 195 | http://192.168.0.1:19001 196 | ``` 197 | 198 | If this works, but you're still unable to load your app by scanning the QR code, please open an issue on the [Create React Native App repository](https://github.com/react-community/create-react-native-app) with details about these steps and any other error messages you may have received. 199 | 200 | If you're not able to load the `http` URL in your phone's web browser, try using the tethering/mobile hotspot feature on your phone (beware of data usage, though), connecting your computer to that WiFi network, and restarting the packager. 201 | 202 | ### iOS Simulator won't open 203 | 204 | If you're on a Mac, there are a few errors that users sometimes see when attempting to `npm run ios`: 205 | 206 | * "non-zero exit code: 107" 207 | * "You may need to install Xcode" but it is already installed 208 | * and others 209 | 210 | There are a few steps you may want to take to troubleshoot these kinds of errors: 211 | 212 | 1. Make sure Xcode is installed and open it to accept the license agreement if it prompts you. You can install it from the Mac App Store. 213 | 2. Open Xcode's Preferences, the Locations tab, and make sure that the `Command Line Tools` menu option is set to something. Sometimes when the CLI tools are first installed by Homebrew this option is left blank, which can prevent Apple utilities from finding the simulator. Make sure to re-run `npm/yarn run ios` after doing so. 214 | 3. If that doesn't work, open the Simulator, and under the app menu select `Reset Contents and Settings...`. After that has finished, quit the Simulator, and re-run `npm/yarn run ios`. 215 | 216 | ### QR Code does not scan 217 | 218 | If you're not able to scan the QR code, make sure your phone's camera is focusing correctly, and also make sure that the contrast on the two colors in your terminal is high enough. For example, WebStorm's default themes may [not have enough contrast](https://github.com/react-community/create-react-native-app/issues/49) for terminal QR codes to be scannable with the system barcode scanners that the Expo app uses. 219 | 220 | If this causes problems for you, you may want to try changing your terminal's color theme to have more contrast, or running Create React Native App from a different terminal. You can also manually enter the URL printed by the packager script in the Expo app's search bar to load it manually. 221 | -------------------------------------------------------------------------------- /aws-iot-device-sdk-js-react-native.js: -------------------------------------------------------------------------------- 1 | !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.pro1=e():t.pro1=e()}(this,function(){return function(t){function e(r){if(n[r])return n[r].exports;var i=n[r]={i:r,l:!1,exports:{}};return t[r].call(i.exports,i,i.exports,e),i.l=!0,i.exports}var n={};return e.m=t,e.c=n,e.i=function(t){return t},e.d=function(t,n,r){e.o(t,n)||Object.defineProperty(t,n,{configurable:!1,enumerable:!0,get:r})},e.n=function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(n,"a",n),n},e.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},e.p="",e(e.s=43)}([function(t,e,n){!function(n,r){t.exports=e=r()}(0,function(){var t=t||function(t,e){var n={},r=n.lib={},i=r.Base=function(){function t(){}return{extend:function(e){t.prototype=this;var n=new t;return e&&n.mixIn(e),n.hasOwnProperty("init")||(n.init=function(){n.$super.init.apply(this,arguments)}),n.init.prototype=n,n.$super=this,n},create:function(){var t=this.extend();return t.init.apply(t,arguments),t},init:function(){},mixIn:function(t){for(var e in t)t.hasOwnProperty(e)&&(this[e]=t[e]);t.hasOwnProperty("toString")&&(this.toString=t.toString)},clone:function(){return this.init.prototype.extend(this)}}}(),o=r.WordArray=i.extend({init:function(t,e){t=this.words=t||[],this.sigBytes=void 0!=e?e:4*t.length},toString:function(t){return(t||a).stringify(this)},concat:function(t){var e=this.words,n=t.words,r=this.sigBytes,i=t.sigBytes;if(this.clamp(),r%4)for(var o=0;o>>2]>>>24-o%4*8&255;e[r+o>>>2]|=s<<24-(r+o)%4*8}else for(var o=0;o>>2]=n[o>>>2];return this.sigBytes+=i,this},clamp:function(){var e=this.words,n=this.sigBytes;e[n>>>2]&=4294967295<<32-n%4*8,e.length=t.ceil(n/4)},clone:function(){var t=i.clone.call(this);return t.words=this.words.slice(0),t},random:function(e){for(var n,r=[],i=0;i>16)&r,e=18e3*(65535&e)+(e>>16)&r;var i=(n<<16)+e&r;return i/=4294967296,(i+=.5)*(t.random()>.5?1:-1)}}(4294967296*(n||t.random()));n=987654071*s(),r.push(4294967296*s()|0)}return new o.init(r,e)}}),s=n.enc={},a=s.Hex={stringify:function(t){for(var e=t.words,n=t.sigBytes,r=[],i=0;i>>2]>>>24-i%4*8&255;r.push((o>>>4).toString(16)),r.push((15&o).toString(16))}return r.join("")},parse:function(t){for(var e=t.length,n=[],r=0;r>>3]|=parseInt(t.substr(r,2),16)<<24-r%8*4;return new o.init(n,e/2)}},c=s.Latin1={stringify:function(t){for(var e=t.words,n=t.sigBytes,r=[],i=0;i>>2]>>>24-i%4*8&255;r.push(String.fromCharCode(o))}return r.join("")},parse:function(t){for(var e=t.length,n=[],r=0;r>>2]|=(255&t.charCodeAt(r))<<24-r%4*8;return new o.init(n,e)}},u=s.Utf8={stringify:function(t){try{return decodeURIComponent(escape(c.stringify(t)))}catch(t){throw new Error("Malformed UTF-8 data")}},parse:function(t){return c.parse(unescape(encodeURIComponent(t)))}},h=r.BufferedBlockAlgorithm=i.extend({reset:function(){this._data=new o.init,this._nDataBytes=0},_append:function(t){"string"==typeof t&&(t=u.parse(t)),this._data.concat(t),this._nDataBytes+=t.sigBytes},_process:function(e){var n=this._data,r=n.words,i=n.sigBytes,s=this.blockSize,a=4*s,c=i/a;c=e?t.ceil(c):t.max((0|c)-this._minBufferSize,0);var u=c*s,h=t.min(4*u,i);if(u){for(var f=0;f>>2];t.sigBytes-=e}},b=(r.BlockCipher=f.extend({cfg:f.cfg.extend({mode:d,padding:v}),reset:function(){f.reset.call(this);var t=this.cfg,e=t.iv,n=t.mode;if(this._xformMode==this._ENC_XFORM_MODE)var r=n.createEncryptor;else{var r=n.createDecryptor;this._minBufferSize=1}this._mode=r.call(n,this,e&&e.words)},_doProcessBlock:function(t,e){this._mode.processBlock(t,e)},_doFinalize:function(){var t=this.cfg.padding;if(this._xformMode==this._ENC_XFORM_MODE){t.pad(this._data,this.blockSize);var e=this._process(!0)}else{var e=this._process(!0);t.unpad(e)}return e},blockSize:4}),r.CipherParams=i.extend({init:function(t){this.mixIn(t)},toString:function(t){return(t||this.formatter).stringify(this)}})),y=n.format={},_=y.OpenSSL={stringify:function(t){var e=t.ciphertext,n=t.salt;if(n)var r=o.create([1398893684,1701076831]).concat(n).concat(e);else var r=e;return r.toString(c)},parse:function(t){var e=c.parse(t),n=e.words;if(1398893684==n[0]&&1701076831==n[1]){var r=o.create(n.slice(2,4));n.splice(0,4),e.sigBytes-=16}return b.create({ciphertext:e,salt:r})}},m=r.SerializableCipher=i.extend({cfg:i.extend({format:_}),encrypt:function(t,e,n,r){r=this.cfg.extend(r);var i=t.createEncryptor(n,r),o=i.finalize(e),s=i.cfg;return b.create({ciphertext:o,key:n,iv:s.iv,algorithm:t,mode:s.mode,padding:s.padding,blockSize:t.blockSize,formatter:r.format})},decrypt:function(t,e,n,r){return r=this.cfg.extend(r),e=this._parse(e,r.format),t.createDecryptor(n,r).finalize(e.ciphertext)},_parse:function(t,e){return"string"==typeof t?e.parse(t,this):t}}),w=n.kdf={},S=w.OpenSSL={execute:function(t,e,n,r){r||(r=o.random(8));var i=h.create({keySize:e+n}).compute(t,r),s=o.create(i.words.slice(e),4*n);return i.sigBytes=4*e,b.create({key:i,iv:s,salt:r})}},E=r.PasswordBasedCipher=m.extend({cfg:m.cfg.extend({kdf:S}),encrypt:function(t,e,n,r){r=this.cfg.extend(r);var i=r.kdf.execute(n,t.keySize,t.ivSize);r.iv=i.iv;var o=m.encrypt.call(this,t,e,i.key,r);return o.mixIn(i),o},decrypt:function(t,e,n,r){r=this.cfg.extend(r),e=this._parse(e,r.format);var i=r.kdf.execute(n,t.keySize,t.ivSize,e.salt);return r.iv=i.iv,m.decrypt.call(this,t,e,i.key,r)}})}()})},function(t,e){function n(){throw new Error("setTimeout has not been defined")}function r(){throw new Error("clearTimeout has not been defined")}function i(t){if(h===setTimeout)return setTimeout(t,0);if((h===n||!h)&&setTimeout)return h=setTimeout,setTimeout(t,0);try{return h(t,0)}catch(e){try{return h.call(null,t,0)}catch(e){return h.call(this,t,0)}}}function o(t){if(f===clearTimeout)return clearTimeout(t);if((f===r||!f)&&clearTimeout)return f=clearTimeout,clearTimeout(t);try{return f(t)}catch(e){try{return f.call(null,t)}catch(e){return f.call(this,t)}}}function s(){g&&p&&(g=!1,p.length?d=p.concat(d):v=-1,d.length&&a())}function a(){if(!g){var t=i(s);g=!0;for(var e=d.length;e;){for(p=d,d=[];++v1)for(var n=1;n0&&this._events[t].length>i&&(this._events[t].warned=!0,console.trace),this},n.prototype.on=n.prototype.addListener,n.prototype.once=function(t,e){function n(){this.removeListener(t,n),i||(i=!0,e.apply(this,arguments))}if(!r(e))throw TypeError("listener must be a function");var i=!1;return n.listener=e,this.on(t,n),this},n.prototype.removeListener=function(t,e){var n,i,s,a;if(!r(e))throw TypeError("listener must be a function");if(!this._events||!this._events[t])return this;if(n=this._events[t],s=n.length,i=-1,n===e||r(n.listener)&&n.listener===e)delete this._events[t],this._events.removeListener&&this.emit("removeListener",t,e);else if(o(n)){for(a=s;a-- >0;)if(n[a]===e||n[a].listener&&n[a].listener===e){i=a;break}if(i<0)return this;1===n.length?(n.length=0,delete this._events[t]):n.splice(i,1),this._events.removeListener&&this.emit("removeListener",t,e)}return this},n.prototype.removeAllListeners=function(t){var e,n;if(!this._events)return this;if(!this._events.removeListener)return 0===arguments.length?this._events={}:this._events[t]&&delete this._events[t],this;if(0===arguments.length){for(e in this._events)"removeListener"!==e&&this.removeAllListeners(e);return this.removeAllListeners("removeListener"),this._events={},this}if(n=this._events[t],r(n))this.removeListener(t,n);else if(n)for(;n.length;)this.removeListener(t,n[n.length-1]);return delete this._events[t],this},n.prototype.listeners=function(t){return this._events&&this._events[t]?r(this._events[t])?[this._events[t]]:this._events[t].slice():[]},n.prototype.listenerCount=function(t){if(this._events){var e=this._events[t];if(r(e))return 1;if(e)return e.length}return 0},n.listenerCount=function(t,e){return t.listenerCount(e)}},function(t,e,n){"use strict";function r(t){if(!(this instanceof r))return new r(t);u.call(this,t),h.call(this,t),t&&!1===t.readable&&(this.readable=!1),t&&!1===t.writable&&(this.writable=!1),this.allowHalfOpen=!0,t&&!1===t.allowHalfOpen&&(this.allowHalfOpen=!1),this.once("end",i)}function i(){this.allowHalfOpen||this._writableState.ended||s(o,this)}function o(t){t.end()}var s=n(15).nextTick,a=Object.keys||function(t){var e=[];for(var n in t)e.push(n);return e};t.exports=r;var c=n(12);c.inherits=n(4);var u=n(36),h=n(38);c.inherits(r,u);for(var f=a(h.prototype),l=0;l>>2]>>>24-o%4*8&255,a=e[o+1>>>2]>>>24-(o+1)%4*8&255,c=e[o+2>>>2]>>>24-(o+2)%4*8&255,u=s<<16|a<<8|c,h=0;h<4&&o+.75*h>>6*(3-h)&63));var f=r.charAt(64);if(f)for(;i.length%4;)i.push(f);return i.join("")},parse:function(t){var e=t.length,n=this._map,i=n.charAt(64);if(i){var o=t.indexOf(i);-1!=o&&(e=o)}for(var s=[],a=0,c=0;c>>6-c%4*2,f=u|h;s[a>>>2]|=f<<24-a%4*8,a++}return r.create(s,a)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="}}(),t.enc.Base64})},function(t,e,n){!function(r,i,o){t.exports=e=i(n(0),n(20),n(19))}(0,function(t){return function(){var e=t,n=e.lib,r=n.Base,i=n.WordArray,o=e.algo,s=o.MD5,a=o.EvpKDF=r.extend({cfg:r.extend({keySize:4,hasher:s,iterations:1}),init:function(t){this.cfg=this.cfg.extend(t)},compute:function(t,e){for(var n=this.cfg,r=n.hasher.create(),o=i.create(),s=o.words,a=n.keySize,c=n.iterations;s.length>>32-o)+e}function r(t,e,n,r,i,o,s){var a=t+(e&r|n&~r)+i+s;return(a<>>32-o)+e}function i(t,e,n,r,i,o,s){var a=t+(e^n^r)+i+s;return(a<>>32-o)+e}function o(t,e,n,r,i,o,s){var a=t+(n^(e|~r))+i+s;return(a<>>32-o)+e}var s=t,a=s.lib,c=a.WordArray,u=a.Hasher,h=s.algo,f=[];!function(){for(var t=0;t<64;t++)f[t]=4294967296*e.abs(e.sin(t+1))|0}();var l=h.MD5=u.extend({_doReset:function(){this._hash=new c.init([1732584193,4023233417,2562383102,271733878])},_doProcessBlock:function(t,e){for(var s=0;s<16;s++){var a=e+s,c=t[a];t[a]=16711935&(c<<8|c>>>24)|4278255360&(c<<24|c>>>8)}var u=this._hash.words,h=t[e+0],l=t[e+1],p=t[e+2],d=t[e+3],g=t[e+4],v=t[e+5],b=t[e+6],y=t[e+7],_=t[e+8],m=t[e+9],w=t[e+10],S=t[e+11],E=t[e+12],k=t[e+13],I=t[e+14],A=t[e+15],x=u[0],T=u[1],C=u[2],B=u[3];x=n(x,T,C,B,h,7,f[0]),B=n(B,x,T,C,l,12,f[1]),C=n(C,B,x,T,p,17,f[2]),T=n(T,C,B,x,d,22,f[3]),x=n(x,T,C,B,g,7,f[4]),B=n(B,x,T,C,v,12,f[5]),C=n(C,B,x,T,b,17,f[6]),T=n(T,C,B,x,y,22,f[7]),x=n(x,T,C,B,_,7,f[8]),B=n(B,x,T,C,m,12,f[9]),C=n(C,B,x,T,w,17,f[10]),T=n(T,C,B,x,S,22,f[11]),x=n(x,T,C,B,E,7,f[12]),B=n(B,x,T,C,k,12,f[13]),C=n(C,B,x,T,I,17,f[14]),T=n(T,C,B,x,A,22,f[15]),x=r(x,T,C,B,l,5,f[16]),B=r(B,x,T,C,b,9,f[17]),C=r(C,B,x,T,S,14,f[18]),T=r(T,C,B,x,h,20,f[19]),x=r(x,T,C,B,v,5,f[20]),B=r(B,x,T,C,w,9,f[21]),C=r(C,B,x,T,A,14,f[22]),T=r(T,C,B,x,g,20,f[23]),x=r(x,T,C,B,m,5,f[24]),B=r(B,x,T,C,I,9,f[25]),C=r(C,B,x,T,d,14,f[26]),T=r(T,C,B,x,_,20,f[27]),x=r(x,T,C,B,k,5,f[28]),B=r(B,x,T,C,p,9,f[29]),C=r(C,B,x,T,y,14,f[30]),T=r(T,C,B,x,E,20,f[31]),x=i(x,T,C,B,v,4,f[32]),B=i(B,x,T,C,_,11,f[33]),C=i(C,B,x,T,S,16,f[34]),T=i(T,C,B,x,I,23,f[35]),x=i(x,T,C,B,l,4,f[36]),B=i(B,x,T,C,g,11,f[37]),C=i(C,B,x,T,y,16,f[38]),T=i(T,C,B,x,w,23,f[39]),x=i(x,T,C,B,k,4,f[40]),B=i(B,x,T,C,h,11,f[41]),C=i(C,B,x,T,d,16,f[42]),T=i(T,C,B,x,b,23,f[43]),x=i(x,T,C,B,m,4,f[44]),B=i(B,x,T,C,E,11,f[45]),C=i(C,B,x,T,A,16,f[46]),T=i(T,C,B,x,p,23,f[47]),x=o(x,T,C,B,h,6,f[48]),B=o(B,x,T,C,y,10,f[49]),C=o(C,B,x,T,I,15,f[50]),T=o(T,C,B,x,v,21,f[51]),x=o(x,T,C,B,E,6,f[52]),B=o(B,x,T,C,d,10,f[53]),C=o(C,B,x,T,w,15,f[54]),T=o(T,C,B,x,l,21,f[55]),x=o(x,T,C,B,_,6,f[56]),B=o(B,x,T,C,A,10,f[57]),C=o(C,B,x,T,b,15,f[58]),T=o(T,C,B,x,k,21,f[59]),x=o(x,T,C,B,g,6,f[60]),B=o(B,x,T,C,S,10,f[61]),C=o(C,B,x,T,p,15,f[62]),T=o(T,C,B,x,m,21,f[63]),u[0]=u[0]+x|0,u[1]=u[1]+T|0,u[2]=u[2]+C|0,u[3]=u[3]+B|0},_doFinalize:function(){var t=this._data,n=t.words,r=8*this._nDataBytes,i=8*t.sigBytes;n[i>>>5]|=128<<24-i%32;var o=e.floor(r/4294967296),s=r;n[15+(i+64>>>9<<4)]=16711935&(o<<8|o>>>24)|4278255360&(o<<24|o>>>8),n[14+(i+64>>>9<<4)]=16711935&(s<<8|s>>>24)|4278255360&(s<<24|s>>>8),t.sigBytes=4*(n.length+1),this._process();for(var a=this._hash,c=a.words,u=0;u<4;u++){var h=c[u];c[u]=16711935&(h<<8|h>>>24)|4278255360&(h<<24|h>>>8)}return a},clone:function(){var t=u.clone.call(this);return t._hash=this._hash.clone(),t}});s.MD5=u._createHelper(l),s.HmacMD5=u._createHmacHelper(l)}(Math),t.MD5})},function(t,e,n){"use strict";(function(t){function r(){return o.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function i(t,e){if(r()=r())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+r().toString(16)+" bytes");return 0|t}function g(t){return+t!=t&&(t=0),o.alloc(+t)}function v(t,e){if(o.isBuffer(t))return t.length;if("undefined"!=typeof ArrayBuffer&&"function"==typeof ArrayBuffer.isView&&(ArrayBuffer.isView(t)||t instanceof ArrayBuffer))return t.byteLength;"string"!=typeof t&&(t=""+t);var n=t.length;if(0===n)return 0;for(var r=!1;;)switch(e){case"ascii":case"latin1":case"binary":return n;case"utf8":case"utf-8":case void 0:return W(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*n;case"hex":return n>>>1;case"base64":return V(t).length;default:if(r)return W(t).length;e=(""+e).toLowerCase(),r=!0}}function b(t,e,n){var r=!1;if((void 0===e||e<0)&&(e=0),e>this.length)return"";if((void 0===n||n>this.length)&&(n=this.length),n<=0)return"";if(n>>>=0,e>>>=0,n<=e)return"";for(t||(t="utf8");;)switch(t){case"hex":return R(this,e,n);case"utf8":case"utf-8":return T(this,e,n);case"ascii":return B(this,e,n);case"latin1":case"binary":return O(this,e,n);case"base64":return x(this,e,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return M(this,e,n);default:if(r)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),r=!0}}function y(t,e,n){var r=t[e];t[e]=t[n],t[n]=r}function _(t,e,n,r,i){if(0===t.length)return-1;if("string"==typeof n?(r=n,n=0):n>2147483647?n=2147483647:n<-2147483648&&(n=-2147483648),n=+n,isNaN(n)&&(n=i?0:t.length-1),n<0&&(n=t.length+n),n>=t.length){if(i)return-1;n=t.length-1}else if(n<0){if(!i)return-1;n=0}if("string"==typeof e&&(e=o.from(e,r)),o.isBuffer(e))return 0===e.length?-1:m(t,e,n,r,i);if("number"==typeof e)return e&=255,o.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?i?Uint8Array.prototype.indexOf.call(t,e,n):Uint8Array.prototype.lastIndexOf.call(t,e,n):m(t,[e],n,r,i);throw new TypeError("val must be string, number or Buffer")}function m(t,e,n,r,i){function o(t,e){return 1===s?t[e]:t.readUInt16BE(e*s)}var s=1,a=t.length,c=e.length;if(void 0!==r&&("ucs2"===(r=String(r).toLowerCase())||"ucs-2"===r||"utf16le"===r||"utf-16le"===r)){if(t.length<2||e.length<2)return-1;s=2,a/=2,c/=2,n/=2}var u;if(i){var h=-1;for(u=n;ua&&(n=a-c),u=n;u>=0;u--){for(var f=!0,l=0;li&&(r=i):r=i;var o=e.length;if(o%2!=0)throw new TypeError("Invalid hex string");r>o/2&&(r=o/2);for(var s=0;s239?4:o>223?3:o>191?2:1;if(i+a<=n){var c,u,h,f;switch(a){case 1:o<128&&(s=o);break;case 2:c=t[i+1],128==(192&c)&&(f=(31&o)<<6|63&c)>127&&(s=f);break;case 3:c=t[i+1],u=t[i+2],128==(192&c)&&128==(192&u)&&(f=(15&o)<<12|(63&c)<<6|63&u)>2047&&(f<55296||f>57343)&&(s=f);break;case 4:c=t[i+1],u=t[i+2],h=t[i+3],128==(192&c)&&128==(192&u)&&128==(192&h)&&(f=(15&o)<<18|(63&c)<<12|(63&u)<<6|63&h)>65535&&f<1114112&&(s=f)}}null===s?(s=65533,a=1):s>65535&&(s-=65536,r.push(s>>>10&1023|55296),s=56320|1023&s),r.push(s),i+=a}return C(r)}function C(t){var e=t.length;if(e<=Z)return String.fromCharCode.apply(String,t);for(var n="",r=0;rr)&&(n=r);for(var i="",o=e;on)throw new RangeError("Trying to access beyond buffer length")}function N(t,e,n,r,i,s){if(!o.isBuffer(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>i||et.length)throw new RangeError("Index out of range")}function L(t,e,n,r){e<0&&(e=65535+e+1);for(var i=0,o=Math.min(t.length-n,2);i>>8*(r?i:1-i)}function j(t,e,n,r){e<0&&(e=4294967295+e+1);for(var i=0,o=Math.min(t.length-n,4);i>>8*(r?i:3-i)&255}function D(t,e,n,r,i,o){if(n+r>t.length)throw new RangeError("Index out of range");if(n<0)throw new RangeError("Index out of range")}function U(t,e,n,r,i){return i||D(t,e,n,4,3.4028234663852886e38,-3.4028234663852886e38),X.write(t,e,n,r,23,4),n+4}function H(t,e,n,r,i){return i||D(t,e,n,8,1.7976931348623157e308,-1.7976931348623157e308),X.write(t,e,n,r,52,8),n+8}function q(t){if(t=z(t).replace(tt,""),t.length<2)return"";for(;t.length%4!=0;)t+="=";return t}function z(t){return t.trim?t.trim():t.replace(/^\s+|\s+$/g,"")}function F(t){return t<16?"0"+t.toString(16):t.toString(16)}function W(t,e){e=e||1/0;for(var n,r=t.length,i=null,o=[],s=0;s55295&&n<57344){if(!i){if(n>56319){(e-=3)>-1&&o.push(239,191,189);continue}if(s+1===r){(e-=3)>-1&&o.push(239,191,189);continue}i=n;continue}if(n<56320){(e-=3)>-1&&o.push(239,191,189),i=n;continue}n=65536+(i-55296<<10|n-56320)}else i&&(e-=3)>-1&&o.push(239,191,189);if(i=null,n<128){if((e-=1)<0)break;o.push(n)}else if(n<2048){if((e-=2)<0)break;o.push(n>>6|192,63&n|128)}else if(n<65536){if((e-=3)<0)break;o.push(n>>12|224,n>>6&63|128,63&n|128)}else{if(!(n<1114112))throw new Error("Invalid code point");if((e-=4)<0)break;o.push(n>>18|240,n>>12&63|128,n>>6&63|128,63&n|128)}}return o}function K(t){for(var e=[],n=0;n>8,i=n%256,o.push(i),o.push(r);return o}function V(t){return G.toByteArray(q(t))}function Q(t,e,n,r){for(var i=0;i=e.length||i>=t.length);++i)e[i+n]=t[i];return i}function $(t){return t!==t}/*! 2 | * The buffer module from node.js, for the browser. 3 | * 4 | * @author Feross Aboukhadijeh 5 | * @license MIT 6 | */ 7 | var G=n(53),X=n(79),J=n(29);e.Buffer=o,e.SlowBuffer=g,e.INSPECT_MAX_BYTES=50,o.TYPED_ARRAY_SUPPORT=void 0!==t.TYPED_ARRAY_SUPPORT?t.TYPED_ARRAY_SUPPORT:function(){try{var t=new Uint8Array(1);return t.__proto__={__proto__:Uint8Array.prototype,foo:function(){return 42}},42===t.foo()&&"function"==typeof t.subarray&&0===t.subarray(1,1).byteLength}catch(t){return!1}}(),e.kMaxLength=r(),o.poolSize=8192,o._augment=function(t){return t.__proto__=o.prototype,t},o.from=function(t,e,n){return s(null,t,e,n)},o.TYPED_ARRAY_SUPPORT&&(o.prototype.__proto__=Uint8Array.prototype,o.__proto__=Uint8Array,"undefined"!=typeof Symbol&&Symbol.species&&o[Symbol.species]===o&&Object.defineProperty(o,Symbol.species,{value:null,configurable:!0})),o.alloc=function(t,e,n){return c(null,t,e,n)},o.allocUnsafe=function(t){return u(null,t)},o.allocUnsafeSlow=function(t){return u(null,t)},o.isBuffer=function(t){return!(null==t||!t._isBuffer)},o.compare=function(t,e){if(!o.isBuffer(t)||!o.isBuffer(e))throw new TypeError("Arguments must be Buffers");if(t===e)return 0;for(var n=t.length,r=e.length,i=0,s=Math.min(n,r);i0&&(t=this.toString("hex",0,n).match(/.{2}/g).join(" "),this.length>n&&(t+=" ... ")),""},o.prototype.compare=function(t,e,n,r,i){if(!o.isBuffer(t))throw new TypeError("Argument must be a Buffer");if(void 0===e&&(e=0),void 0===n&&(n=t?t.length:0),void 0===r&&(r=0),void 0===i&&(i=this.length),e<0||n>t.length||r<0||i>this.length)throw new RangeError("out of range index");if(r>=i&&e>=n)return 0;if(r>=i)return-1;if(e>=n)return 1;if(e>>>=0,n>>>=0,r>>>=0,i>>>=0,this===t)return 0;for(var s=i-r,a=n-e,c=Math.min(s,a),u=this.slice(r,i),h=t.slice(e,n),f=0;fi)&&(n=i),t.length>0&&(n<0||e<0)||e>this.length)throw new RangeError("Attempt to write outside buffer bounds");r||(r="utf8");for(var o=!1;;)switch(r){case"hex":return w(this,t,e,n);case"utf8":case"utf-8":return S(this,t,e,n);case"ascii":return E(this,t,e,n);case"latin1":case"binary":return k(this,t,e,n);case"base64":return I(this,t,e,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return A(this,t,e,n);default:if(o)throw new TypeError("Unknown encoding: "+r);r=(""+r).toLowerCase(),o=!0}},o.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var Z=4096;o.prototype.slice=function(t,e){var n=this.length;t=~~t,e=void 0===e?n:~~e,t<0?(t+=n)<0&&(t=0):t>n&&(t=n),e<0?(e+=n)<0&&(e=0):e>n&&(e=n),e0&&(i*=256);)r+=this[t+--e]*i;return r},o.prototype.readUInt8=function(t,e){return e||P(t,1,this.length),this[t]},o.prototype.readUInt16LE=function(t,e){return e||P(t,2,this.length),this[t]|this[t+1]<<8},o.prototype.readUInt16BE=function(t,e){return e||P(t,2,this.length),this[t]<<8|this[t+1]},o.prototype.readUInt32LE=function(t,e){return e||P(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},o.prototype.readUInt32BE=function(t,e){return e||P(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},o.prototype.readIntLE=function(t,e,n){t|=0,e|=0,n||P(t,e,this.length);for(var r=this[t],i=1,o=0;++o=i&&(r-=Math.pow(2,8*e)),r},o.prototype.readIntBE=function(t,e,n){t|=0,e|=0,n||P(t,e,this.length);for(var r=e,i=1,o=this[t+--r];r>0&&(i*=256);)o+=this[t+--r]*i;return i*=128,o>=i&&(o-=Math.pow(2,8*e)),o},o.prototype.readInt8=function(t,e){return e||P(t,1,this.length),128&this[t]?-1*(255-this[t]+1):this[t]},o.prototype.readInt16LE=function(t,e){e||P(t,2,this.length);var n=this[t]|this[t+1]<<8;return 32768&n?4294901760|n:n},o.prototype.readInt16BE=function(t,e){e||P(t,2,this.length);var n=this[t+1]|this[t]<<8;return 32768&n?4294901760|n:n},o.prototype.readInt32LE=function(t,e){return e||P(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},o.prototype.readInt32BE=function(t,e){return e||P(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},o.prototype.readFloatLE=function(t,e){return e||P(t,4,this.length),X.read(this,t,!0,23,4)},o.prototype.readFloatBE=function(t,e){return e||P(t,4,this.length),X.read(this,t,!1,23,4)},o.prototype.readDoubleLE=function(t,e){return e||P(t,8,this.length),X.read(this,t,!0,52,8)},o.prototype.readDoubleBE=function(t,e){return e||P(t,8,this.length),X.read(this,t,!1,52,8)},o.prototype.writeUIntLE=function(t,e,n,r){if(t=+t,e|=0,n|=0,!r){N(this,t,e,n,Math.pow(2,8*n)-1,0)}var i=1,o=0;for(this[e]=255&t;++o=0&&(o*=256);)this[e+i]=t/o&255;return e+n},o.prototype.writeUInt8=function(t,e,n){return t=+t,e|=0,n||N(this,t,e,1,255,0),o.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),this[e]=255&t,e+1},o.prototype.writeUInt16LE=function(t,e,n){return t=+t,e|=0,n||N(this,t,e,2,65535,0),o.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):L(this,t,e,!0),e+2},o.prototype.writeUInt16BE=function(t,e,n){return t=+t,e|=0,n||N(this,t,e,2,65535,0),o.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):L(this,t,e,!1),e+2},o.prototype.writeUInt32LE=function(t,e,n){return t=+t,e|=0,n||N(this,t,e,4,4294967295,0),o.TYPED_ARRAY_SUPPORT?(this[e+3]=t>>>24,this[e+2]=t>>>16,this[e+1]=t>>>8,this[e]=255&t):j(this,t,e,!0),e+4},o.prototype.writeUInt32BE=function(t,e,n){return t=+t,e|=0,n||N(this,t,e,4,4294967295,0),o.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):j(this,t,e,!1),e+4},o.prototype.writeIntLE=function(t,e,n,r){if(t=+t,e|=0,!r){var i=Math.pow(2,8*n-1);N(this,t,e,n,i-1,-i)}var o=0,s=1,a=0;for(this[e]=255&t;++o>0)-a&255;return e+n},o.prototype.writeIntBE=function(t,e,n,r){if(t=+t,e|=0,!r){var i=Math.pow(2,8*n-1);N(this,t,e,n,i-1,-i)}var o=n-1,s=1,a=0;for(this[e+o]=255&t;--o>=0&&(s*=256);)t<0&&0===a&&0!==this[e+o+1]&&(a=1),this[e+o]=(t/s>>0)-a&255;return e+n},o.prototype.writeInt8=function(t,e,n){return t=+t,e|=0,n||N(this,t,e,1,127,-128),o.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),t<0&&(t=255+t+1),this[e]=255&t,e+1},o.prototype.writeInt16LE=function(t,e,n){return t=+t,e|=0,n||N(this,t,e,2,32767,-32768),o.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):L(this,t,e,!0),e+2},o.prototype.writeInt16BE=function(t,e,n){return t=+t,e|=0,n||N(this,t,e,2,32767,-32768),o.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):L(this,t,e,!1),e+2},o.prototype.writeInt32LE=function(t,e,n){return t=+t,e|=0,n||N(this,t,e,4,2147483647,-2147483648),o.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8,this[e+2]=t>>>16,this[e+3]=t>>>24):j(this,t,e,!0),e+4},o.prototype.writeInt32BE=function(t,e,n){return t=+t,e|=0,n||N(this,t,e,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),o.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):j(this,t,e,!1),e+4},o.prototype.writeFloatLE=function(t,e,n){return U(this,t,e,!0,n)},o.prototype.writeFloatBE=function(t,e,n){return U(this,t,e,!1,n)},o.prototype.writeDoubleLE=function(t,e,n){return H(this,t,e,!0,n)},o.prototype.writeDoubleBE=function(t,e,n){return H(this,t,e,!1,n)},o.prototype.copy=function(t,e,n,r){if(n||(n=0),r||0===r||(r=this.length),e>=t.length&&(e=t.length),e||(e=0),r>0&&r=this.length)throw new RangeError("sourceStart out of bounds");if(r<0)throw new RangeError("sourceEnd out of bounds");r>this.length&&(r=this.length),t.length-e=0;--i)t[i+e]=this[i+n];else if(s<1e3||!o.TYPED_ARRAY_SUPPORT)for(i=0;i>>=0,n=void 0===n?this.length:n>>>0,t||(t=0);var s;if("number"==typeof t)for(s=e;s=3&&(r.depth=arguments[2]),arguments.length>=4&&(r.colors=arguments[3]),g(n)?r.showHidden=n:n&&e._extend(r,n),w(r.showHidden)&&(r.showHidden=!1),w(r.depth)&&(r.depth=2),w(r.colors)&&(r.colors=!1),w(r.customInspect)&&(r.customInspect=!0),r.colors&&(r.stylize=o),c(r,t,r.depth)}function o(t,e){var n=i.styles[e];return n?"["+i.colors[n][0]+"m"+t+"["+i.colors[n][1]+"m":t}function s(t,e){return t}function a(t){var e={};return t.forEach(function(t,n){e[t]=!0}),e}function c(t,n,r){if(t.customInspect&&n&&A(n.inspect)&&n.inspect!==e.inspect&&(!n.constructor||n.constructor.prototype!==n)){var i=n.inspect(r,t);return _(i)||(i=c(t,i,r)),i}var o=u(t,n);if(o)return o;var s=Object.keys(n),g=a(s);if(t.showHidden&&(s=Object.getOwnPropertyNames(n)),I(n)&&(s.indexOf("message")>=0||s.indexOf("description")>=0))return h(n);if(0===s.length){if(A(n)){var v=n.name?": "+n.name:"";return t.stylize("[Function"+v+"]","special")}if(S(n))return t.stylize(RegExp.prototype.toString.call(n),"regexp");if(k(n))return t.stylize(Date.prototype.toString.call(n),"date");if(I(n))return h(n)}var b="",y=!1,m=["{","}"];if(d(n)&&(y=!0,m=["[","]"]),A(n)){b=" [Function"+(n.name?": "+n.name:"")+"]"}if(S(n)&&(b=" "+RegExp.prototype.toString.call(n)),k(n)&&(b=" "+Date.prototype.toUTCString.call(n)),I(n)&&(b=" "+h(n)),0===s.length&&(!y||0==n.length))return m[0]+b+m[1];if(r<0)return S(n)?t.stylize(RegExp.prototype.toString.call(n),"regexp"):t.stylize("[Object]","special");t.seen.push(n);var w;return w=y?f(t,n,r,g,s):s.map(function(e){return l(t,n,r,g,e,y)}),t.seen.pop(),p(w,b,m)}function u(t,e){if(w(e))return t.stylize("undefined","undefined");if(_(e)){var n="'"+JSON.stringify(e).replace(/^"|"$/g,"").replace(/'/g,"\\'").replace(/\\"/g,'"')+"'";return t.stylize(n,"string")}return y(e)?t.stylize(""+e,"number"):g(e)?t.stylize(""+e,"boolean"):v(e)?t.stylize("null","null"):void 0}function h(t){return"["+Error.prototype.toString.call(t)+"]"}function f(t,e,n,r,i){for(var o=[],s=0,a=e.length;s-1&&(a=o?a.split("\n").map(function(t){return" "+t}).join("\n").substr(2):"\n"+a.split("\n").map(function(t){return" "+t}).join("\n"))):a=t.stylize("[Circular]","special")),w(s)){if(o&&i.match(/^\d+$/))return a;s=JSON.stringify(""+i),s.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)?(s=s.substr(1,s.length-2),s=t.stylize(s,"name")):(s=s.replace(/'/g,"\\'").replace(/\\"/g,'"').replace(/(^"|"$)/g,"'"),s=t.stylize(s,"string"))}return s+": "+a}function p(t,e,n){var r=0;return t.reduce(function(t,e){return r++,e.indexOf("\n")>=0&&r++,t+e.replace(/\u001b\[\d\d?m/g,"").length+1},0)>60?n[0]+(""===e?"":e+"\n ")+" "+t.join(",\n ")+" "+n[1]:n[0]+e+" "+t.join(", ")+" "+n[1]}function d(t){return Array.isArray(t)}function g(t){return"boolean"==typeof t}function v(t){return null===t}function b(t){return null==t}function y(t){return"number"==typeof t}function _(t){return"string"==typeof t}function m(t){return"symbol"==typeof t}function w(t){return void 0===t}function S(t){return E(t)&&"[object RegExp]"===T(t)}function E(t){return"object"==typeof t&&null!==t}function k(t){return E(t)&&"[object Date]"===T(t)}function I(t){return E(t)&&("[object Error]"===T(t)||t instanceof Error)}function A(t){return"function"==typeof t}function x(t){return null===t||"boolean"==typeof t||"number"==typeof t||"string"==typeof t||"symbol"==typeof t||void 0===t}function T(t){return Object.prototype.toString.call(t)}function C(t,e){return Object.prototype.hasOwnProperty.call(t,e)}var B=/%[sdj%]/g;e.format=function(t){if(!_(t)){for(var e=[],n=0;n=o)return t;switch(t){case"%s":return String(r[n++]);case"%d":return Number(r[n++]);case"%j":try{return JSON.stringify(r[n++])}catch(t){return"[Circular]"}default:return t}}),a=r[n];n9?t:"0"+t}function i(){var t=new Date;return t.getUTCFullYear()+""+r(t.getUTCMonth()+1)+r(t.getUTCDate())+"T"+r(t.getUTCHours())+r(t.getUTCMinutes())+r(t.getUTCSeconds())+"Z"}function o(t){return t.substring(0,t.indexOf("T"))}function s(t,e,n,r){var i=v.HmacSHA256(e,"AWS4"+t,{asBytes:!0}),o=v.HmacSHA256(n,i,{asBytes:!0}),s=v.HmacSHA256(r,o,{asBytes:!0});return v.HmacSHA256("aws4_request",s,{asBytes:!0})}function a(t,e,n,r,i,o,a,c,u,h,f,l,p,d){var g="host:"+n.toLowerCase()+"\n",b=t+"\n"+r+"\n"+i+"\n"+g+"\nhost\n"+v.SHA256(h,{asBytes:!0}),_=v.SHA256(b,{asBytes:!0}),m="AWS4-HMAC-SHA256\n"+l+"\n"+f+"/"+c+"/"+u+"/aws4_request\n"+_,w=s(a,f,c,u),S=v.HmacSHA256(m,w,{asBytes:!0}),E=i+"&X-Amz-Signature="+S;y(d)||(E+="&X-Amz-Security-Token="+encodeURIComponent(d));var k=e+n+r+"?"+E;return k}function c(t,e,n,r){var s=i(),c=o(s),u="X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential="+e+"%2F"+c+"%2F"+t.region+"%2Fiotdevicegateway%2Faws4_request&X-Amz-Date="+s+"&X-Amz-SignedHeaders=host",h=t.host;return y(t.port)||443===t.port||(h=t.host+":"+t.port),a("GET","wss://",h,"/mqtt",u,e,n,t.region,"iotdevicegateway","",c,s,t.debug,r)}function u(t){var e=t.host;return y(t.port)||443===t.port||(e=t.host+":"+t.port),"wss://"+e+"/mqtt"}function h(t,e){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.call(this,t[n],parseInt(n,10))}function f(t){var e={},n={};return h(t.split(/\r?\n/),function(t){t=t.split(/(^|\s)[;#]/)[0];var r=t.match(/^\s*\[([^\[\]]+)\]\s*$/);if(r)n=r[1];else if(n){var i=t.match(/^\s*(.+?)\s*=\s*(.+?)\s*$/);i&&(e[n]=e[n]||{},e[n][i[1]]=i[2])}}),e}function l(t){function r(t,e){0===x.filter(function(e){return e.topic===t}).length&&x.push({topic:t,options:e})}function i(t,e){var n=x.filter(function(e){return e.topic!==t});x=n}function o(t,e,n){var o=null;!1!==T&&("subscribe"===t?o=r:"unsubscribe"===t&&(o=i),"[object Array]"===Object.prototype.toString.call(e)?e.forEach(function(t,e,r){o(t,n)}):o(e,n))}function s(){return"inactive"===P}function a(e){var n=t.protocol;if("wss"===n){var r;r=""===O||""===R?"wss://no-credentials-available":c(t,O,R,M),t.debug,t.url=r}else"wss-custom-auth"===n&&(t.url=u(t),t.debug,n="wss");return G[n](e,t)}function h(){B=j,X.options.reconnectPeriod=B,H=null,P="stable"}function p(){var t=!0;return k>0&&S.length>=k&&("oldest"===I?S.shift():t=!1),t}function d(){var t=C.shift();if(y(t)){var e=A.shift();if(y(e)){var n=S.shift();y(n)||X.publish(n.topic,n.message,n.options,n.callback),0===S.length&&(clearInterval(N),N=null)}else o(e.type,e.topics,e.options),"subscribe"===e.type?y(e.callback)?X.subscribe(e.topics,e.options):X.subscribe(e.topics,e.options,e.callback):"unsubscribe"===e.type&&X.unsubscribe(e.topics,e.callback)}else y(t.callback)?X.subscribe(t.topic,t.options):X.subscribe(t.topic,t.options,t.callback)}if(!(this instanceof l))return new l(t);var v=this,S=[],E=!0,k=0,I="oldest";S.length=0;var A=[];A.length=0;var x=[],T=!0;x.length=0;var C=[];C.length=0;var B,O,R,M,P="inactive",N=null,L=250,j=1e3,D=2e4,U=128e3,H=null,q=n(50),z=q.version,F="?SDK=JavaScript&Version="+z;if(y(t)||0===Object.keys(t).length)throw new Error(b.INVALID_CONNECT_OPTIONS);if(y(t.keepalive)&&(t.keepalive=300),(y(t.enableMetrics)||!0===t.enableMetrics)&&(y(t.username)?t.username=F:t.username+=F),y(t.baseReconnectTimeMs)||(j=t.baseReconnectTimeMs),y(t.minimumConnectionTimeMs)||(D=t.minimumConnectionTimeMs),y(t.maximumReconnectTimeMs)||(U=t.maximumReconnectTimeMs),y(t.drainTimeMs)||(L=t.drainTimeMs),y(t.autoResubscribe)||(T=t.autoResubscribe),y(t.offlineQueueing)||(E=t.offlineQueueing),y(t.offlineQueueMaxSize)||(k=t.offlineQueueMaxSize),y(t.offlineQueueDropBehavior)||(I=t.offlineQueueDropBehavior),B=j,t.reconnectPeriod=B,t.fastDisconnectDetection=!0,t.resubscribe=!1,t.baseReconnectTimeMs<=0)throw new Error(b.INVALID_RECONNECT_TIMING);if(Ur&&(e=t.finalize(e)),e.clamp();for(var i=this._oKey=e.clone(),s=this._iKey=e.clone(),a=i.words,c=s.words,u=0;u>>31}var f=(r<<5|r>>>27)+c+s[u];f+=u<20?1518500249+(i&o|~i&a):u<40?1859775393+(i^o^a):u<60?(i&o|i&a|o&a)-1894007588:(i^o^a)-899497514,c=a,a=o,o=i<<30|i>>>2,i=r,r=f}n[0]=n[0]+r|0,n[1]=n[1]+i|0,n[2]=n[2]+o|0,n[3]=n[3]+a|0,n[4]=n[4]+c|0},_doFinalize:function(){var t=this._data,e=t.words,n=8*this._nDataBytes,r=8*t.sigBytes;return e[r>>>5]|=128<<24-r%32,e[14+(r+64>>>9<<4)]=Math.floor(n/4294967296),e[15+(r+64>>>9<<4)]=n,t.sigBytes=4*e.length,this._process(),this._hash},clone:function(){var t=i.clone.call(this);return t._hash=this._hash.clone(),t}});e.SHA1=i._createHelper(a),e.HmacSHA1=i._createHmacHelper(a)}(),t.SHA1})},function(t,e,n){"use strict";function r(t,e){function n(n){e.rejectUnauthorized&&t.emit("error",n),r.end()}var r;return e.port=e.port||8883,e.host=e.hostname||e.host||"localhost",e.rejectUnauthorized=!1!==e.rejectUnauthorized,delete e.path,r=i.connect(e),r.on("secureConnect",function(){e.rejectUnauthorized&&!r.authorized?r.emit("error",new Error("TLS not authorized")):r.removeListener("error",n)}),r.on("error",n),r}var i=n(110);t.exports=r},function(t,e){},function(t,e,n){"use strict";function r(){this.protocol=null,this.slashes=null,this.auth=null,this.host=null,this.port=null,this.hostname=null,this.hash=null,this.search=null,this.query=null,this.pathname=null,this.path=null,this.href=null}function i(t,e,n){if(t&&u.isObject(t)&&t instanceof r)return t;var i=new r;return i.parse(t,e,n),i}function o(t){return u.isString(t)&&(t=i(t)),t instanceof r?t.format():r.prototype.format.call(t)}function s(t,e){return i(t,!1,!0).resolve(e)}function a(t,e){return t?i(t,!1,!0).resolveObject(e):e}var c=n(91),u=n(102);e.parse=i,e.resolve=s,e.resolveObject=a,e.format=o,e.Url=r;var h=/^([a-z0-9.+-]+:)/i,f=/:[0-9]*$/,l=/^(\/\/?(?!\/)[^\?\s]*)(\?[^\s]*)?$/,p=["<",">",'"',"`"," ","\r","\n","\t"],d=["{","}","|","\\","^","`"].concat(p),g=["'"].concat(d),v=["%","/","?",";","#"].concat(g),b=["/","?","#"],y=/^[+a-z0-9A-Z_-]{0,63}$/,_=/^([+a-z0-9A-Z_-]{0,63})(.*)$/,m={javascript:!0,"javascript:":!0},w={javascript:!0,"javascript:":!0},S={http:!0,https:!0,ftp:!0,gopher:!0,file:!0,"http:":!0,"https:":!0,"ftp:":!0,"gopher:":!0,"file:":!0},E=n(94);r.prototype.parse=function(t,e,n){if(!u.isString(t))throw new TypeError("Parameter 'url' must be a string, not "+typeof t);var r=t.indexOf("?"),i=-1!==r&&r127?P+="x":P+=M[N];if(!P.match(y)){var j=O.slice(0,A),D=O.slice(A+1),U=M.match(_);U&&(j.push(U[1]),D.unshift(U[2])),D.length&&(a="/"+D.join(".")+a),this.hostname=j.join(".");break}}}this.hostname.length>255?this.hostname="":this.hostname=this.hostname.toLowerCase(),B||(this.hostname=c.toASCII(this.hostname));var H=this.port?":"+this.port:"",q=this.hostname||"";this.host=q+H,this.href+=this.host,B&&(this.hostname=this.hostname.substr(1,this.hostname.length-2),"/"!==a[0]&&(a="/"+a))}if(!m[d])for(var A=0,R=g.length;A0)&&n.host.split("@");I&&(n.auth=I.shift(),n.host=n.hostname=I.shift())}return n.search=t.search,n.query=t.query,u.isNull(n.pathname)&&u.isNull(n.search)||(n.path=(n.pathname?n.pathname:"")+(n.search?n.search:"")),n.href=n.format(),n}if(!E.length)return n.pathname=null,n.search?n.path="/"+n.search:n.path=null,n.href=n.format(),n;for(var A=E.slice(-1)[0],x=(n.host||t.host||E.length>1)&&("."===A||".."===A)||""===A,T=0,C=E.length;C>=0;C--)A=E[C],"."===A?E.splice(C,1):".."===A?(E.splice(C,1),T++):T&&(E.splice(C,1),T--);if(!_&&!m)for(;T--;T)E.unshift("..");!_||""===E[0]||E[0]&&"/"===E[0].charAt(0)||E.unshift(""),x&&"/"!==E.join("/").substr(-1)&&E.push("");var B=""===E[0]||E[0]&&"/"===E[0].charAt(0);if(k){n.hostname=n.host=B?"":E.length?E.shift():"";var I=!!(n.host&&n.host.indexOf("@")>0)&&n.host.split("@");I&&(n.auth=I.shift(),n.host=n.hostname=I.shift())}return _=_||n.host&&E.length,_&&!B&&E.unshift(""),E.length?n.pathname=E.join("/"):(n.pathname=null,n.path=null),u.isNull(n.pathname)&&u.isNull(n.search)||(n.path=(n.pathname?n.pathname:"")+(n.search?n.search:"")),n.auth=t.auth||n.auth,n.slashes=n.slashes||t.slashes,n.href=n.format(),n},r.prototype.parseHost=function(){var t=this.host,e=f.exec(t);e&&(e=e[0],":"!==e&&(this.port=e.substr(1)),t=t.substr(0,t.length-e.length)),t&&(this.hostname=t)}},function(t,e,n){"use strict";(function(e,r){function i(t,n,r){var i=new s({objectMode:t.objectMode});return i._write=n,i._flush=r,i._destroy=function(t,n){var r=this;this.push(null),this.end(),e.nextTick(function(){n(t),r.emit("close")})},i}function o(t,n,o){function s(t,e,n){if(_.readyState!==_.OPEN)return void n();A&&"string"==typeof t&&(t=new u(t,"utf8")),_.send(t,n)}function h(t,e,n){if(_.bufferedAmount>k)return void setTimeout(h,I,t,e,n);A&&"string"==typeof t&&(t=new u(t,"utf8"));try{_.send(t)}catch(t){return n(t)}n()}function f(t){_.close(),t()}function l(){y.setReadable(E),y.setWritable(E),y.emit("connect")}function p(){y.end(),y.destroy()}function d(t){y.destroy(t)}function g(t){var e=t.data;e=e instanceof ArrayBuffer?u.from(e):u.from(e,"utf8"),E.push(e)}function v(){_.close()}function b(t,e){for(var n=new Array(t.length),r=0;r>>7)^(d<<14|d>>>18)^d>>>3,v=u[p-2],b=(v<<15|v>>>17)^(v<<13|v>>>19)^v>>>10;u[p]=g+u[p-7]+b+u[p-16]}var y=a&h^~a&f,_=r&i^r&o^i&o,m=(r<<30|r>>>2)^(r<<19|r>>>13)^(r<<10|r>>>22),w=(a<<26|a>>>6)^(a<<21|a>>>11)^(a<<7|a>>>25),S=l+w+y+c[p]+u[p],E=m+_;l=f,f=h,h=a,a=s+S|0,s=o,o=i,i=r,r=S+E|0}n[0]=n[0]+r|0,n[1]=n[1]+i|0,n[2]=n[2]+o|0,n[3]=n[3]+s|0,n[4]=n[4]+a|0,n[5]=n[5]+h|0,n[6]=n[6]+f|0,n[7]=n[7]+l|0},_doFinalize:function(){var t=this._data,n=t.words,r=8*this._nDataBytes,i=8*t.sigBytes;return n[i>>>5]|=128<<24-i%32,n[14+(i+64>>>9<<4)]=e.floor(r/4294967296),n[15+(i+64>>>9<<4)]=r,t.sigBytes=4*n.length,this._process(),this._hash},clone:function(){var t=o.clone.call(this);return t._hash=this._hash.clone(),t}});n.SHA256=o._createHelper(h),n.HmacSHA256=o._createHmacHelper(h)}(Math),t.SHA256})},function(t,e,n){!function(r,i,o){t.exports=e=i(n(0),n(14))}(0,function(t){return function(){function e(){return s.create.apply(s,arguments)}var n=t,r=n.lib,i=r.Hasher,o=n.x64,s=o.Word,a=o.WordArray,c=n.algo,u=[e(1116352408,3609767458),e(1899447441,602891725),e(3049323471,3964484399),e(3921009573,2173295548),e(961987163,4081628472),e(1508970993,3053834265),e(2453635748,2937671579),e(2870763221,3664609560),e(3624381080,2734883394),e(310598401,1164996542),e(607225278,1323610764),e(1426881987,3590304994),e(1925078388,4068182383),e(2162078206,991336113),e(2614888103,633803317),e(3248222580,3479774868),e(3835390401,2666613458),e(4022224774,944711139),e(264347078,2341262773),e(604807628,2007800933),e(770255983,1495990901),e(1249150122,1856431235),e(1555081692,3175218132),e(1996064986,2198950837),e(2554220882,3999719339),e(2821834349,766784016),e(2952996808,2566594879),e(3210313671,3203337956),e(3336571891,1034457026),e(3584528711,2466948901),e(113926993,3758326383),e(338241895,168717936),e(666307205,1188179964),e(773529912,1546045734),e(1294757372,1522805485),e(1396182291,2643833823),e(1695183700,2343527390),e(1986661051,1014477480),e(2177026350,1206759142),e(2456956037,344077627),e(2730485921,1290863460),e(2820302411,3158454273),e(3259730800,3505952657),e(3345764771,106217008),e(3516065817,3606008344),e(3600352804,1432725776),e(4094571909,1467031594),e(275423344,851169720),e(430227734,3100823752),e(506948616,1363258195),e(659060556,3750685593),e(883997877,3785050280),e(958139571,3318307427),e(1322822218,3812723403),e(1537002063,2003034995),e(1747873779,3602036899),e(1955562222,1575990012),e(2024104815,1125592928),e(2227730452,2716904306),e(2361852424,442776044),e(2428436474,593698344),e(2756734187,3733110249),e(3204031479,2999351573),e(3329325298,3815920427),e(3391569614,3928383900),e(3515267271,566280711),e(3940187606,3454069534),e(4118630271,4000239992),e(116418474,1914138554),e(174292421,2731055270),e(289380356,3203993006),e(460393269,320620315),e(685471733,587496836),e(852142971,1086792851),e(1017036298,365543100),e(1126000580,2618297676),e(1288033470,3409855158),e(1501505948,4234509866),e(1607167915,987167468),e(1816402316,1246189591)],h=[];!function(){for(var t=0;t<80;t++)h[t]=e()}();var f=c.SHA512=i.extend({_doReset:function(){this._hash=new a.init([new s.init(1779033703,4089235720),new s.init(3144134277,2227873595),new s.init(1013904242,4271175723),new s.init(2773480762,1595750129),new s.init(1359893119,2917565137),new s.init(2600822924,725511199),new s.init(528734635,4215389547),new s.init(1541459225,327033209)])},_doProcessBlock:function(t,e){for(var n=this._hash.words,r=n[0],i=n[1],o=n[2],s=n[3],a=n[4],c=n[5],f=n[6],l=n[7],p=r.high,d=r.low,g=i.high,v=i.low,b=o.high,y=o.low,_=s.high,m=s.low,w=a.high,S=a.low,E=c.high,k=c.low,I=f.high,A=f.low,x=l.high,T=l.low,C=p,B=d,O=g,R=v,M=b,P=y,N=_,L=m,j=w,D=S,U=E,H=k,q=I,z=A,F=x,W=T,K=0;K<80;K++){var Y=h[K];if(K<16)var V=Y.high=0|t[e+2*K],Q=Y.low=0|t[e+2*K+1];else{var $=h[K-15],G=$.high,X=$.low,J=(G>>>1|X<<31)^(G>>>8|X<<24)^G>>>7,Z=(X>>>1|G<<31)^(X>>>8|G<<24)^(X>>>7|G<<25),tt=h[K-2],et=tt.high,nt=tt.low,rt=(et>>>19|nt<<13)^(et<<3|nt>>>29)^et>>>6,it=(nt>>>19|et<<13)^(nt<<3|et>>>29)^(nt>>>6|et<<26),ot=h[K-7],st=ot.high,at=ot.low,ct=h[K-16],ut=ct.high,ht=ct.low,Q=Z+at,V=J+st+(Q>>>0>>0?1:0),Q=Q+it,V=V+rt+(Q>>>0>>0?1:0),Q=Q+ht,V=V+ut+(Q>>>0>>0?1:0);Y.high=V,Y.low=Q}var ft=j&U^~j&q,lt=D&H^~D&z,pt=C&O^C&M^O&M,dt=B&R^B&P^R&P,gt=(C>>>28|B<<4)^(C<<30|B>>>2)^(C<<25|B>>>7),vt=(B>>>28|C<<4)^(B<<30|C>>>2)^(B<<25|C>>>7),bt=(j>>>14|D<<18)^(j>>>18|D<<14)^(j<<23|D>>>9),yt=(D>>>14|j<<18)^(D>>>18|j<<14)^(D<<23|j>>>9),_t=u[K],mt=_t.high,wt=_t.low,St=W+yt,Et=F+bt+(St>>>0>>0?1:0),St=St+lt,Et=Et+ft+(St>>>0>>0?1:0),St=St+wt,Et=Et+mt+(St>>>0>>0?1:0),St=St+Q,Et=Et+V+(St>>>0>>0?1:0),kt=vt+dt,It=gt+pt+(kt>>>0>>0?1:0);F=q,W=z,q=U,z=H,U=j,H=D,D=L+St|0,j=N+Et+(D>>>0>>0?1:0)|0,N=M,L=P,M=O,P=R,O=C,R=B,B=St+kt|0,C=Et+It+(B>>>0>>0?1:0)|0}d=r.low=d+B,r.high=p+C+(d>>>0>>0?1:0),v=i.low=v+R,i.high=g+O+(v>>>0>>0?1:0),y=o.low=y+P,o.high=b+M+(y>>>0

>>0?1:0),m=s.low=m+L,s.high=_+N+(m>>>0>>0?1:0),S=a.low=S+D,a.high=w+j+(S>>>0>>0?1:0),k=c.low=k+H,c.high=E+U+(k>>>0>>0?1:0),A=f.low=A+z,f.high=I+q+(A>>>0>>0?1:0),T=l.low=T+W,l.high=x+F+(T>>>0>>0?1:0)},_doFinalize:function(){var t=this._data,e=t.words,n=8*this._nDataBytes,r=8*t.sigBytes;return e[r>>>5]|=128<<24-r%32,e[30+(r+128>>>10<<5)]=Math.floor(n/4294967296),e[31+(r+128>>>10<<5)]=n,t.sigBytes=4*e.length,this._process(),this._hash.toX32()},clone:function(){var t=i.clone.call(this);return t._hash=this._hash.clone(),t},blockSize:32});n.SHA512=i._createHelper(f),n.HmacSHA512=i._createHmacHelper(f)}(),t.SHA512})},function(t,e,n){var r=n(89),i=function(){},o=function(t){return t.setHeader&&"function"==typeof t.abort},s=function(t){return t.stdio&&Array.isArray(t.stdio)&&3===t.stdio.length},a=function(t,e,n){if("function"==typeof e)return a(t,null,e);e||(e={}),n=r(n||i);var c=t._writableState,u=t._readableState,h=e.readable||!1!==e.readable&&t.readable,f=e.writable||!1!==e.writable&&t.writable,l=function(){t.writable||p()},p=function(){f=!1,h||n.call(t)},d=function(){h=!1,f||n.call(t)},g=function(e){n.call(t,e?new Error("exited with error code: "+e):null)},v=function(e){n.call(t,e)},b=function(){return(!h||u&&u.ended)&&(!f||c&&c.ended)?void 0:n.call(t,new Error("premature close"))},y=function(){t.req.on("finish",p)};return o(t)?(t.on("complete",p),t.on("abort",b),t.req?y():t.on("request",y)):f&&!c&&(t.on("end",l),t.on("close",l)),s(t)&&t.on("exit",g),t.on("end",d),t.on("finish",p),!1!==e.error&&t.on("error",v),t.on("close",b),function(){t.removeListener("complete",p),t.removeListener("abort",b),t.removeListener("request",y),t.req&&t.req.removeListener("finish",p),t.removeListener("end",l),t.removeListener("close",l),t.removeListener("finish",p),t.removeListener("exit",g),t.removeListener("end",d),t.removeListener("error",v),t.removeListener("close",b)}};t.exports=a},function(t,e){var n={}.toString;t.exports=Array.isArray||function(t){return"[object Array]"==n.call(t)}},function(t,e,n){"use strict";function r(t){return[0,1,2].map(function(e){return[0,1].map(function(n){return[0,1].map(function(r){var s=new i(1);return s.writeUInt8(o.codes[t]<65535||a%1!=0)return e.emit("error",new Error("Invalid keepalive")),!1;if(f+=2,f+=1,o){if("object"!=typeof o)return e.emit("error",new Error("Invalid will")),!1;if(!o.topic||"string"!=typeof o.topic)return e.emit("error",new Error("Invalid will topic")),!1;if(f+=S.byteLength(o.topic)+2,o.payload&&o.payload){if(!(o.payload.length>=0))return e.emit("error",new Error("Invalid will payload")),!1;"string"==typeof o.payload?f+=S.byteLength(o.payload)+2:f+=o.payload.length+2}else f+=2}if(u){if(!u.length)return e.emit("error",new Error("Invalid username")),!1;f+=S.byteLength(u)+2}if(h){if(!h.length)return e.emit("error",new Error("Invalid password")),!1;f+=m(h)+2}e.write(w.CONNECT_HEADER),g(e,f),_(e,r),e.write(4===i?w.VERSION4:w.VERSION3);var l=0;return l|=u?w.USERNAME_MASK:0,l|=h?w.PASSWORD_MASK:0,l|=o&&o.retain?w.WILL_RETAIN_MASK:0,l|=o&&o.qos?o.qos<0&&B(e,a),e.write(s))}function c(t,e){var n=t||{},r=n.cmd||"puback",i=n.messageId,o=n.dup&&"pubrel"===r?w.DUP_MASK:0,s=0;return"pubrel"===r&&(s=1),"number"!=typeof i?(e.emit("error",new Error("Invalid messageId")),!1):(e.write(w.ACKS[r][s][o][0]),g(e,2),B(e,i))}function u(t,e){var n=t||{},r=n.dup?w.DUP_MASK:0,i=n.messageId,o=n.subscriptions,s=0;if("number"!=typeof i)return e.emit("error",new Error("Invalid messageId")),!1;if(s+=2,"object"!=typeof o||!o.length)return e.emit("error",new Error("Invalid subscriptions")),!1;for(var a=0;a=0&&t<128?1:t>=128&&t<16384?2:t>=16384&&t<2097152?3:t>=2097152&&t<268435456?4:0}function d(t){var e=0,n=0,r=S.allocUnsafe(p(t));do{e=t%128|0,t=t/128|0,t>0&&(e|=128),r.writeUInt8(e,n++,!0)}while(t>0);return r}function g(t,e){var n=R[e];n||(n=d(e),e<16384&&(R[e]=n)),t.write(n)}function v(t,e){var n=S.byteLength(e);B(t,n),t.write(e,"utf8")}function b(t,e){return t.write(x[e])}function y(t,e){return t.write(T(e))}function _(t,e){e&&"string"==typeof e?v(t,e):e?(B(t,e.length),t.write(e)):B(t,0)}function m(t){return t?S.isBuffer(t)?t.length:S.byteLength(t):0}var w=n(30),S=n(5).Buffer,E=S.allocUnsafe(0),k=S.from([0]),I=n(83),A=n(82),x=I.cache,T=I.generateNumber,C=I.generateCache,B=b,O=!0;Object.defineProperty(r,"cacheNumbers",{get:function(){return B===b},set:function(t){t?(x&&0!==Object.keys(x).length||(O=!0),B=b):(O=!1,B=y)}});var R={};t.exports=r},function(t,e,n){"use strict";function r(t,e){var n,r;return e.port=e.port||1883,e.hostname=e.hostname||e.host||"localhost",n=e.port,r=e.hostname,i.createConnection(n,r)}var i=n(109);t.exports=r},function(t,e,n){"use strict";(function(e){function r(t,e){var n=t.protocol+"://"+t.hostname+":"+t.port+t.path;return"function"==typeof t.transformWsUrl&&(n=t.transformWsUrl(n,t,e)),n}function i(t){t.hostname||(t.hostname="localhost"),t.port||("wss"===t.protocol?t.port=443:t.port=80),t.path||(t.path="/"),t.wsOptions||(t.wsOptions={}),f||"wss"!==t.protocol||h.forEach(function(e){t.hasOwnProperty(e)&&!t.wsOptions.hasOwnProperty(e)&&(t.wsOptions[e]=t[e])})}function o(t,e){var n="MQIsdp"===e.protocolId&&3===e.protocolVersion?"mqttv3.1":"mqtt";i(e);var o=r(e,t);return c(o,[n],e.wsOptions)}function s(t,e){return o(t,e)}function a(t,e){if(e.hostname||(e.hostname=e.host),!e.hostname){if("undefined"==typeof document)throw new Error("Could not determine host. Specify host manually.");var n=u.parse(document.URL);e.hostname=n.hostname,e.port||(e.port=n.port)}return o(t,e)}var c=n(24),u=n(23),h=["rejectUnauthorized","ca","cert","key","pfx","passphrase"],f="browser"===e.title;t.exports=f?a:s}).call(e,n(2))},function(t,e,n){"use strict";function r(t){u?wx.sendSocketMessage({data:t}):h.push(t)}function i(t,e){var n={OPEN:1,CLOSING:2,CLOSED:3,readyState:u?1:0,send:r,close:wx.closeSocket,onopen:null,onmessage:null,onclose:null,onerror:null};return wx.connectSocket({url:t,protocols:e}),wx.onSocketOpen(function(t){n.readyState=n.OPEN,u=!0;for(var e=0;e0?("string"==typeof e||s.objectMode||Object.getPrototypeOf(e)===j.prototype||(e=i(e)),r?s.endEmitted?t.emit("error",new Error("stream.unshift() after end event")):h(t,s,e,!0):s.ended?t.emit("error",new Error("stream.push() after EOF")):(s.reading=!1,s.decoder&&!n?(e=s.decoder.write(e),s.objectMode||0!==e.length?h(t,s,e,!1):y(t,s)):h(t,s,e,!1))):r||(s.reading=!1)}return l(s)}function h(t,e,n,r){e.flowing&&0===e.length&&!e.sync?(t.emit("data",n),t.read(0)):(e.length+=e.objectMode?1:n.length,r?e.buffer.unshift(n):e.buffer.push(n),e.needReadable&&v(t)),y(t,e)}function f(t,e){var n;return o(e)||"string"==typeof e||void 0===e||t.objectMode||(n=new TypeError("Invalid non-string/buffer chunk")),n}function l(t){return!t.ended&&(t.needReadable||t.length=Y?t=Y:(t--,t|=t>>>1,t|=t>>>2,t|=t>>>4,t|=t>>>8,t|=t>>>16,t++),t}function d(t,e){return t<=0||0===e.length&&e.ended?0:e.objectMode?1:t!==t?e.flowing&&e.length?e.buffer.head.data.length:e.length:(t>e.highWaterMark&&(e.highWaterMark=p(t)),t<=e.length?t:e.ended?e.length:(e.needReadable=!0,0))}function g(t,e){if(!e.ended){if(e.decoder){var n=e.decoder.end();n&&n.length&&(e.buffer.push(n),e.length+=e.objectMode?1:n.length)}e.ended=!0,v(t)}}function v(t){var e=t._readableState;e.needReadable=!1,e.emittedReadable||(q("emitReadable",e.flowing),e.emittedReadable=!0,e.sync?R(b,t):b(t))}function b(t){q("emit readable"),t.emit("readable"),k(t)}function y(t,e){e.readingMore||(e.readingMore=!0,R(_,t,e))}function _(t,e){for(var n=e.length;!e.reading&&!e.flowing&&!e.ended&&e.length=e.length?(n=e.decoder?e.buffer.join(""):1===e.buffer.length?e.buffer.head.data:e.buffer.concat(e.length),e.buffer.clear()):n=A(t,e.buffer,e.decoder),n}function A(t,e,n){var r;return to.length?o.length:t;if(s===o.length?i+=o:i+=o.slice(0,t),0===(t-=s)){s===o.length?(++r,n.next?e.head=n.next:e.head=e.tail=null):(e.head=n,n.data=o.slice(s));break}++r}return e.length-=r,i}function T(t,e){var n=j.allocUnsafe(t),r=e.head,i=1;for(r.data.copy(n),t-=r.data.length;r=r.next;){var o=r.data,s=t>o.length?o.length:t;if(o.copy(n,n.length-t,0,s),0===(t-=s)){s===o.length?(++i,r.next?e.head=r.next:e.head=e.tail=null):(e.head=r,r.data=o.slice(s));break}++i}return e.length-=i,n}function C(t){var e=t._readableState;if(e.length>0)throw new Error('"endReadable()" called on non-empty stream');e.endEmitted||(e.ended=!0,R(B,e,t))}function B(t,e){t.endEmitted||0!==t.length||(t.endEmitted=!0,e.readable=!1,e.emit("end"))}function O(t,e){for(var n=0,r=t.length;n=e.highWaterMark||e.ended))return q("read: emitReadable",e.length,e.ended),0===e.length&&e.ended?C(this):v(this),null;if(0===(t=d(t,e))&&e.ended)return 0===e.length&&C(this),null;var r=e.needReadable;q("need readable",r),(0===e.length||e.length-t0?I(t,e):null,null===i?(e.needReadable=!0,t=0):e.length-=t,0===e.length&&(e.ended||(e.needReadable=!0),n!==t&&e.ended&&C(this)),null!==i&&this.emit("data",i),i},c.prototype._read=function(t){this.emit("error",new Error("_read() is not implemented"))},c.prototype.pipe=function(t,e){function n(t,e){q("onunpipe"),t===l&&e&&!1===e.hasUnpiped&&(e.hasUnpiped=!0,o())}function i(){q("onend"),t.end()}function o(){q("cleanup"),t.removeListener("close",u),t.removeListener("finish",h),t.removeListener("drain",v),t.removeListener("error",c),t.removeListener("unpipe",n),l.removeListener("end",i),l.removeListener("end",f),l.removeListener("data",a),b=!0,!p.awaitDrain||t._writableState&&!t._writableState.needDrain||v()}function a(e){q("ondata"),y=!1,!1!==t.write(e)||y||((1===p.pipesCount&&p.pipes===t||p.pipesCount>1&&-1!==O(p.pipes,t))&&!b&&(q("false write response, pause",l._readableState.awaitDrain),l._readableState.awaitDrain++,y=!0),l.pause())}function c(e){q("onerror",e),f(),t.removeListener("error",c),0===N(t,"error")&&t.emit("error",e)}function u(){t.removeListener("finish",h),f()}function h(){q("onfinish"),t.removeListener("close",u),f()}function f(){q("unpipe"),l.unpipe(t)}var l=this,p=this._readableState;switch(p.pipesCount){case 0:p.pipes=t;break;case 1:p.pipes=[p.pipes,t];break;default:p.pipes.push(t)}p.pipesCount+=1,q("pipe count=%d opts=%j",p.pipesCount,e);var d=(!e||!1!==e.end)&&t!==r.stdout&&t!==r.stderr,g=d?i:f;p.endEmitted?R(g):l.once("end",g),t.on("unpipe",n);var v=m(l);t.on("drain",v);var b=!1,y=!1;return l.on("data",a),s(t,"error",c),t.once("close",u),t.once("finish",h),t.emit("pipe",l),p.flowing||(q("pipe resume"),l.resume()),t},c.prototype.unpipe=function(t){var e=this._readableState,n={hasUnpiped:!1};if(0===e.pipesCount)return this;if(1===e.pipesCount)return t&&t!==e.pipes?this:(t||(t=e.pipes),e.pipes=null,e.pipesCount=0,e.flowing=!1,t&&t.emit("unpipe",this,n),this);if(!t){var r=e.pipes,i=e.pipesCount;e.pipes=null,e.pipesCount=0,e.flowing=!1;for(var o=0;o-1?r:T;h.WritableState=u;var O=n(12);O.inherits=n(4);var R={deprecate:n(103)},M=n(40),P=n(5).Buffer,N=i.Uint8Array||function(){},L=n(39);O.inherits(h,M),u.prototype.getBuffer=function(){for(var t=this.bufferedRequest,e=[];t;)e.push(t),t=t.next;return e},function(){try{Object.defineProperty(u.prototype,"buffer",{get:R.deprecate(function(){return this.getBuffer()},"_writableState.buffer is deprecated. Use _writableState.getBuffer instead.","DEP0003")})}catch(t){}}();var j;"function"==typeof Symbol&&Symbol.hasInstance&&"function"==typeof Function.prototype[Symbol.hasInstance]?(j=Function.prototype[Symbol.hasInstance],Object.defineProperty(h,Symbol.hasInstance,{value:function(t){return!!j.call(this,t)||this===h&&(t&&t._writableState instanceof u)}})):j=function(t){return t instanceof this},h.prototype.pipe=function(){this.emit("error",new Error("Cannot pipe, not readable"))},h.prototype.write=function(t,e,n){var r=this._writableState,i=!1,o=!r.objectMode&&a(t);return o&&!P.isBuffer(t)&&(t=s(t)),"function"==typeof e&&(n=e,e=null),o?e="buffer":e||(e=r.defaultEncoding),"function"!=typeof n&&(n=c),r.ended?f(this,n):(o||l(this,r,t,n))&&(r.pendingcb++,i=d(this,r,o,t,e,n)),i},h.prototype.cork=function(){this._writableState.corked++},h.prototype.uncork=function(){var t=this._writableState;t.corked&&(t.corked--,t.writing||t.corked||t.finished||t.bufferProcessing||!t.bufferedRequest||w(this,t))},h.prototype.setDefaultEncoding=function(t){if("string"==typeof t&&(t=t.toLowerCase()),!(["hex","utf8","utf-8","ascii","binary","base64","ucs2","ucs-2","utf16le","utf-16le","raw"].indexOf((t+"").toLowerCase())>-1))throw new TypeError("Unknown encoding: "+t);return this._writableState.defaultEncoding=t,this},h.prototype._write=function(t,e,n){n(new Error("_write() is not implemented"))},h.prototype._writev=null,h.prototype.end=function(t,e,n){var r=this._writableState;"function"==typeof t?(n=t,t=null,e=null):"function"==typeof e&&(n=e,e=null),null!==t&&void 0!==t&&this.write(t,e),r.corked&&(r.corked=1,this.uncork()),r.ending||r.finished||A(this,r,n)},Object.defineProperty(h.prototype,"destroyed",{get:function(){return void 0!==this._writableState&&this._writableState.destroyed},set:function(t){this._writableState&&(this._writableState.destroyed=t)}}),h.prototype.destroy=L.destroy,h.prototype._undestroy=L.undestroy,h.prototype._destroy=function(t,e){this.end(),e(t)}}).call(e,n(2),n(101).setImmediate,n(3))},function(t,e,n){"use strict";function r(t,e){var n=this,r=this._readableState&&this._readableState.destroyed,i=this._writableState&&this._writableState.destroyed;return r||i?(e?e(t):!t||this._writableState&&this._writableState.errorEmitted||s(o,this,t),this):(this._readableState&&(this._readableState.destroyed=!0),this._writableState&&(this._writableState.destroyed=!0),this._destroy(t||null,function(t){!e&&t?(s(o,n,t),n._writableState&&(n._writableState.errorEmitted=!0)):e&&e(t)}),this)}function i(){this._readableState&&(this._readableState.destroyed=!1,this._readableState.reading=!1,this._readableState.ended=!1,this._readableState.endEmitted=!1),this._writableState&&(this._writableState.destroyed=!1,this._writableState.ended=!1,this._writableState.ending=!1,this._writableState.finished=!1,this._writableState.errorEmitted=!1)}function o(t,e){t.emit("error",e)}var s=n(15).nextTick;t.exports={destroy:r,undestroy:i}},function(t,e,n){t.exports=n(6).EventEmitter},function(t,e,n){"use strict";function r(t){if(!t)return"utf8";for(var e;;)switch(t){case"utf8":case"utf-8":return"utf8";case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return"utf16le";case"latin1":case"binary":return"latin1";case"base64":case"ascii":case"hex":return t;default:if(e)return;t=(""+t).toLowerCase(),e=!0}}function i(t){var e=r(t);if("string"!=typeof e&&(y.isEncoding===_||!_(t)))throw new Error("Unknown encoding: "+t);return e||t}function o(t){this.encoding=i(t);var e;switch(this.encoding){case"utf16le":this.text=l,this.end=p,e=4;break;case"utf8":this.fillLast=u,e=4;break;case"base64":this.text=d,this.end=g,e=3;break;default:return this.write=v,void(this.end=b)}this.lastNeed=0,this.lastTotal=0,this.lastChar=y.allocUnsafe(e)}function s(t){return t<=127?0:t>>5==6?2:t>>4==14?3:t>>3==30?4:-1}function a(t,e,n){var r=e.length-1;if(r=0?(i>0&&(t.lastNeed=i-1),i):--r=0?(i>0&&(t.lastNeed=i-2),i):--r=0?(i>0&&(2===i?i=0:t.lastNeed=i-3),i):0)}function c(t,e,n){if(128!=(192&e[0]))return t.lastNeed=0,"�".repeat(n);if(t.lastNeed>1&&e.length>1){if(128!=(192&e[1]))return t.lastNeed=1,"�".repeat(n+1);if(t.lastNeed>2&&e.length>2&&128!=(192&e[2]))return t.lastNeed=2,"�".repeat(n+2)}}function u(t){var e=this.lastTotal-this.lastNeed,n=c(this,t,e);return void 0!==n?n:this.lastNeed<=t.length?(t.copy(this.lastChar,e,0,this.lastNeed),this.lastChar.toString(this.encoding,0,this.lastTotal)):(t.copy(this.lastChar,e,0,t.length),void(this.lastNeed-=t.length))}function h(t,e){var n=a(this,t,e);if(!this.lastNeed)return t.toString("utf8",e);this.lastTotal=n;var r=t.length-(n-this.lastNeed);return t.copy(this.lastChar,0,r),t.toString("utf8",e,r)}function f(t){var e=t&&t.length?this.write(t):"";return this.lastNeed?e+"�".repeat(this.lastTotal-this.lastNeed):e}function l(t,e){if((t.length-e)%2==0){var n=t.toString("utf16le",e);if(n){var r=n.charCodeAt(n.length-1);if(r>=55296&&r<=56319)return this.lastNeed=2,this.lastTotal=4,this.lastChar[0]=t[t.length-2],this.lastChar[1]=t[t.length-1],n.slice(0,-1)}return n}return this.lastNeed=1,this.lastTotal=2,this.lastChar[0]=t[t.length-1],t.toString("utf16le",e,t.length-1)}function p(t){var e=t&&t.length?this.write(t):"";if(this.lastNeed){var n=this.lastTotal-this.lastNeed;return e+this.lastChar.toString("utf16le",0,n)}return e}function d(t,e){var n=(t.length-e)%3;return 0===n?t.toString("base64",e):(this.lastNeed=3-n,this.lastTotal=3,1===n?this.lastChar[0]=t[t.length-1]:(this.lastChar[0]=t[t.length-2],this.lastChar[1]=t[t.length-1]),t.toString("base64",e,t.length-n))}function g(t){var e=t&&t.length?this.write(t):"";return this.lastNeed?e+this.lastChar.toString("base64",0,3-this.lastNeed):e}function v(t){return t.toString(this.encoding)}function b(t){return t&&t.length?this.write(t):""}var y=n(5).Buffer,_=y.isEncoding||function(t){switch((t=""+t)&&t.toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":case"raw":return!0;default:return!1}};e.StringDecoder=o,o.prototype.write=function(t){if(0===t.length)return"";var e,n;if(this.lastNeed){if(void 0===(e=this.fillLast(t)))return"";n=this.lastNeed,this.lastNeed=0}else n=0;return n=4.0.0"},homepage:"https://github.com/aws/aws-iot-device-sdk-js",keywords:["api","amazon","aws","iot","mqtt"],license:"Apache-2.0",main:"index.js",name:"aws-iot-device-sdk",repository:{type:"git",url:"git://github.com/aws/aws-iot-device-sdk-js.git"},scripts:{beautify:"node ./node_modules/gulp/bin/gulp.js beautify",browserize:"./scripts/browserize.sh",test:"node ./node_modules/gulp/bin/gulp.js test --verbose"},version:"2.2.1"}},function(t,e,n){function r(t,e,n){return h(n)?"$aws/things/"+t+"/shadow/"+e:"$aws/things/"+t+"/shadow/"+e+"/"+n}function i(t){return"$aws/things/"===t.substring(0,12)}function o(t,e){var n=!1;return"$aws"===t[0]&&("things"!==t[1]||"shadow"!==t[3]||"update"!==t[4]&&"get"!==t[4]&&"delete"!==t[4]||("subscribe"===e?"accepted"!==t[5]&&"rejected"!==t[5]&&"delta"!==t[5]||6!==t.length||(n=!0):5===t.length&&(n=!0))),n}function s(t,e){if(!(this instanceof s))return new s(t,e);var n=this,c=[{}],f=0,l=1e4,p=!0,d=u.DeviceClient(t);h(e)||h(e.operationTimeout)||(l=e.operationTimeout),this._handleSubscriptions=function(t,e,n,i){for(var o=[],s=0,a=e.length;s0)return void i("Not all subscriptions were granted",n);i()}})):h(i)||g.push(i),d[n].apply(d,g)},this._handleMessages=function(e,n,r,i){var o={};try{o=JSON.parse(i.toString())}catch(e){return void t.debug}var s=o.clientToken,a=o.version;if(delete o.clientToken,!h(a)&&"rejected"!==r)if(h(c[e].version)||a>=c[e].version)c[e].version=a;else if("delete"!==n&&!0===c[e].discardStale)return void t.debug;return"delta"===r?void this.emit("delta",e,o):h(c[e].clientToken)||c[e].clientToken!==s?void("accepted"===r&&"get"!==n&&this.emit("foreignStateChange",e,n,o)):(clearTimeout(c[e].timeout),delete c[e].timeout,delete c[e].clientToken,c[e].pending=!1,!1===c[e].persistentSubscribe&&this._handleSubscriptions(e,[{operations:[n],statii:["accepted","rejected"]}],"unsubscribe"),void this.emit("status",e,r,s,o))},d.on("connect",function(){n.emit("connect")}),d.on("close",function(){n.emit("close")}),d.on("reconnect",function(){n.emit("reconnect")}),d.on("offline",function(){n.emit("offline")}),d.on("error",function(t){n.emit("error",t)}),d.on("packetsend",function(t){n.emit("packetsend",t)}),d.on("packetreceive",function(t){n.emit("packetreceive",t)}),d.on("message",function(t,e){if(!0===p){var r=t.split("/");o(r,"subscribe")?c.hasOwnProperty(r[2])&&n._handleMessages(r[2],r[4],r[5],e):n.emit("message",t,e)}}),this._thingOperation=function(e,i,o){var s=null;if(c.hasOwnProperty(e))if(!1===c[e].pending){c[e].pending=!0;var a;if(h(o.clientToken)){var u=t.clientId.length;a=u>48?t.clientId.substr(u-48)+"-"+f++:t.clientId+"-"+f++}else a=o.clientToken;c[e].clientToken=a;var p=r(e,i);c[e].timeout=setTimeout(function(t,e){!1===c[t].persistentSubscribe&&n._handleSubscriptions(t,[{operations:[i],statii:["accepted","rejected"]}],"unsubscribe"),c[t].pending=!1,n.emit("timeout",t,e),delete c[t].timeout,delete c[t].clientToken},l,e,a),!1===c[e].persistentSubscribe?this._handleSubscriptions(e,[{operations:[i],statii:["accepted","rejected"]}],"subscribe",function(t,n){h(t)&&h(n)&&(h(o)||(!h(c[e].version)&&c[e].enableVersioning&&(o.version=c[e].version),o.clientToken=a,d.publish(p,JSON.stringify(o),{qos:c[e].qos}),!h(c[e])&&c[e].debug))}):(!h(c[e].version)&&c[e].enableVersioning&&(o.version=c[e].version),o.clientToken=a,d.publish(p,JSON.stringify(o),{qos:c[e].qos}),c[e].debug),s=a}else t.debug;else t.debug;return s},this.register=function(e,n,r){if(c.hasOwnProperty(e))t.debug;else{var i=!1,o=[];c[e]={persistentSubscribe:!0,debug:!1,discardStale:!0,enableVersioning:!0,qos:0,pending:!0},"function"==typeof n&&(r=n,n=null),h(n)||(h(n.ignoreDeltas)||(i=n.ignoreDeltas),h(n.persistentSubscribe)||(c[e].persistentSubscribe=n.persistentSubscribe),h(n.debug)||(c[e].debug=n.debug),h(n.discardStale)||(c[e].discardStale=n.discardStale),h(n.enableVersioning)||(c[e].enableVersioning=n.enableVersioning),h(n.qos)||(c[e].qos=n.qos)),!1===i&&o.push({operations:["update"],statii:["delta"]}),!0===c[e].persistentSubscribe&&o.push({operations:["update","get","delete"],statii:["accepted","rejected"]}),o.length>0?this._handleSubscriptions(e,o,"subscribe",function(t,n){h(t)&&h(n)&&(c[e].pending=!1),h(r)||r(t,n)}):(c[e].pending=!1,h(r)||r())}},this.unregister=function(e){if(c.hasOwnProperty(e)){var n=[];n.push({operations:["update"],statii:["delta"]}),!0===c[e].persistentSubscribe&&n.push({operations:["update","get","delete"],statii:["accepted","rejected"]}),this._handleSubscriptions(e,n,"unsubscribe"),h(c[e].timeout)||clearTimeout(c[e].timeout),delete c[e]}else t.debug},this.update=function(t,e){var r=null;return h(e.version)&&(r=n._thingOperation(t,"update",e)),r},this.get=function(t,e){var r={};return h(e)||(r.clientToken=e),n._thingOperation(t,"get",r)},this.delete=function(t,e){var r={};return h(e)||(r.clientToken=e),n._thingOperation(t,"delete",r)},this.publish=function(t,e,n,r){if(i(t))throw"cannot publish to reserved topic '"+t+"'";d.publish(t,e,n,r)},this.subscribe=function(t,e,n){var r=[];"string"==typeof t?r.push(t):"object"==typeof t&&t.length&&(r=t);for(var o=0;othis.length)&&(i=this.length),r>=this.length)return t||new e(0);if(i<=0)return t||new e(0);var o,s,a=!!t,c=this._offset(r),u=i-r,h=u,f=a&&n||0,l=c[1];if(0===r&&i==this.length){if(!a)return 1===this._bufs.length?this._bufs[0]:e.concat(this._bufs,this.length);for(s=0;so)){this._bufs[s].copy(t,f,l,l+h);break}this._bufs[s].copy(t,f,l),f+=o,h-=o,l&&(l=0)}return t},r.prototype.shallowSlice=function(t,e){t=t||0,e=e||this.length,t<0&&(t+=this.length),e<0&&(e+=this.length);var n=this._offset(t),i=this._offset(e),o=this._bufs.slice(n[0],i[0]+1);return 0==i[1]?o.pop():o[o.length-1]=o[o.length-1].slice(0,i[1]),0!=n[1]&&(o[0]=o[0].slice(n[1])),new r(o)},r.prototype.toString=function(t,e,n){return this.slice(e,n).toString(t)},r.prototype.consume=function(t){for(;this._bufs.length;){if(!(t>=this._bufs[0].length)){this._bufs[0]=this._bufs[0].slice(t),this.length-=t;break}t-=this._bufs[0].length,this.length-=this._bufs[0].length,this._bufs.shift()}return this},r.prototype.duplicate=function(){for(var t=0,e=new r;t0)throw new Error("Invalid string. Length must be a multiple of 4");return"="===t[e-2]?2:"="===t[e-1]?1:0}function i(t){return 3*t.length/4-r(t)}function o(t){var e,n,i,o,s,a=t.length;o=r(t),s=new f(3*a/4-o),n=o>0?a-4:a;var c=0;for(e=0;e>16&255,s[c++]=i>>8&255,s[c++]=255&i;return 2===o?(i=h[t.charCodeAt(e)]<<2|h[t.charCodeAt(e+1)]>>4,s[c++]=255&i):1===o&&(i=h[t.charCodeAt(e)]<<10|h[t.charCodeAt(e+1)]<<4|h[t.charCodeAt(e+2)]>>2,s[c++]=i>>8&255,s[c++]=255&i),s}function s(t){return u[t>>18&63]+u[t>>12&63]+u[t>>6&63]+u[63&t]}function a(t,e,n){for(var r,i=[],o=e;oc?c:s+16383));return 1===r?(e=t[n-1],i+=u[e>>2],i+=u[e<<4&63],i+="=="):2===r&&(e=(t[n-2]<<8)+t[n-1],i+=u[e>>10],i+=u[e>>4&63],i+=u[e<<2&63],i+="="),o.push(i),o.join("")}e.byteLength=i,e.toByteArray=o,e.fromByteArray=c;for(var u=[],h=[],f="undefined"!=typeof Uint8Array?Uint8Array:Array,l="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",p=0,d=l.length;p>>8^255&i^99,o[n]=i,s[i]=n;var g=t[n],v=t[g],b=t[v],y=257*t[i]^16843008*i;a[n]=y<<24|y>>>8,c[n]=y<<16|y>>>16,u[n]=y<<8|y>>>24,h[n]=y;var y=16843009*b^65537*v^257*g^16843008*n;f[i]=y<<24|y>>>8,l[i]=y<<16|y>>>16,p[i]=y<<8|y>>>24,d[i]=y,n?(n=g^t[t[t[b^g]]],r^=t[t[r]]):n=r=1}}();var g=[0,1,2,4,8,16,32,64,128,27,54],v=i.AES=r.extend({_doReset:function(){for(var t=this._key,e=t.words,n=t.sigBytes/4,r=this._nRounds=n+6,i=4*(r+1),s=this._keySchedule=[],a=0;a6&&a%n==4&&(c=o[c>>>24]<<24|o[c>>>16&255]<<16|o[c>>>8&255]<<8|o[255&c]):(c=c<<8|c>>>24,c=o[c>>>24]<<24|o[c>>>16&255]<<16|o[c>>>8&255]<<8|o[255&c],c^=g[a/n|0]<<24),s[a]=s[a-n]^c}for(var u=this._invKeySchedule=[],h=0;h>>24]]^l[o[c>>>16&255]]^p[o[c>>>8&255]]^d[o[255&c]]}},encryptBlock:function(t,e){this._doCryptBlock(t,e,this._keySchedule,a,c,u,h,o)},decryptBlock:function(t,e){var n=t[e+1];t[e+1]=t[e+3],t[e+3]=n,this._doCryptBlock(t,e,this._invKeySchedule,f,l,p,d,s);var n=t[e+1];t[e+1]=t[e+3],t[e+3]=n},_doCryptBlock:function(t,e,n,r,i,o,s,a){for(var c=this._nRounds,u=t[e]^n[0],h=t[e+1]^n[1],f=t[e+2]^n[2],l=t[e+3]^n[3],p=4,d=1;d>>24]^i[h>>>16&255]^o[f>>>8&255]^s[255&l]^n[p++],v=r[h>>>24]^i[f>>>16&255]^o[l>>>8&255]^s[255&u]^n[p++],b=r[f>>>24]^i[l>>>16&255]^o[u>>>8&255]^s[255&h]^n[p++],y=r[l>>>24]^i[u>>>16&255]^o[h>>>8&255]^s[255&f]^n[p++];u=g,h=v,f=b,l=y}var g=(a[u>>>24]<<24|a[h>>>16&255]<<16|a[f>>>8&255]<<8|a[255&l])^n[p++],v=(a[h>>>24]<<24|a[f>>>16&255]<<16|a[l>>>8&255]<<8|a[255&u])^n[p++],b=(a[f>>>24]<<24|a[l>>>16&255]<<16|a[u>>>8&255]<<8|a[255&h])^n[p++],y=(a[l>>>24]<<24|a[u>>>16&255]<<16|a[h>>>8&255]<<8|a[255&f])^n[p++];t[e]=g,t[e+1]=v,t[e+2]=b,t[e+3]=y},keySize:8});e.AES=r._createHelper(v)}(),t.AES})},function(t,e,n){!function(r,i){t.exports=e=i(n(0))}(0,function(t){return function(){function e(t){return t<<8&4278255360|t>>>8&16711935}var n=t,r=n.lib,i=r.WordArray,o=n.enc;o.Utf16=o.Utf16BE={stringify:function(t){for(var e=t.words,n=t.sigBytes,r=[],i=0;i>>2]>>>16-i%4*8&65535;r.push(String.fromCharCode(o))}return r.join("")},parse:function(t){for(var e=t.length,n=[],r=0;r>>1]|=t.charCodeAt(r)<<16-r%2*16;return i.create(n,2*e)}};o.Utf16LE={stringify:function(t){for(var n=t.words,r=t.sigBytes,i=[],o=0;o>>2]>>>16-o%4*8&65535);i.push(String.fromCharCode(s))}return i.join("")},parse:function(t){for(var n=t.length,r=[],o=0;o>>1]|=e(t.charCodeAt(o)<<16-o%2*16);return i.create(r,2*n)}}}(),t.enc.Utf16})},function(t,e,n){!function(r,i,o){t.exports=e=i(n(0),n(1))}(0,function(t){return function(e){var n=t,r=n.lib,i=r.CipherParams,o=n.enc,s=o.Hex,a=n.format;a.Hex={stringify:function(t){return t.ciphertext.toString(s)},parse:function(t){var e=s.parse(t);return i.create({ciphertext:e})}}}(),t.format.Hex})},function(t,e,n){!function(r,i,o){t.exports=e=i(n(0),n(14),n(58),n(55),n(8),n(10),n(20),n(26),n(74),n(27),n(76),n(75),n(73),n(19),n(69),n(9),n(1),n(59),n(61),n(60),n(63),n(62),n(64),n(65),n(66),n(68),n(67),n(56),n(54),n(77),n(72),n(71),n(70))}(0,function(t){return t})},function(t,e,n){!function(r,i){t.exports=e=i(n(0))}(0,function(t){return function(){if("function"==typeof ArrayBuffer){var e=t,n=e.lib,r=n.WordArray,i=r.init;(r.init=function(t){if(t instanceof ArrayBuffer&&(t=new Uint8Array(t)),(t instanceof Int8Array||"undefined"!=typeof Uint8ClampedArray&&t instanceof Uint8ClampedArray||t instanceof Int16Array||t instanceof Uint16Array||t instanceof Int32Array||t instanceof Uint32Array||t instanceof Float32Array||t instanceof Float64Array)&&(t=new Uint8Array(t.buffer,t.byteOffset,t.byteLength)),t instanceof Uint8Array){for(var e=t.byteLength,n=[],r=0;r>>2]|=t[r]<<24-r%4*8;i.call(this,n,e)}else i.apply(this,arguments)}).prototype=r}}(),t.lib.WordArray})},function(t,e,n){!function(r,i,o){t.exports=e=i(n(0),n(1))}(0,function(t){return t.mode.CFB=function(){function e(t,e,n,r){var i=this._iv;if(i){var o=i.slice(0);this._iv=void 0}else var o=this._prevBlock;r.encryptBlock(o,0);for(var s=0;s>24&255)){var e=t>>16&255,n=t>>8&255,r=255&t;255===e?(e=0,255===n?(n=0,255===r?r=0:++r):++n):++e,t=0,t+=e<<16,t+=n<<8,t+=r}else t+=1<<24;return t}function n(t){return 0===(t[0]=e(t[0]))&&(t[1]=e(t[1])),t}var r=t.lib.BlockCipherMode.extend(),i=r.Encryptor=r.extend({processBlock:function(t,e){var r=this._cipher,i=r.blockSize,o=this._iv,s=this._counter;o&&(s=this._counter=o.slice(0),this._iv=void 0),n(s);var a=s.slice(0);r.encryptBlock(a,0);for(var c=0;c>>2]|=i<<24-o%4*8,t.sigBytes+=i},unpad:function(t){var e=255&t.words[t.sigBytes-1>>>2];t.sigBytes-=e}},t.pad.Ansix923})},function(t,e,n){!function(r,i,o){t.exports=e=i(n(0),n(1))}(0,function(t){return t.pad.Iso10126={pad:function(e,n){var r=4*n,i=r-e.sigBytes%r;e.concat(t.lib.WordArray.random(i-1)).concat(t.lib.WordArray.create([i<<24],1))},unpad:function(t){var e=255&t.words[t.sigBytes-1>>>2];t.sigBytes-=e}},t.pad.Iso10126})},function(t,e,n){!function(r,i,o){t.exports=e=i(n(0),n(1))}(0,function(t){return t.pad.Iso97971={pad:function(e,n){e.concat(t.lib.WordArray.create([2147483648],1)),t.pad.ZeroPadding.pad(e,n)},unpad:function(e){t.pad.ZeroPadding.unpad(e),e.sigBytes--}},t.pad.Iso97971})},function(t,e,n){!function(r,i,o){t.exports=e=i(n(0),n(1))}(0,function(t){return t.pad.NoPadding={pad:function(){},unpad:function(){}},t.pad.NoPadding})},function(t,e,n){!function(r,i,o){t.exports=e=i(n(0),n(1))}(0,function(t){return t.pad.ZeroPadding={pad:function(t,e){var n=4*e;t.clamp(),t.sigBytes+=n-(t.sigBytes%n||n)},unpad:function(t){for(var e=t.words,n=t.sigBytes-1;!(e[n>>>2]>>>24-n%4*8&255);)n--;t.sigBytes=n+1}},t.pad.ZeroPadding})},function(t,e,n){!function(r,i,o){t.exports=e=i(n(0),n(20),n(19))}(0,function(t){return function(){var e=t,n=e.lib,r=n.Base,i=n.WordArray,o=e.algo,s=o.SHA1,a=o.HMAC,c=o.PBKDF2=r.extend({cfg:r.extend({keySize:4,hasher:s,iterations:1}),init:function(t){this.cfg=this.cfg.extend(t)},compute:function(t,e){for(var n=this.cfg,r=a.create(n.hasher,t),o=i.create(),s=i.create([1]),c=o.words,u=s.words,h=n.keySize,f=n.iterations;c.length>>0>>0?1:0)|0,e[2]=e[2]+886263092+(e[1]>>>0>>0?1:0)|0,e[3]=e[3]+1295307597+(e[2]>>>0>>0?1:0)|0,e[4]=e[4]+3545052371+(e[3]>>>0>>0?1:0)|0,e[5]=e[5]+886263092+(e[4]>>>0>>0?1:0)|0,e[6]=e[6]+1295307597+(e[5]>>>0>>0?1:0)|0,e[7]=e[7]+3545052371+(e[6]>>>0>>0?1:0)|0,this._b=e[7]>>>0>>0?1:0;for(var n=0;n<8;n++){var r=t[n]+e[n],i=65535&r,o=r>>>16,s=((i*i>>>17)+i*o>>>15)+o*o,u=((4294901760&r)*r|0)+((65535&r)*r|0);c[n]=s^u}t[0]=c[0]+(c[7]<<16|c[7]>>>16)+(c[6]<<16|c[6]>>>16)|0,t[1]=c[1]+(c[0]<<8|c[0]>>>24)+c[7]|0,t[2]=c[2]+(c[1]<<16|c[1]>>>16)+(c[0]<<16|c[0]>>>16)|0,t[3]=c[3]+(c[2]<<8|c[2]>>>24)+c[1]|0,t[4]=c[4]+(c[3]<<16|c[3]>>>16)+(c[2]<<16|c[2]>>>16)|0,t[5]=c[5]+(c[4]<<8|c[4]>>>24)+c[3]|0,t[6]=c[6]+(c[5]<<16|c[5]>>>16)+(c[4]<<16|c[4]>>>16)|0,t[7]=c[7]+(c[6]<<8|c[6]>>>24)+c[5]|0}var n=t,r=n.lib,i=r.StreamCipher,o=n.algo,s=[],a=[],c=[],u=o.RabbitLegacy=i.extend({_doReset:function(){var t=this._key.words,n=this.cfg.iv,r=this._X=[t[0],t[3]<<16|t[2]>>>16,t[1],t[0]<<16|t[3]>>>16,t[2],t[1]<<16|t[0]>>>16,t[3],t[2]<<16|t[1]>>>16],i=this._C=[t[2]<<16|t[2]>>>16,4294901760&t[0]|65535&t[1],t[3]<<16|t[3]>>>16,4294901760&t[1]|65535&t[2],t[0]<<16|t[0]>>>16,4294901760&t[2]|65535&t[3],t[1]<<16|t[1]>>>16,4294901760&t[3]|65535&t[0]];this._b=0;for(var o=0;o<4;o++)e.call(this);for(var o=0;o<8;o++)i[o]^=r[o+4&7];if(n){var s=n.words,a=s[0],c=s[1],u=16711935&(a<<8|a>>>24)|4278255360&(a<<24|a>>>8),h=16711935&(c<<8|c>>>24)|4278255360&(c<<24|c>>>8),f=u>>>16|4294901760&h,l=h<<16|65535&u;i[0]^=u,i[1]^=f,i[2]^=h,i[3]^=l,i[4]^=u,i[5]^=f,i[6]^=h,i[7]^=l;for(var o=0;o<4;o++)e.call(this)}},_doProcessBlock:function(t,n){var r=this._X;e.call(this),s[0]=r[0]^r[5]>>>16^r[3]<<16,s[1]=r[2]^r[7]>>>16^r[5]<<16,s[2]=r[4]^r[1]>>>16^r[7]<<16,s[3]=r[6]^r[3]>>>16^r[1]<<16;for(var i=0;i<4;i++)s[i]=16711935&(s[i]<<8|s[i]>>>24)|4278255360&(s[i]<<24|s[i]>>>8),t[n+i]^=s[i]},blockSize:4,ivSize:2});n.RabbitLegacy=i._createHelper(u)}(),t.RabbitLegacy})},function(t,e,n){!function(r,i,o){t.exports=e=i(n(0),n(8),n(10),n(9),n(1))}(0,function(t){return function(){function e(){for(var t=this._X,e=this._C,n=0;n<8;n++)a[n]=e[n];e[0]=e[0]+1295307597+this._b|0,e[1]=e[1]+3545052371+(e[0]>>>0>>0?1:0)|0,e[2]=e[2]+886263092+(e[1]>>>0>>0?1:0)|0,e[3]=e[3]+1295307597+(e[2]>>>0>>0?1:0)|0,e[4]=e[4]+3545052371+(e[3]>>>0>>0?1:0)|0,e[5]=e[5]+886263092+(e[4]>>>0>>0?1:0)|0,e[6]=e[6]+1295307597+(e[5]>>>0>>0?1:0)|0,e[7]=e[7]+3545052371+(e[6]>>>0>>0?1:0)|0,this._b=e[7]>>>0>>0?1:0;for(var n=0;n<8;n++){var r=t[n]+e[n],i=65535&r,o=r>>>16,s=((i*i>>>17)+i*o>>>15)+o*o,u=((4294901760&r)*r|0)+((65535&r)*r|0);c[n]=s^u}t[0]=c[0]+(c[7]<<16|c[7]>>>16)+(c[6]<<16|c[6]>>>16)|0,t[1]=c[1]+(c[0]<<8|c[0]>>>24)+c[7]|0,t[2]=c[2]+(c[1]<<16|c[1]>>>16)+(c[0]<<16|c[0]>>>16)|0,t[3]=c[3]+(c[2]<<8|c[2]>>>24)+c[1]|0,t[4]=c[4]+(c[3]<<16|c[3]>>>16)+(c[2]<<16|c[2]>>>16)|0,t[5]=c[5]+(c[4]<<8|c[4]>>>24)+c[3]|0,t[6]=c[6]+(c[5]<<16|c[5]>>>16)+(c[4]<<16|c[4]>>>16)|0,t[7]=c[7]+(c[6]<<8|c[6]>>>24)+c[5]|0}var n=t,r=n.lib,i=r.StreamCipher,o=n.algo,s=[],a=[],c=[],u=o.Rabbit=i.extend({_doReset:function(){for(var t=this._key.words,n=this.cfg.iv,r=0;r<4;r++)t[r]=16711935&(t[r]<<8|t[r]>>>24)|4278255360&(t[r]<<24|t[r]>>>8);var i=this._X=[t[0],t[3]<<16|t[2]>>>16,t[1],t[0]<<16|t[3]>>>16,t[2],t[1]<<16|t[0]>>>16,t[3],t[2]<<16|t[1]>>>16],o=this._C=[t[2]<<16|t[2]>>>16,4294901760&t[0]|65535&t[1],t[3]<<16|t[3]>>>16,4294901760&t[1]|65535&t[2],t[0]<<16|t[0]>>>16,4294901760&t[2]|65535&t[3],t[1]<<16|t[1]>>>16,4294901760&t[3]|65535&t[0]];this._b=0;for(var r=0;r<4;r++)e.call(this);for(var r=0;r<8;r++)o[r]^=i[r+4&7];if(n){var s=n.words,a=s[0],c=s[1],u=16711935&(a<<8|a>>>24)|4278255360&(a<<24|a>>>8),h=16711935&(c<<8|c>>>24)|4278255360&(c<<24|c>>>8),f=u>>>16|4294901760&h,l=h<<16|65535&u;o[0]^=u,o[1]^=f,o[2]^=h,o[3]^=l,o[4]^=u,o[5]^=f,o[6]^=h,o[7]^=l;for(var r=0;r<4;r++)e.call(this)}},_doProcessBlock:function(t,n){var r=this._X;e.call(this),s[0]=r[0]^r[5]>>>16^r[3]<<16,s[1]=r[2]^r[7]>>>16^r[5]<<16,s[2]=r[4]^r[1]>>>16^r[7]<<16,s[3]=r[6]^r[3]>>>16^r[1]<<16;for(var i=0;i<4;i++)s[i]=16711935&(s[i]<<8|s[i]>>>24)|4278255360&(s[i]<<24|s[i]>>>8),t[n+i]^=s[i]},blockSize:4,ivSize:2});n.Rabbit=i._createHelper(u)}(),t.Rabbit})},function(t,e,n){!function(r,i,o){t.exports=e=i(n(0),n(8),n(10),n(9),n(1))}(0,function(t){return function(){function e(){for(var t=this._S,e=this._i,n=this._j,r=0,i=0;i<4;i++){e=(e+1)%256,n=(n+t[e])%256;var o=t[e];t[e]=t[n],t[n]=o,r|=t[(t[e]+t[n])%256]<<24-8*i}return this._i=e,this._j=n,r}var n=t,r=n.lib,i=r.StreamCipher,o=n.algo,s=o.RC4=i.extend({_doReset:function(){for(var t=this._key,e=t.words,n=t.sigBytes,r=this._S=[],i=0;i<256;i++)r[i]=i;for(var i=0,o=0;i<256;i++){var s=i%n,a=e[s>>>2]>>>24-s%4*8&255;o=(o+r[i]+a)%256;var c=r[i];r[i]=r[o],r[o]=c}this._i=this._j=0},_doProcessBlock:function(t,n){t[n]^=e.call(this)},keySize:8,ivSize:0});n.RC4=i._createHelper(s);var a=o.RC4Drop=s.extend({cfg:s.cfg.extend({drop:192}),_doReset:function(){s._doReset.call(this);for(var t=this.cfg.drop;t>0;t--)e.call(this)}});n.RC4Drop=i._createHelper(a)}(),t.RC4})},function(t,e,n){!function(r,i){t.exports=e=i(n(0))}(0,function(t){/** @preserve 13 | (c) 2012 by Cédric Mesnil. All rights reserved. 14 | 15 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 16 | 17 | - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 18 | - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 21 | */ 22 | return function(e){function n(t,e,n){return t^e^n}function r(t,e,n){return t&e|~t&n}function i(t,e,n){return(t|~e)^n}function o(t,e,n){return t&n|e&~n}function s(t,e,n){return t^(e|~n)}function a(t,e){return t<>>32-e}var c=t,u=c.lib,h=u.WordArray,f=u.Hasher,l=c.algo,p=h.create([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8,3,10,14,4,9,15,8,1,2,7,0,6,13,11,5,12,1,9,11,10,0,8,12,4,13,3,7,15,14,5,6,2,4,0,5,9,7,12,2,10,14,1,3,8,11,6,15,13]),d=h.create([5,14,7,0,9,2,11,4,13,6,15,8,1,10,3,12,6,11,3,7,0,13,5,10,14,15,8,12,4,9,1,2,15,5,1,3,7,14,6,9,11,8,12,2,10,0,4,13,8,6,4,1,3,11,15,0,5,12,2,13,9,7,10,14,12,15,10,4,1,5,8,7,6,2,13,14,0,3,9,11]),g=h.create([11,14,15,12,5,8,7,9,11,13,14,15,6,7,9,8,7,6,8,13,11,9,7,15,7,12,15,9,11,7,13,12,11,13,6,7,14,9,13,15,14,8,13,6,5,12,7,5,11,12,14,15,14,15,9,8,9,14,5,6,8,6,5,12,9,15,5,11,6,8,13,12,5,12,13,14,11,8,5,6]),v=h.create([8,9,9,11,13,15,15,5,7,7,8,11,14,14,12,6,9,13,15,7,12,8,9,11,7,7,12,7,6,15,13,11,9,7,15,11,8,6,6,14,12,13,5,14,13,13,7,5,15,5,8,11,14,14,6,14,6,9,12,9,12,5,15,8,8,5,12,9,12,5,14,6,8,13,6,5,15,13,11,11]),b=h.create([0,1518500249,1859775393,2400959708,2840853838]),y=h.create([1352829926,1548603684,1836072691,2053994217,0]),_=l.RIPEMD160=f.extend({_doReset:function(){this._hash=h.create([1732584193,4023233417,2562383102,271733878,3285377520])},_doProcessBlock:function(t,e){for(var c=0;c<16;c++){var u=e+c,h=t[u];t[u]=16711935&(h<<8|h>>>24)|4278255360&(h<<24|h>>>8)}var f,l,_,m,w,S,E,k,I,A,x=this._hash.words,T=b.words,C=y.words,B=p.words,O=d.words,R=g.words,M=v.words;S=f=x[0],E=l=x[1],k=_=x[2],I=m=x[3],A=w=x[4];for(var P,c=0;c<80;c+=1)P=f+t[e+B[c]]|0,P+=c<16?n(l,_,m)+T[0]:c<32?r(l,_,m)+T[1]:c<48?i(l,_,m)+T[2]:c<64?o(l,_,m)+T[3]:s(l,_,m)+T[4],P|=0,P=a(P,R[c]),P=P+w|0,f=w,w=m,m=a(_,10),_=l,l=P,P=S+t[e+O[c]]|0,P+=c<16?s(E,k,I)+C[0]:c<32?o(E,k,I)+C[1]:c<48?i(E,k,I)+C[2]:c<64?r(E,k,I)+C[3]:n(E,k,I)+C[4],P|=0,P=a(P,M[c]),P=P+A|0,S=A,A=I,I=a(k,10),k=E,E=P;P=x[1]+_+I|0,x[1]=x[2]+m+A|0,x[2]=x[3]+w+S|0,x[3]=x[4]+f+E|0,x[4]=x[0]+l+k|0,x[0]=P},_doFinalize:function(){var t=this._data,e=t.words,n=8*this._nDataBytes,r=8*t.sigBytes;e[r>>>5]|=128<<24-r%32,e[14+(r+64>>>9<<4)]=16711935&(n<<8|n>>>24)|4278255360&(n<<24|n>>>8),t.sigBytes=4*(e.length+1),this._process();for(var i=this._hash,o=i.words,s=0;s<5;s++){var a=o[s];o[s]=16711935&(a<<8|a>>>24)|4278255360&(a<<24|a>>>8)}return i},clone:function(){var t=f.clone.call(this);return t._hash=this._hash.clone(),t}});c.RIPEMD160=f._createHelper(_),c.HmacRIPEMD160=f._createHmacHelper(_)}(Math),t.RIPEMD160})},function(t,e,n){!function(r,i,o){t.exports=e=i(n(0),n(26))}(0,function(t){return function(){var e=t,n=e.lib,r=n.WordArray,i=e.algo,o=i.SHA256,s=i.SHA224=o.extend({_doReset:function(){this._hash=new r.init([3238371032,914150663,812702999,4144912697,4290775857,1750603025,1694076839,3204075428])},_doFinalize:function(){var t=o._doFinalize.call(this);return t.sigBytes-=4,t}});e.SHA224=o._createHelper(s),e.HmacSHA224=o._createHmacHelper(s)}(),t.SHA224})},function(t,e,n){!function(r,i,o){t.exports=e=i(n(0),n(14))}(0,function(t){return function(e){var n=t,r=n.lib,i=r.WordArray,o=r.Hasher,s=n.x64,a=s.Word,c=n.algo,u=[],h=[],f=[];!function(){for(var t=1,e=0,n=0;n<24;n++){u[t+5*e]=(n+1)*(n+2)/2%64;var r=e%5,i=(2*t+3*e)%5;t=r,e=i}for(var t=0;t<5;t++)for(var e=0;e<5;e++)h[t+5*e]=e+(2*t+3*e)%5*5;for(var o=1,s=0;s<24;s++){for(var c=0,l=0,p=0;p<7;p++){if(1&o){var d=(1<>>24)|4278255360&(o<<24|o>>>8),s=16711935&(s<<8|s>>>24)|4278255360&(s<<24|s>>>8);var a=n[i];a.high^=s,a.low^=o}for(var c=0;c<24;c++){for(var p=0;p<5;p++){for(var d=0,g=0,v=0;v<5;v++){var a=n[p+5*v];d^=a.high,g^=a.low}var b=l[p];b.high=d,b.low=g}for(var p=0;p<5;p++)for(var y=l[(p+4)%5],_=l[(p+1)%5],m=_.high,w=_.low,d=y.high^(m<<1|w>>>31),g=y.low^(w<<1|m>>>31),v=0;v<5;v++){var a=n[p+5*v];a.high^=d,a.low^=g}for(var S=1;S<25;S++){var a=n[S],E=a.high,k=a.low,I=u[S];if(I<32)var d=E<>>32-I,g=k<>>32-I;else var d=k<>>64-I,g=E<>>64-I;var A=l[h[S]];A.high=d,A.low=g}var x=l[0],T=n[0];x.high=T.high,x.low=T.low;for(var p=0;p<5;p++)for(var v=0;v<5;v++){var S=p+5*v,a=n[S],C=l[S],B=l[(p+1)%5+5*v],O=l[(p+2)%5+5*v];a.high=C.high^~B.high&O.high,a.low=C.low^~B.low&O.low}var a=n[0],R=f[c];a.high^=R.high,a.low^=R.low}},_doFinalize:function(){var t=this._data,n=t.words,r=(this._nDataBytes,8*t.sigBytes),o=32*this.blockSize;n[r>>>5]|=1<<24-r%32,n[(e.ceil((r+1)/o)*o>>>5)-1]|=128,t.sigBytes=4*n.length,this._process();for(var s=this._state,a=this.cfg.outputLength/8,c=a/8,u=[],h=0;h>>24)|4278255360&(l<<24|l>>>8),p=16711935&(p<<8|p>>>24)|4278255360&(p<<24|p>>>8),u.push(p),u.push(l)}return new i.init(u,a)},clone:function(){for(var t=o.clone.call(this),e=t._state=this._state.slice(0),n=0;n<25;n++)e[n]=e[n].clone();return t}});n.SHA3=o._createHelper(p),n.HmacSHA3=o._createHmacHelper(p)}(Math),t.SHA3})},function(t,e,n){!function(r,i,o){t.exports=e=i(n(0),n(14),n(27))}(0,function(t){return function(){var e=t,n=e.x64,r=n.Word,i=n.WordArray,o=e.algo,s=o.SHA512,a=o.SHA384=s.extend({_doReset:function(){this._hash=new i.init([new r.init(3418070365,3238371032),new r.init(1654270250,914150663),new r.init(2438529370,812702999),new r.init(355462360,4144912697),new r.init(1731405415,4290775857),new r.init(2394180231,1750603025),new r.init(3675008525,1694076839),new r.init(1203062813,3204075428)])},_doFinalize:function(){var t=s._doFinalize.call(this);return t.sigBytes-=16,t}});e.SHA384=s._createHelper(a),e.HmacSHA384=s._createHmacHelper(a)}(),t.SHA384})},function(t,e,n){!function(r,i,o){t.exports=e=i(n(0),n(8),n(10),n(9),n(1))}(0,function(t){return function(){function e(t,e){var n=(this._lBlock>>>t^this._rBlock)&e;this._rBlock^=n,this._lBlock^=n<>>t^this._lBlock)&e;this._lBlock^=n,this._rBlock^=n<>>5]>>>31-i%32&1}for(var o=this._subKeys=[],s=0;s<16;s++){for(var a=o[s]=[],f=h[s],r=0;r<24;r++)a[r/6|0]|=n[(u[r]-1+f)%28]<<31-r%6,a[4+(r/6|0)]|=n[28+(u[r+24]-1+f)%28]<<31-r%6;a[0]=a[0]<<1|a[0]>>>31;for(var r=1;r<7;r++)a[r]=a[r]>>>4*(r-1)+3;a[7]=a[7]<<5|a[7]>>>27}for(var l=this._invSubKeys=[],r=0;r<16;r++)l[r]=o[15-r]},encryptBlock:function(t,e){this._doCryptBlock(t,e,this._subKeys)},decryptBlock:function(t,e){this._doCryptBlock(t,e,this._invSubKeys)},_doCryptBlock:function(t,r,i){this._lBlock=t[r],this._rBlock=t[r+1],e.call(this,4,252645135),e.call(this,16,65535),n.call(this,2,858993459),n.call(this,8,16711935),e.call(this,1,1431655765);for(var o=0;o<16;o++){for(var s=i[o],a=this._lBlock,c=this._rBlock,u=0,h=0;h<8;h++)u|=f[h][((c^s[h])&l[h])>>>0];this._lBlock=c,this._rBlock=a^u}var p=this._lBlock;this._lBlock=this._rBlock,this._rBlock=p,e.call(this,1,1431655765),n.call(this,8,16711935),n.call(this,2,858993459),e.call(this,16,65535),e.call(this,4,252645135),t[r]=this._lBlock,t[r+1]=this._rBlock},keySize:2,ivSize:2,blockSize:2});r.DES=s._createHelper(p);var d=a.TripleDES=s.extend({_doReset:function(){var t=this._key,e=t.words;this._des1=p.createEncryptor(o.create(e.slice(0,2))),this._des2=p.createEncryptor(o.create(e.slice(2,4))),this._des3=p.createEncryptor(o.create(e.slice(4,6)))},encryptBlock:function(t,e){this._des1.encryptBlock(t,e),this._des2.decryptBlock(t,e),this._des3.encryptBlock(t,e)},decryptBlock:function(t,e){this._des3.decryptBlock(t,e),this._des2.encryptBlock(t,e),this._des1.decryptBlock(t,e)},keySize:6,ivSize:2,blockSize:2});r.TripleDES=s._createHelper(d)}(),t.TripleDES})},function(t,e,n){(function(e,r){var i=n(16),o=n(28),s=n(4),a=n(100),c=new e([0]),u=function(t,e){t._corked?t.once("uncork",e):e()},h=function(t,e){return function(n){n?t._destroyInterval(n):e&&!t._ended&&t.end()}},f=function(t,e){return t?t._writableState&&t._writableState.finished?e():t._writableState?t.end(e):(t.end(),void e()):e()},l=function(t){return new i.Readable({objectMode:!0,highWaterMark:16}).wrap(t)},p=function(t,e,n){if(!(this instanceof p))return new p(t,e,n);i.Duplex.call(this,n),this._writable=null,this._readable=null,this._readable2=null,this._forwardDestroy=!n||!1!==n.destroy,this._forwardEnd=!n||!1!==n.end,this._corked=1,this._ondrain=null,this._drained=!1,this._forwarding=!1,this._unwrite=null,this._unread=null,this._ended=!1,this._error=null,this._preferError=!1,this.destroyed=!1,t&&this.setWritable(t),e&&this.setReadable(e)};s(p,i.Duplex),p.obj=function(t,e,n){return n||(n={}),n.objectMode=!0,n.highWaterMark=16,new p(t,e,n)},p.prototype.cork=function(){1==++this._corked&&this.emit("cork")},p.prototype.uncork=function(){this._corked&&0==--this._corked&&this.emit("uncork")},p.prototype.setWritable=function(t){if(this._unwrite&&this._unwrite(),this.destroyed)return void(t&&t.destroy&&t.destroy());if(null===t||!1===t)return void this.end();var e=this,n=o(t,{writable:!0,readable:!1},h(this,this._forwardEnd)),i=function(){var t=e._ondrain;e._ondrain=null,t&&t()},s=function(){e._writable.removeListener("drain",i),n()};this._unwrite&&r.nextTick(i),this._writable=t,this._writable.on("drain",i),this._unwrite=s,this.uncork()},p.prototype.setReadable=function(t){if(this._unread&&this._unread(),this.destroyed)return void(t&&t.destroy&&t.destroy());if(null===t||!1===t)return this.push(null),void this.resume();var e=this,n=o(t,{writable:!1,readable:!0},h(this)),r=function(){e._forward()},i=function(){e.push(null)},s=function(){e._readable2.removeListener("readable",r),e._readable2.removeListener("end",i),n()};this._drained=!0,this._readable=t,this._readable2=t._readableState?t:l(t),this._readable2.on("readable",r),this._readable2.on("end",i),this._unread=s,this._forward()},p.prototype._read=function(){this._drained=!0,this._forward()},p.prototype._forward=function(){if(!this._forwarding&&this._readable2&&this._drained){this._forwarding=!0;for(var t;this._drained&&null!==(t=a(this._readable2));)this.destroyed||(this._drained=this.push(t));this._forwarding=!1}},p.prototype.destroy=function(t){if(this._preferError&&!this._error&&t&&(this._error=t),!this.destroyed){this.destroyed=!0;var e=this;r.nextTick(function(){e._destroy(e._preferError?e._error:t)})}},p.prototype._destroyInterval=function(t){if(!this.destroyed){if("premature close"!==t.message)return this.destroy(t);this._preferError=!0,this.destroy(null)}},p.prototype._destroy=function(t){if(t){var e=this._ondrain;this._ondrain=null,e?e(t):this.emit("error",t)}this._forwardDestroy&&(this._readable&&this._readable.destroy&&this._readable.destroy(),this._writable&&this._writable.destroy&&this._writable.destroy()),this.emit("close")},p.prototype._write=function(t,e,n){return this.destroyed?n():this._corked?u(this,this._write.bind(this,t,e,n)):t===c?this._finish(n):this._writable?void(!1===this._writable.write(t)?this._ondrain=n:n()):n()},p.prototype._finish=function(t){var e=this;this.emit("preend"),u(this,function(){f(e._forwardEnd&&e._writable,function(){!1===e._writableState.prefinished&&(e._writableState.prefinished=!0),e.emit("prefinish"),u(e,t)})})},p.prototype.end=function(t,e,n){return"function"==typeof t?this.end(null,null,t):"function"==typeof e?this.end(t,null,e):(this._ended=!0,t&&this.write(t),this._writableState.ending||this.write(c),i.Writable.prototype.end.call(this,n))},t.exports=p}).call(e,n(11).Buffer,n(2))},function(t,e){e.read=function(t,e,n,r,i){var o,s,a=8*i-r-1,c=(1<>1,h=-7,f=n?i-1:0,l=n?-1:1,p=t[e+f];for(f+=l,o=p&(1<<-h)-1,p>>=-h,h+=a;h>0;o=256*o+t[e+f],f+=l,h-=8);for(s=o&(1<<-h)-1,o>>=-h,h+=r;h>0;s=256*s+t[e+f],f+=l,h-=8);if(0===o)o=1-u;else{if(o===c)return s?NaN:1/0*(p?-1:1);s+=Math.pow(2,r),o-=u}return(p?-1:1)*s*Math.pow(2,o-r)},e.write=function(t,e,n,r,i,o){var s,a,c,u=8*o-i-1,h=(1<>1,l=23===i?Math.pow(2,-24)-Math.pow(2,-77):0,p=r?0:o-1,d=r?1:-1,g=e<0||0===e&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(a=isNaN(e)?1:0,s=h):(s=Math.floor(Math.log(e)/Math.LN2),e*(c=Math.pow(2,-s))<1&&(s--,c*=2),e+=s+f>=1?l/c:l*Math.pow(2,1-f),e*c>=2&&(s++,c/=2),s+f>=h?(a=0,s=h):s+f>=1?(a=(e*c-1)*Math.pow(2,i),s+=f):(a=e*Math.pow(2,f-1)*Math.pow(2,i),s=0));i>=8;t[n+p]=255&a,p+=d,a/=256,i-=8);for(s=s<0;t[n+p]=255&s,p+=d,s/=256,u-=8);t[n+p-d]|=128*g}},function(t,e,n){"use strict";function r(t){var e=new i;return s(t,e),e.concat()}function i(){this._array=new Array(20),this._i=0}var o=n(5).Buffer,s=n(31),a=n(6).EventEmitter;n(4)(i,a),i.prototype.write=function(t){return this._array[this._i++]=t,!0},i.prototype.concat=function(){var t,e,n=0,r=new Array(this._array.length),i=this._array,s=0;for(t=0;t>8,0,!0),e.writeUInt8(255&t,1,!0),e}function i(){for(var t=0;t0)&&this[this._states[this._stateCounter]]()&&!this.error;)++this._stateCounter>=this._states.length&&(this._stateCounter=0);return this._list.length},r.prototype._parseHeader=function(){var t=this._list.readUInt8(0);return this.packet.cmd=c.types[t>>c.CMD_SHIFT],this.packet.retain=0!=(t&c.RETAIN_MASK),this.packet.qos=t>>c.QOS_SHIFT&c.QOS_MASK,this.packet.dup=0!=(t&c.DUP_MASK),this._list.consume(1),!0},r.prototype._parseLength=function(){for(var t,e=0,n=1,r=0,i=!0;e<5&&(t=this._list.readUInt8(e++),r+=n*(t&c.LENGTH_MASK),n*=128,0!=(t&c.LENGTH_FIN_MASK));)if(this._list.length<=e){i=!1;break}return i&&(this.packet.length=r,this._list.consume(e)),i},r.prototype._parsePayload=function(){var t=!1;if(0===this.packet.length||this._list.length>=this.packet.length){switch(this._pos=0,this.packet.cmd){case"connect":this._parseConnect();break;case"connack":this._parseConnack();break;case"publish":this._parsePublish();break;case"puback":case"pubrec":case"pubrel":case"pubcomp":this._parseMessageId();break;case"subscribe":this._parseSubscribe();break;case"suback":this._parseSuback();break;case"unsubscribe":this._parseUnsubscribe();break;case"unsuback":this._parseUnsuback();break;case"pingreq":case"pingresp":case"disconnect":break;default:this._emitError(new Error("Not supported"))}t=!0}return t},r.prototype._parseConnect=function(){var t,e,n,r,i,o,s={},a=this.packet;if(null===(t=this._parseString()))return this._emitError(new Error("Cannot parse protocolId"));if("MQTT"!==t&&"MQIsdp"!==t)return this._emitError(new Error("Invalid protocolId"));if(a.protocolId=t,this._pos>=this._list.length)return this._emitError(new Error("Packet too short"));if(a.protocolVersion=this._list.readUInt8(this._pos),3!==a.protocolVersion&&4!==a.protocolVersion)return this._emitError(new Error("Invalid protocol version"));if(++this._pos>=this._list.length)return this._emitError(new Error("Packet too short"));if(s.username=this._list.readUInt8(this._pos)&c.USERNAME_MASK,s.password=this._list.readUInt8(this._pos)&c.PASSWORD_MASK,s.will=this._list.readUInt8(this._pos)&c.WILL_FLAG_MASK,s.will&&(a.will={},a.will.retain=0!=(this._list.readUInt8(this._pos)&c.WILL_RETAIN_MASK),a.will.qos=(this._list.readUInt8(this._pos)&c.WILL_QOS_MASK)>>c.WILL_QOS_SHIFT),a.clean=0!=(this._list.readUInt8(this._pos)&c.CLEAN_SESSION_MASK),this._pos++,a.keepalive=this._parseNum(),-1===a.keepalive)return this._emitError(new Error("Packet too short"));if(null===(e=this._parseString()))return this._emitError(new Error("Packet too short"));if(a.clientId=e,s.will){if(null===(n=this._parseString()))return this._emitError(new Error("Cannot parse will topic"));if(a.will.topic=n,null===(r=this._parseBuffer()))return this._emitError(new Error("Cannot parse will payload"));a.will.payload=r}if(s.username){if(null===(o=this._parseString()))return this._emitError(new Error("Cannot parse username"));a.username=o}if(s.password){if(null===(i=this._parseBuffer()))return this._emitError(new Error("Cannot parse password"));a.password=i}return a},r.prototype._parseConnack=function(){var t=this.packet;return this._list.length<2?null:(t.sessionPresent=!!(this._list.readUInt8(this._pos++)&c.SESSIONPRESENT_MASK),t.returnCode=this._list.readUInt8(this._pos),-1===t.returnCode?this._emitError(new Error("Cannot parse return code")):void 0)},r.prototype._parsePublish=function(){var t=this.packet;if(t.topic=this._parseString(),null===t.topic)return this._emitError(new Error("Cannot parse topic"));t.qos>0&&!this._parseMessageId()||(t.payload=this._list.slice(this._pos,t.length))},r.prototype._parseSubscribe=function(){var t,e,n=this.packet;if(1!==n.qos)return this._emitError(new Error("Wrong subscribe header"));if(n.subscriptions=[],this._parseMessageId())for(;this._posthis._list.length||r>this.packet.length?null:(e=this._list.toString("utf8",this._pos,r),this._pos+=n,e)},r.prototype._parseBuffer=function(){var t,e=this._parseNum(),n=e+this._pos;return-1===e||n>this._list.length||n>this.packet.length?null:(t=this._list.slice(this._pos,n),this._pos+=e,t)},r.prototype._parseNum=function(){if(this._list.length-this._pos<2)return-1;var t=this._list.readUInt16BE(this._pos);return this._pos+=2,t},r.prototype._newPacket=function(){return this.packet&&(this._list.consume(this.packet.length),this.emit("packet",this.packet)),this.packet=new a,!0},r.prototype._emitError=function(t){this.error=t,this.emit("error",t)},t.exports=r},function(t,e,n){"use strict";(function(e,r){function i(){return"mqttjs_"+Math.random().toString(16).substr(2,8)}function o(t,e,n){t.emit("packetsend",e),!l.writeToStream(e,t.stream)&&n?t.stream.once("drain",n):n&&n()}function s(t,e,n){t.outgoingStore.put(e,function(r){if(r)return n&&n(r);o(t,e,n)})}function a(){}function c(t,e){var n,r=this;if(!(this instanceof c))return new c(t,e);this.options=e||{};for(n in _)void 0===this.options[n]?this.options[n]=_[n]:this.options[n]=e[n];this.options.clientId="string"==typeof this.options.clientId?this.options.clientId:i(),this.streamBuilder=t,this.outgoingStore=this.options.outgoingStore||new h,this.incomingStore=this.options.incomingStore||new h,this.queueQoSZero=void 0===this.options.queueQoSZero||this.options.queueQoSZero,this._resubscribeTopics={},this.messageIdToTopic={},this.pingTimer=null,this.connected=!1,this.disconnecting=!1,this.queue=[],this.connackTimer=null,this.reconnectTimer=null,this.nextId=Math.floor(65535*Math.random()),this.outgoing={},this.on("connect",function(){if(!this.disconnected){this.connected=!0;var t=null;t=this.outgoingStore.createStream(),t.once("readable",function(){function e(){var n,i=t.read(1);i&&(!r.disconnecting&&!r.reconnectTimer&&r.options.reconnectPeriod>0?(t.read(0),n=r.outgoing[i.messageId],r.outgoing[i.messageId]=function(t,r){n&&n(t,r),e()},r._sendPacket(i)):t.destroy&&t.destroy())}e()}).on("error",this.emit.bind(this,"error"))}}),this.on("close",function(){this.connected=!1,clearTimeout(this.connackTimer)}),this.on("connect",this._setupPingTimer),this.on("connect",function(){function t(){var n=e.shift(),i=null;n&&(i=n.packet,r._sendPacket(i,function(e){n.cb&&n.cb(e),t()}))}var e=this.queue;t()});var o=!0;this.on("connect",function(){!o&&this.options.clean&&Object.keys(this._resubscribeTopics).length>0&&(this.options.resubscribe?(this._resubscribeTopics.resubscribe=!0,this.subscribe(this._resubscribeTopics)):this._resubscribeTopics={}),o=!1}),this.on("close",function(){null!==r.pingTimer&&(r.pingTimer.clear(),r.pingTimer=null)}),this.on("close",this._setupReconnect),u.EventEmitter.call(this),this._setupStream()}var u=n(6),h=n(35),f=n(28),l=n(81),p=n(16).Writable,d=n(4),g=n(98),v=n(88),b=n(25),y=e.setImmediate||function(t){r.nextTick(t)},_={keepalive:60,reschedulePings:!0,protocolId:"MQTT",protocolVersion:4,reconnectPeriod:1e3,connectTimeout:3e4,clean:!0,resubscribe:!0};d(c,u.EventEmitter),c.prototype._setupStream=function(){function t(){r.nextTick(e)}function e(){var e=h.shift(),n=u;e?i._handlePacket(e,t):(u=null,n())}var n,i=this,s=new p,c=l.parser(this.options),u=null,h=[];this._clearReconnect(),this.stream=this.streamBuilder(this),c.on("packet",function(t){h.push(t)}),s._write=function(t,n,r){u=r,c.parse(t),e()},this.stream.pipe(s),this.stream.on("error",a),f(this.stream,this.emit.bind(this,"close")),n=Object.create(this.options),n.cmd="connect",o(this,n),c.on("error",this.emit.bind(this,"error")),this.stream.setMaxListeners(1e3),clearTimeout(this.connackTimer),this.connackTimer=setTimeout(function(){i._cleanUp(!0)},this.options.connectTimeout)},c.prototype._handlePacket=function(t,e){switch(this.emit("packetreceive",t),t.cmd){case"publish":this._handlePublish(t,e);break;case"puback":case"pubrec":case"pubcomp":case"suback":case"unsuback":this._handleAck(t),e();break;case"pubrel":this._handlePubrel(t,e);break;case"connack":this._handleConnack(t),e();break;case"pingresp":this._handlePingresp(t),e()}},c.prototype._checkDisconnecting=function(t){return this.disconnecting&&(t?t(new Error("client disconnecting")):this.emit("error",new Error("client disconnecting"))),this.disconnecting},c.prototype.publish=function(t,e,n,r){var i;if("function"==typeof n&&(r=n,n=null),n=b({qos:0,retain:!1,dup:!1},n),this._checkDisconnecting(r))return this;switch(i={cmd:"publish",topic:t,payload:e,qos:n.qos,retain:n.retain,messageId:this._nextId(),dup:n.dup},n.qos){case 1:case 2:this.outgoing[i.messageId]=r||a,this._sendPacket(i);break;default:this._sendPacket(i,r)}return this},c.prototype.subscribe=function(){var t,e,n=Array.prototype.slice.call(arguments),r=[],i=n.shift(),o=i.resubscribe,s=n.pop()||a,c=n.pop(),u=this;if(delete i.resubscribe,"string"==typeof i&&(i=[i]),"function"!=typeof s&&(c=s,s=a),null!==(e=v.validateTopics(i)))return y(s,new Error("Invalid topic "+e)),this;if(this._checkDisconnecting(s))return this;if(c=b({qos:0},c),Array.isArray(i)?i.forEach(function(t){(u._resubscribeTopics[t]0&&(u._resubscribeTopics[t.topic]=t.qos,h.push(t.topic))}),u.messageIdToTopic[t.messageId]=h}return this.outgoing[t.messageId]=function(t,e){if(!t)for(var n=e.granted,i=0;i0?this.once("outgoingEmpty",setTimeout.bind(null,r,10)):r(),this)},c.prototype.removeOutgoingMessage=function(t){var e=this.outgoing[t];return delete this.outgoing[t],this.outgoingStore.del({messageId:t},function(){e(new Error("Message removed"))}),this},c.prototype.reconnect=function(t){var e=this,n=function(){t?(e.options.incomingStore=t.incomingStore,e.options.outgoingStore=t.outgoingStore):(e.options.incomingStore=null,e.options.outgoingStore=null),e.incomingStore=e.options.incomingStore||new h,e.outgoingStore=e.options.outgoingStore||new h,e.disconnecting=!1,e.disconnected=!1,e._deferredReconnect=null,e._reconnect()};return this.disconnecting&&!this.disconnected?this._deferredReconnect=n:n(),this},c.prototype._reconnect=function(){this.emit("reconnect"),this._setupStream()},c.prototype._setupReconnect=function(){var t=this;!t.disconnecting&&!t.reconnectTimer&&t.options.reconnectPeriod>0&&(this.reconnecting||(this.emit("offline"),this.reconnecting=!0),t.reconnectTimer=setInterval(function(){t._reconnect()},t.options.reconnectPeriod))},c.prototype._clearReconnect=function(){this.reconnectTimer&&(clearInterval(this.reconnectTimer),this.reconnectTimer=null)},c.prototype._cleanUp=function(t,e){e&&this.stream.on("close",e),t?this.stream.destroy():this._sendPacket({cmd:"disconnect"},y.bind(null,this.stream.end.bind(this.stream))),this.disconnecting||(this._clearReconnect(),this._setupReconnect()),null!==this.pingTimer&&(this.pingTimer.clear(),this.pingTimer=null)},c.prototype._sendPacket=function(t,e){if(!this.connected)return void(0===(t.qos||0)&&this.queueQoSZero||"publish"!==t.cmd?this.queue.push({packet:t,cb:e}):t.qos>0?(e=this.outgoing[t.messageId],this.outgoingStore.put(t,function(t){if(t)return e&&e(t)})):e&&e(new Error("No connection to broker")));if(this._shiftPingInterval(),"publish"!==t.cmd)return void o(this,t,e);switch(t.qos){case 2:case 1:s(this,t,e);break;case 0:default:o(this,t,e)}},c.prototype._setupPingTimer=function(){var t=this;!this.pingTimer&&this.options.keepalive&&(this.pingResp=!0,this.pingTimer=g(function(){t._checkPing()},1e3*this.options.keepalive))},c.prototype._shiftPingInterval=function(){this.pingTimer&&this.options.keepalive&&this.options.reschedulePings&&this.pingTimer.reschedule(1e3*this.options.keepalive)},c.prototype._checkPing=function(){this.pingResp?(this.pingResp=!1,this._sendPacket({cmd:"pingreq"})):this._cleanUp(!0)},c.prototype._handlePingresp=function(){this.pingResp=!0},c.prototype._handleConnack=function(t){var e=t.returnCode,n=["","Unacceptable protocol version","Identifier rejected","Server unavailable","Bad username or password","Not authorized"];if(clearTimeout(this.connackTimer),0===e)this.reconnecting=!1,this.emit("connect",t);else if(e>0){var r=new Error("Connection refused: "+n[e]);r.code=e,this.emit("error",r)}},c.prototype._handlePublish=function(t,e){var n=t.topic.toString(),r=t.payload,i=t.qos,o=t.messageId,s=this;switch(i){case 2:this.incomingStore.put(t,function(){s._sendPacket({cmd:"pubrec",messageId:o},e)});break;case 1:this.emit("message",n,r,t),this.handleMessage(t,function(t){if(t)return e&&e(t);s._sendPacket({cmd:"puback",messageId:o},e)});break;case 0:this.emit("message",n,r,t),this.handleMessage(t,e)}},c.prototype.handleMessage=function(t,e){e()},c.prototype._handleAck=function(t){var e=t.messageId,n=t.cmd,r=null,i=this.outgoing[e],o=this;if(i){switch(n){case"pubcomp":case"puback":delete this.outgoing[e],this.outgoingStore.del(t,i);break;case"pubrec":r={cmd:"pubrel",qos:2,messageId:e},this._sendPacket(r);break;case"suback":if(delete this.outgoing[e],1===t.granted.length&&0!=(128&t.granted[0])){var s=this.messageIdToTopic[e];s&&s.forEach(function(t){delete o._resubscribeTopics[t]})}i(null,t);break;case"unsuback":delete this.outgoing[e],i(null);break;default:o.emit("error",new Error("unrecognized packet type"))}this.disconnecting&&0===Object.keys(this.outgoing).length&&this.emit("outgoingEmpty")}},c.prototype._handlePubrel=function(t,e){var n=t.messageId,r=this,i={cmd:"pubcomp",messageId:n};r.incomingStore.get(t,function(n,o){n||"pubrel"===o.cmd?r._sendPacket(i,e):(r.emit("message",o.topic,o.payload,o),r.incomingStore.put(t),r.handleMessage(o,function(t){if(t)return e&&e(t);r._sendPacket(i,e)}))})},c.prototype._nextId=function(){var t=this.nextId++;return 65535===t&&(this.nextId=1),t},c.prototype.getLastMessageId=function(){return 1===this.nextId?65535:this.nextId-1},t.exports=c}).call(e,n(3),n(2))},function(t,e,n){"use strict";(function(e){function r(t){var e;t.auth&&(e=t.auth.match(/^(.+):(.+)$/),e?(t.username=e[1],t.password=e[2]):t.username=t.auth)}function i(t,e){function n(t){return e.servers&&(t._reconnectCount&&t._reconnectCount!==e.servers.length||(t._reconnectCount=0),e.host=e.servers[t._reconnectCount].host,e.port=e.servers[t._reconnectCount].port,e.hostname=e.host,t._reconnectCount++),u[e.protocol](t,e)}if("object"!=typeof t||e||(e=t,t=null),e=e||{},t){var i=a.parse(t,!0);if(null!=i.port&&(i.port=Number(i.port)),e=c(i,e),null===e.protocol)throw new Error("Missing protocol");e.protocol=e.protocol.replace(/:$/,"")}if(r(e),e.query&&"string"==typeof e.query.clientId&&(e.clientId=e.query.clientId),e.cert&&e.key){if(!e.protocol)throw new Error("Missing secure protocol key");if(-1===["mqtts","wss","wxs"].indexOf(e.protocol))switch(e.protocol){case"mqtt":e.protocol="mqtts";break;case"ws":e.protocol="wss";break;case"wx":e.protocol="wxs";break;default:throw new Error('Unknown protocol for secure connection: "'+e.protocol+'"!')}}if(!u[e.protocol]){var s=-1!==["mqtts","wss"].indexOf(e.protocol);e.protocol=["mqtt","mqtts","ws","wss","wx","wxs"].filter(function(t,e){return(!s||e%2!=0)&&"function"==typeof u[t]})[0]}if(!1===e.clean&&!e.clientId)throw new Error("Missing clientId for unclean clients");return new o(n,e)}var o=n(86),s=n(35),a=n(23),c=n(25),u={};"browser"!==e.title?(u.mqtt=n(32),u.tcp=n(32),u.ssl=n(21),u.tls=n(21),u.mqtts=n(21)):(u.wx=n(34),u.wxs=n(34)),u.ws=n(33),u.wss=n(33),t.exports=i,t.exports.connect=i,t.exports.MqttClient=o,t.exports.Store=s}).call(e,n(2))},function(t,e,n){"use strict";function r(t){for(var e=t.split("/"),n=0;n=0;r--){var i=t[r];"."===i?t.splice(r,1):".."===i?(t.splice(r,1),n++):n&&(t.splice(r,1),n--)}if(e)for(;n--;n)t.unshift("..");return t}function r(t,e){if(t.filter)return t.filter(e);for(var n=[],r=0;r=-1&&!i;o--){var s=o>=0?arguments[o]:t.cwd();if("string"!=typeof s)throw new TypeError("Arguments to path.resolve must be strings");s&&(e=s+"/"+e,i="/"===s.charAt(0))}return e=n(r(e.split("/"),function(t){return!!t}),!i).join("/"),(i?"/":"")+e||"."},e.normalize=function(t){var i=e.isAbsolute(t),o="/"===s(t,-1);return t=n(r(t.split("/"),function(t){return!!t}),!i).join("/"),t||i||(t="."),t&&o&&(t+="/"),(i?"/":"")+t},e.isAbsolute=function(t){return"/"===t.charAt(0)},e.join=function(){var t=Array.prototype.slice.call(arguments,0);return e.normalize(r(t,function(t,e){if("string"!=typeof t)throw new TypeError("Arguments to path.join must be strings");return t}).join("/"))},e.relative=function(t,n){function r(t){for(var e=0;e=0&&""===t[n];n--);return e>n?[]:t.slice(e,n-e+1)}t=e.resolve(t).substr(1),n=e.resolve(n).substr(1);for(var i=r(t.split("/")),o=r(n.split("/")),s=Math.min(i.length,o.length),a=s,c=0;c1&&(r=n[0]+"@",t=n[1]),t=t.replace(O,"."),r+a(t.split("."),e).join(".")}function u(t){for(var e,n,r=[],i=0,o=t.length;i=55296&&e<=56319&&i65535&&(t-=65536,e+=N(t>>>10&1023|55296),t=56320|1023&t),e+=N(t)}).join("")}function f(t){return t-48<10?t-22:t-65<26?t-65:t-97<26?t-97:w}function l(t,e){return t+22+75*(t<26)-((0!=e)<<5)}function p(t,e,n){var r=0;for(t=n?P(t/I):t>>1,t+=P(t/e);t>M*E>>1;r+=w)t=P(t/M);return P(r+(M+1)*t/(t+k))}function d(t){var e,n,r,i,o,a,c,u,l,d,g=[],v=t.length,b=0,y=x,_=A;for(n=t.lastIndexOf(T),n<0&&(n=0),r=0;r=128&&s("not-basic"),g.push(t.charCodeAt(r));for(i=n>0?n+1:0;i=v&&s("invalid-input"),u=f(t.charCodeAt(i++)),(u>=w||u>P((m-b)/a))&&s("overflow"),b+=u*a,l=c<=_?S:c>=_+E?E:c-_,!(uP(m/d)&&s("overflow"),a*=d;e=g.length+1,_=p(b-o,e,0==o),P(b/e)>m-y&&s("overflow"),y+=P(b/e),b%=e,g.splice(b++,0,y)}return h(g)}function g(t){var e,n,r,i,o,a,c,h,f,d,g,v,b,y,_,k=[];for(t=u(t),v=t.length,e=x,n=0,o=A,a=0;a=e&&gP((m-n)/b)&&s("overflow"),n+=(c-e)*b,e=c,a=0;am&&s("overflow"),g==e){for(h=n,f=w;d=f<=o?S:f>=o+E?E:f-o,!(h= 0x80 (not a basic code point)","invalid-input":"Invalid input"},M=w-S,P=Math.floor,N=String.fromCharCode;_={version:"1.3.2",ucs2:{decode:u,encode:h},decode:d,encode:g,toASCII:b,toUnicode:v},void 0!==(i=function(){return _}.call(e,n,e,t))&&(t.exports=i)}()}).call(e,n(106)(t),n(3))},function(t,e,n){"use strict";function r(t,e){return Object.prototype.hasOwnProperty.call(t,e)}t.exports=function(t,e,n,o){e=e||"&",n=n||"=";var s={};if("string"!=typeof t||0===t.length)return s;var a=/\+/g;t=t.split(e);var c=1e3;o&&"number"==typeof o.maxKeys&&(c=o.maxKeys);var u=t.length;c>0&&u>c&&(u=c);for(var h=0;h=0?(f=g.substr(0,v),l=g.substr(v+1)):(f=g,l=""),p=decodeURIComponent(f),d=decodeURIComponent(l),r(s,p)?i(s[p])?s[p].push(d):s[p]=[s[p],d]:s[p]=d}return s};var i=Array.isArray||function(t){return"[object Array]"===Object.prototype.toString.call(t)}},function(t,e,n){"use strict";function r(t,e){if(t.map)return t.map(e);for(var n=[],r=0;r0?this.tail.next=e:this.head=e,this.tail=e,++this.length},t.prototype.unshift=function(t){var e={data:t,next:this.head};0===this.length&&(this.tail=e),this.head=e,++this.length},t.prototype.shift=function(){if(0!==this.length){var t=this.head.data;return 1===this.length?this.head=this.tail=null:this.head=this.head.next,--this.length,t}},t.prototype.clear=function(){this.head=this.tail=null,this.length=0},t.prototype.join=function(t){if(0===this.length)return"";for(var e=this.head,n=""+e.data;e=e.next;)n+=t+e.data;return n},t.prototype.concat=function(t){if(0===this.length)return o.alloc(0);if(1===this.length)return this.head.data;for(var e=o.allocUnsafe(t>>>0),n=this.head,r=0;n;)i(n.data,e,r),r+=n.data.length,n=n.next;return e},t}(),s&&s.inspect&&s.inspect.custom&&(t.exports.prototype[s.inspect.custom]=function(){var t=s.inspect({length:this.length});return this.constructor.name+" "+t})},function(t,e,n){"use strict";function r(t,e,n){var r=this;this._callback=t,this._args=n,this._interval=setInterval(t,e,this._args),this.reschedule=function(t){t||(t=r._interval),r._interval&&clearInterval(r._interval),r._interval=setInterval(r._callback,t,r._args)},this.clear=function(){r._interval&&(clearInterval(r._interval),r._interval=void 0)},this.destroy=function(){r._interval&&clearInterval(r._interval),r._callback=void 0,r._interval=void 0,r._args=void 0}}function i(){if("function"!=typeof arguments[0])throw new Error("callback needed");if("number"!=typeof arguments[1])throw new Error("interval needed");var t;if(arguments.length>0){t=new Array(arguments.length-2);for(var e=0;e=0&&(t._idleTimeoutId=setTimeout(function(){t._onTimeout&&t._onTimeout()},e))},n(99),e.setImmediate="undefined"!=typeof self&&self.setImmediate||void 0!==t&&t.setImmediate||this&&this.setImmediate,e.clearImmediate="undefined"!=typeof self&&self.clearImmediate||void 0!==t&&t.clearImmediate||this&&this.clearImmediate}).call(e,n(3))},function(t,e,n){"use strict";t.exports={isString:function(t){return"string"==typeof t},isObject:function(t){return"object"==typeof t&&null!==t},isNull:function(t){return null===t},isNullOrUndefined:function(t){return null==t}}},function(t,e,n){(function(e){function n(t,e){function n(){if(!i){if(r("throwDeprecation"))throw new Error(e);r("traceDeprecation"),i=!0}return t.apply(this,arguments)}if(r("noDeprecation"))return t;var i=!1;return n}function r(t){try{if(!e.localStorage)return!1}catch(t){return!1}var n=e.localStorage[t];return null!=n&&"true"===String(n).toLowerCase()}t.exports=n}).call(e,n(3))},function(t,e){"function"==typeof Object.create?t.exports=function(t,e){t.super_=e,t.prototype=Object.create(e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}})}:t.exports=function(t,e){t.super_=e;var n=function(){};n.prototype=e.prototype,t.prototype=new n,t.prototype.constructor=t}},function(t,e){t.exports=function(t){return t&&"object"==typeof t&&"function"==typeof t.copy&&"function"==typeof t.fill&&"function"==typeof t.readUInt8}},function(t,e){t.exports=function(t){return t.webpackPolyfill||(t.deprecate=function(){},t.paths=[],t.children||(t.children=[]),Object.defineProperty(t,"loaded",{enumerable:!0,get:function(){return t.l}}),Object.defineProperty(t,"id",{enumerable:!0,get:function(){return t.i}}),t.webpackPolyfill=1),t}},function(t,e){var n=null;"undefined"!=typeof WebSocket?n=WebSocket:"undefined"!=typeof MozWebSocket?n=MozWebSocket:"undefined"!=typeof window&&(n=window.WebSocket||window.MozWebSocket),t.exports=n},function(t,e){function n(t,e){function r(){for(var e=new Array(arguments.length),n=0;n