mirror of
https://github.com/bourquep/mysa-js-sdk.git
synced 2026-02-04 09:41:07 +00:00
Compare commits
8 Commits
main
...
180-rapid-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d9d6fc2861 | ||
|
|
1b680b693f | ||
|
|
181c9238da | ||
|
|
6c24d59760 | ||
|
|
f7c3dc07b3 | ||
|
|
2a2a843534 | ||
|
|
2d49a4ddb9 | ||
|
|
5fce04543a |
@@ -20,6 +20,7 @@ const rootLogger = pino({
|
||||
/** Main entry point of the example application. */
|
||||
async function main() {
|
||||
let session: MysaSession | undefined;
|
||||
|
||||
try {
|
||||
rootLogger.info('Loading session...');
|
||||
const sessionJson = await readFile('session.json', 'utf8');
|
||||
@@ -27,7 +28,11 @@ async function main() {
|
||||
} catch {
|
||||
rootLogger.info('No valid session file found.');
|
||||
}
|
||||
const client = new MysaApiClient(session, { logger: rootLogger.child({ module: 'mysa-js-sdk' }) });
|
||||
|
||||
const client = new MysaApiClient(session, {
|
||||
logger: rootLogger.child({ module: 'mysa-js-sdk' }),
|
||||
isAwsCrtDebugLoggingEnabled: process.env.AWS_CRT_DEBUG_LOGGING === '1'
|
||||
});
|
||||
|
||||
client.emitter.on('sessionChanged', async (newSession) => {
|
||||
if (newSession) {
|
||||
@@ -96,14 +101,12 @@ async function main() {
|
||||
});
|
||||
}
|
||||
|
||||
await Promise.all(
|
||||
Object.entries(devices.DevicesObj).map(async ([deviceId, device]) => {
|
||||
const serial = await client.getDeviceSerialNumber(deviceId);
|
||||
rootLogger.info(`Serial number for device '${deviceId}' (${device.Name ?? 'Unknown'}): ${serial}`);
|
||||
for (const [deviceId, device] of Object.entries(devices.DevicesObj)) {
|
||||
const serial = await client.getDeviceSerialNumber(deviceId);
|
||||
rootLogger.info(`Serial number for device '${deviceId}' (${device.Name ?? 'Unknown'}): ${serial}`);
|
||||
|
||||
await client.startRealtimeUpdates(deviceId);
|
||||
})
|
||||
);
|
||||
await client.startRealtimeUpdates(deviceId);
|
||||
}
|
||||
}
|
||||
|
||||
main().catch((error) => {
|
||||
|
||||
@@ -18,7 +18,7 @@ import {
|
||||
CognitoUserPool,
|
||||
CognitoUserSession
|
||||
} from 'amazon-cognito-identity-js';
|
||||
import { iot, mqtt } from 'aws-iot-device-sdk-v2';
|
||||
import { io, iot, mqtt } from 'aws-iot-device-sdk-v2';
|
||||
import { hash } from 'crypto';
|
||||
import dayjs, { Dayjs } from 'dayjs';
|
||||
import duration from 'dayjs/plugin/duration.js';
|
||||
@@ -152,6 +152,10 @@ export class MysaApiClient {
|
||||
this._logger = options?.logger || new VoidLogger();
|
||||
this._fetcher = options?.fetcher || fetch;
|
||||
|
||||
if (options?.isAwsCrtDebugLoggingEnabled) {
|
||||
io.enable_logging(io.LogLevel.DEBUG);
|
||||
}
|
||||
|
||||
if (session) {
|
||||
this._cognitoUser = new CognitoUser({
|
||||
Username: session.username,
|
||||
@@ -741,7 +745,7 @@ export class MysaApiClient {
|
||||
.with_client_id(this._mqttClientId)
|
||||
.with_clean_session(false)
|
||||
.with_keep_alive_seconds(30)
|
||||
.with_ping_timeout_ms(3000)
|
||||
.with_ping_timeout_ms(10000)
|
||||
.with_protocol_operation_timeout_ms(60000)
|
||||
.with_reconnect_min_sec(1)
|
||||
.with_reconnect_max_sec(30);
|
||||
|
||||
@@ -15,4 +15,11 @@ export interface MysaApiClientOptions {
|
||||
* @defaultValue The global `fetch` function.
|
||||
*/
|
||||
fetcher?: typeof fetch;
|
||||
|
||||
/**
|
||||
* Whether to enable debug logging for AWS CRT.
|
||||
*
|
||||
* @defaultValue `false`
|
||||
*/
|
||||
isAwsCrtDebugLoggingEnabled?: boolean;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user