Skip to content

Commit 033ec52

Browse files
authored
Merge pull request #74 from bumi/remove-window-dependency
remove global window and localStorage dependecy
2 parents 5be4484 + 0b312e8 commit 033ec52

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

lib/lnc.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export default class LNC {
6565
}
6666

6767
private get wasm() {
68-
return window[this._namespace] as WasmGlobal;
68+
return globalThis[this._namespace] as WasmGlobal;
6969
}
7070

7171
get isReady() {
@@ -195,7 +195,11 @@ export default class LNC {
195195
);
196196

197197
// add an event listener to disconnect if the page is unloaded
198-
window.addEventListener('unload', this.wasm.wasmClientDisconnect);
198+
if (typeof window !== "undefined") {
199+
window.addEventListener('unload', this.wasm.wasmClientDisconnect);
200+
} else {
201+
log.info("No unload event listener added. window is not available");
202+
}
199203

200204
// repeatedly check if the connection was successful
201205
return new Promise<void>((resolve, reject) => {

lib/util/encryption.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export const generateSalt = () => {
66
const validChars =
77
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
88
let array = new Uint8Array(32);
9-
window.crypto.getRandomValues(array);
9+
globalThis.crypto.getRandomValues(array);
1010
array = array.map((x) => validChars.charCodeAt(x % validChars.length));
1111
const salt = String.fromCharCode.apply(null, array as any);
1212
return salt;

lib/util/log.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ export class Logger {
2727
// by default, log nothing (assuming prod)
2828
let level = LogLevel.none;
2929

30-
if (localStorage && localStorage.getItem('debug')) {
30+
if (globalThis.localStorage && globalThis.localStorage.getItem('debug')) {
3131
// if a 'debug' key is found in localStorage, use the level in storage or 'debug' by default
32-
const storageLevel = localStorage.getItem('debug-level') || 'debug';
32+
const storageLevel = globalThis.localStorage.getItem('debug-level') || 'debug';
3333
level = LogLevel[storageLevel as keyof typeof LogLevel];
3434
}
3535

0 commit comments

Comments
 (0)