Skip to content

Commit

Permalink
chore(pubsub): manual fix of linter reproted error
Browse files Browse the repository at this point in the history
  • Loading branch information
HuiSF committed Mar 5, 2024
1 parent 6d4b112 commit 86323c4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
24 changes: 15 additions & 9 deletions packages/pubsub/src/Providers/MqttOverWS.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

// @ts-ignore
import { Observable, Observer, SubscriptionLike as Subscription } from 'rxjs';
import { ConsoleLogger, Hub, HubPayload } from '@aws-amplify/core';
import { amplifyUuid } from '@aws-amplify/core/internals/utils';
Expand All @@ -14,6 +13,8 @@ import {
PublishInput,
SubscribeInput,
} from '../types/PubSub';
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore this module is expected to not have declaration file
import * as Paho from '../vendor/paho-mqtt.js';
import {
CONNECTION_CHANGE,
Expand Down Expand Up @@ -179,7 +180,8 @@ export class MqttOverWS extends AbstractPubSub<MqttOptions> {
logger.debug('Creating new MQTT client', clientId);

this.connectionStateMonitor.record(CONNECTION_CHANGE.OPENING_CONNECTION);
// @ts-ignore
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore this module is expected to not have declaration file
const client = new Paho.Client(url, clientId) as PahoClient;

client.onMessageArrived = ({
Expand All @@ -201,7 +203,7 @@ export class MqttOverWS extends AbstractPubSub<MqttOptions> {
this.connectionStateMonitor.record(CONNECTION_CHANGE.CLOSED);
};

const connected = await new Promise((resolve, reject) => {
const connected = await new Promise((resolve, _reject) => {
client.connect({
useSSL: this.isSSLEnabled,
mqttVersion: 3,
Expand Down Expand Up @@ -229,8 +231,11 @@ export class MqttOverWS extends AbstractPubSub<MqttOptions> {
clientId: string,
options: MqttOptions = {},
): Promise<PahoClient | undefined> {
return await this.clientsQueue.get(clientId, async clientId => {
const client = await this.newClient({ ...options, clientId });
return this.clientsQueue.get(clientId, async inputClientId => {
const client = await this.newClient({
...options,
clientId: inputClientId,
});

if (client) {
// Once connected, subscribe to all topics registered observers
Expand Down Expand Up @@ -290,7 +295,6 @@ export class MqttOverWS extends AbstractPubSub<MqttOptions> {
const parsedMessage: PubSubContent = JSON.parse(msg);

if (typeof parsedMessage === 'object') {
// @ts-ignore
parsedMessage[topicSymbol] = topic;
}

Expand Down Expand Up @@ -357,9 +361,11 @@ export class MqttOverWS extends AbstractPubSub<MqttOptions> {
await getClient();

// Add an observable to the reconnection list to manage reconnection for this subscription
reconnectSubscription = new Observable(observer => {
this.reconnectionMonitor.addObserver(observer);
}).subscribe(() => {
reconnectSubscription = new Observable(
reconnectSubscriptionObserver => {
this.reconnectionMonitor.addObserver(reconnectSubscriptionObserver);
},
).subscribe(() => {
getClient();
});
})();
Expand Down
2 changes: 1 addition & 1 deletion packages/pubsub/src/types/PubSub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export enum ConnectionState {
ConnectedPendingKeepAlive = 'ConnectedPendingKeepAlive',
}

export type PubSubContent = Record<string, unknown>;
export type PubSubContent = Record<string | symbol, unknown>;
export type PubSubContentObserver = Observer<PubSubContent>;

export interface PubSubOptions {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

import { Reachability } from '@aws-amplify/core/internals/utils';
import { default as NetInfo } from '@react-native-community/netinfo';
import NetInfo from '@react-native-community/netinfo';

export const ReachabilityMonitor = () =>
new Reachability().networkMonitor(NetInfo);

0 comments on commit 86323c4

Please sign in to comment.