Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/pubsub/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
},
"sideEffects": [
"./lib/PubSub.js",
"./lib-esm/PubSub.js"
"./lib-esm/PubSub.js",
"./lib/utils/PatchLocalStorage.js",
"./lib-esm/utils/PatchLocalStorage.js"
],
"publishConfig": {
"access": "public"
Expand Down
4 changes: 4 additions & 0 deletions packages/pubsub/src/Providers/MqttOverWSProvider.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import { reinstateLocalStorageError } from '../utils/PatchLocalStorage';
import * as Paho from 'paho-mqtt';
import { v4 as uuid } from 'uuid';
import Observable, { ZenObservable } from 'zen-observable-ts';
Expand All @@ -20,6 +22,8 @@ import { AMPLIFY_SYMBOL, CONNECTION_STATE_CHANGE } from './constants';

const logger = new Logger('MqttOverWSProvider');

reinstateLocalStorageError();

export function mqttTopicMatch(filter: string, topic: string) {
const filterArray = filter.split('/');
const length = filterArray.length;
Expand Down
29 changes: 29 additions & 0 deletions packages/pubsub/src/utils/PatchLocalStorage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { ConsoleLogger as Logger } from '@aws-amplify/core';

const logger = new Logger('PatchLocalStorage');

let error = undefined;

function patchLocalStorage() {
try {
window.localStorage;
} catch (e) {
logger.error(e);
error = e;
Object.defineProperty(window, 'localStorage', {
value: null,
});
}
}

export function reinstateLocalStorageError() {
if (error) {
Object.defineProperty(window, 'localStorage', {
get: () => {
throw error;
},
});
}
}

patchLocalStorage();