aws-mqtt
aws-mqtt copied to clipboard
Code 1005 is reserved and may not be used in React Native
This is my code:
import Aws from 'aws-sdk/dist/aws-sdk-react-native'
import AwsIot from 'aws-iot-device-sdk'
AWS_REGION = 'us-east-1' // Change if needed.
AWS_COGNITO_IDENTITY_POOL = 'us-east-1:******-******-******-******-******'
AWS_IOT_ENDPOINT = '******-ats.iot.us-east-1.amazonaws.com' // Fill in.
Aws.config.region = AWS_REGION
Aws.config.credentials = new Aws.CognitoIdentityCredentials({
IdentityPoolId: AWS_COGNITO_IDENTITY_POOL
})
Aws.config.credentials.get(() => {
const config = {}
let client
config.host = AWS_IOT_ENDPOINT
config.protocol = 'wss'
config.clientId = `client-${Math.floor((Math.random() * 100000) + 1)}`
config.accessKeyId = Aws.config.credentials.accessKeyId
config.secretKey = Aws.config.credentials.secretAccessKey
config.sessionToken = Aws.config.credentials.sessionToken
client = AwsIot.device(config)
client.on('connect', () => {
client.subscribe('some_topic')
})
client.on('message', (topic, message) => {
console.log("topic", topic)
console.log("message", message)
})
client.on('error', error => {
console.log("error", error)
})
})
Then it gives me an error:
Event {
"isTrusted": false,
"message": "Code 1005 is reserved and may not be used.",
}