Skip to content

Commit bb3649c

Browse files
committed
fix condition
1 parent 073b93c commit bb3649c

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/SignalR/clients/ts/signalr/src/HubConnection.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -185,14 +185,14 @@ export class HubConnection {
185185
document.addEventListener("freeze", this._freezeEventListener);
186186
}
187187

188-
const promise = new Promise((res) => {
189-
this._lockResolver = res;
190-
});
191-
192188
// Chrome and Edge currently support Web Locks, it's also experimental, so let's be safe and check if the APIs exist
193189
// https://developer.mozilla.org/en-US/docs/Web/API/Web_Locks_API
194190
// This should prevent the browsers from sleeping the tab which would close the connection unexpectedly
195191
if (navigator && (navigator as any).locks && (navigator as any).locks.request) {
192+
const promise = new Promise((res) => {
193+
this._lockResolver = res;
194+
});
195+
196196
// Use a 'shared' lock so multiple tabs to the same site can used the same lock
197197
(navigator as any).locks.request('signalr_client_lock', { mode: "shared" }, () => {
198198
// Keep lock until promise is resolved
@@ -748,8 +748,10 @@ export class HubConnection {
748748
this._connectionState = HubConnectionState.Disconnected;
749749
this._connectionStarted = false;
750750

751-
this._lockResolver();
752751
if (Platform.isBrowser) {
752+
if (this._lockResolver) {
753+
this._lockResolver();
754+
}
753755
if (document) {
754756
document.removeEventListener("freeze", this._freezeEventListener);
755757
}

0 commit comments

Comments
 (0)