Skip to content

Commit 5f5cffd

Browse files
committed
remove web lock
1 parent bb3649c commit 5f5cffd

File tree

1 file changed

+2
-20
lines changed

1 file changed

+2
-20
lines changed

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

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ export class HubConnection {
4949
private _handshakeResolver!: (value?: PromiseLike<{}>) => void;
5050
private _handshakeRejecter!: (reason?: any) => void;
5151
private _stopDuringStartError?: Error;
52-
private _lockResolver!: (value?: PromiseLike<{}>) => void;
5352

5453
private _connectionState: HubConnectionState;
5554
// connectionStarted is tracked independently from connectionState, so we can check if the
@@ -68,7 +67,7 @@ export class HubConnection {
6867

6968
private _freezeEventListener = () =>
7069
{
71-
this._logger.log(LogLevel.Warning, "The page is being frozen, this will likely lead to the connection being closed and messages being lost.");
70+
this._logger.log(LogLevel.Warning, "The page is being frozen, this will likely lead to the connection being closed and messages being lost. For more information see the docs at https://docs.microsoft.com/aspnet/core/signalr/javascript-client#browser-sleeping-tab");
7271
};
7372

7473
/** The server timeout in milliseconds.
@@ -182,23 +181,9 @@ export class HubConnection {
182181

183182
if (Platform.isBrowser) {
184183
if (document) {
184+
// Log when the browser freezes the tab so users know why their connection unexpectedly stopped working
185185
document.addEventListener("freeze", this._freezeEventListener);
186186
}
187-
188-
// Chrome and Edge currently support Web Locks, it's also experimental, so let's be safe and check if the APIs exist
189-
// https://developer.mozilla.org/en-US/docs/Web/API/Web_Locks_API
190-
// This should prevent the browsers from sleeping the tab which would close the connection unexpectedly
191-
if (navigator && (navigator as any).locks && (navigator as any).locks.request) {
192-
const promise = new Promise((res) => {
193-
this._lockResolver = res;
194-
});
195-
196-
// Use a 'shared' lock so multiple tabs to the same site can used the same lock
197-
(navigator as any).locks.request('signalr_client_lock', { mode: "shared" }, () => {
198-
// Keep lock until promise is resolved
199-
return promise;
200-
});
201-
}
202187
}
203188

204189
this._connectionState = HubConnectionState.Connected;
@@ -749,9 +734,6 @@ export class HubConnection {
749734
this._connectionStarted = false;
750735

751736
if (Platform.isBrowser) {
752-
if (this._lockResolver) {
753-
this._lockResolver();
754-
}
755737
if (document) {
756738
document.removeEventListener("freeze", this._freezeEventListener);
757739
}

0 commit comments

Comments
 (0)