Websocket parameter returned is null #504
Unanswered
pallaviwhy
asked this question in
Q&A
Replies: 2 comments 3 replies
-
A few comments:
|
Beta Was this translation helpful? Give feedback.
2 replies
-
websocket isn't null, it's an empty object. That parameter exists to override parts of the signing process, which is not needed in your case. The problem is that you're passing in something that is not a valid credentials provider. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi i am using the example browser pub/sub in which i have changed provider authentication to fit my requirements.
i am running the code example in vs code
import { fromCognitoIdentityPool } from "@aws-sdk/credential-providers";
import { mqtt, iot} from "aws-iot-device-sdk-v2";
async function connect_websocket(provider: any) {
return new Promise<mqtt.MqttClientConnection>((resolve, reject) => {
});
}
async function main() {
let idToken = sessionStorage.getItem('idToken');
if (!idToken) {
log('No idToken found, please sign in.');
return;
}
let COGNITO_ID = "cognito-idp.us-east-1.amazonaws.com/us-east-1_7YKwIrPtO";
let loginData = {
[COGNITO_ID]: idToken,
};
let provider;
const providerfunc = await fromCognitoIdentityPool({
clientConfig: { region: AWS_REGION },
identityPoolId: AWS_COGNITO_IDENTITY_POOL_ID,
logins: loginData
});
provider = await providerfunc();
console.log("Authenticated", provider);
connect_websocket(provider)
.then((connection) => {
connection
.subscribe(
"test/topic",
mqtt.QoS.AtLeastOnce,
(topic, payload, dup, qos, retain) => {
const decoder = new TextDecoder("utf8");
let message = decoder.decode(new Uint8Array(payload));
log(
Message received: topic=${topic} message=${message}
);// Uncomment the following line to see how disconnect behaves.
// connection.disconnect();
}
)
.then((subscription) => {
log(
start publish
);var msg_count = 0;
connection.publish(subscription.topic,
Hello world! ${msg_count}
, subscription.qos);// The sample will keep publishing the message every minute.
setInterval(() => {
msg_count++;
const msg =
Hello world! ${msg_count}
;connection.publish(subscription.topic, msg, subscription.qos);
}, 60000);
});
})
.catch((reason) => {
log(
Error while connecting: ${reason}
);});
}
Here is part of my code i have shared
i have logged the config. here all values are present except that "websocket":{} is null
i have intialized aws_iotendpoint and other inputs correctly and have checked the input are correct
Beta Was this translation helpful? Give feedback.
All reactions