@based/client
Advanced tools
Comparing version 6.7.1 to 6.8.0
import { BasedClient } from '../index.js'; | ||
export declare const cacheId = "/-74rxe8kzryxek07e36yr"; | ||
export declare const forceReload: (client: BasedClient, type: number) => void; | ||
export declare const forceReload: (client: BasedClient, type: number, seqId: number) => void; |
export const cacheId = '/-74rxe8kzryxek07e36yr'; | ||
export const forceReload = (client, type) => { | ||
// clear based cache (extra byte) | ||
// if to background reconnect needs to know if it handled the bust | ||
// add seqId | ||
// keep seqId in mem for 24h ? :/ ? how long | ||
// add seqId on connect after access key | ||
export const forceReload = (client, type, seqId) => { | ||
// 0 = all | ||
// 1 = browser | ||
// 2 = non-browser | ||
if (client.lastForceId === seqId) { | ||
// all good and handled | ||
return; | ||
} | ||
client.lastForceId = seqId; | ||
// prob browser... | ||
if (typeof window !== 'undefined') { | ||
// prob browser... | ||
if (type === 1 || type === 0) { | ||
window.location.href = | ||
window.location.href + cacheId + ~~(Math.random() * 9999); | ||
// seqId is the bust part | ||
window.location.href = window.location.href + cacheId + seqId; | ||
} | ||
@@ -12,0 +22,0 @@ } |
@@ -349,4 +349,4 @@ import { inflateSync } from 'fflate'; | ||
else if (subType === 3) { | ||
// | 4 header | 1 subType | 1 type | ||
forceReload(client, readUint8(buffer, 5, 1)); | ||
// | 4 header | 1 subType | 1 type | 1 seqId | ||
forceReload(client, readUint8(buffer, 5, 1), readUint8(buffer, 6, 1)); | ||
} | ||
@@ -359,5 +359,5 @@ } | ||
// 981 - cannot parse data | ||
console.error(981, err); | ||
console.error(981, err, data); | ||
} | ||
}; | ||
//# sourceMappingURL=index.js.map |
@@ -7,3 +7,5 @@ import { BasedOpts, AuthState, FunctionResponseListeners, Settings, FunctionQueue, ObserveState, ObserveQueue, Cache, GetObserveQueue, GetState, ChannelQueue, ChannelPublishQueue, ChannelState, CallOptions, QueryOptions } from './types/index.js'; | ||
import { BasedChannel } from './channel/index.js'; | ||
import { cacheId } from './incoming/forceReload.js'; | ||
export * from './authState/parseAuthState.js'; | ||
export { cacheId }; | ||
export { AuthState, BasedQuery }; | ||
@@ -13,2 +15,3 @@ export declare class BasedClient extends Emitter { | ||
restFallBack?: Settings['restFallBack']; | ||
lastForceId: number; | ||
storageSize: number; | ||
@@ -15,0 +18,0 @@ maxStorageSize: number; |
@@ -14,2 +14,3 @@ import { BasedOpts, AuthState, FunctionResponseListeners, Settings, FunctionQueue, ObserveState, ObserveQueue, Cache, GetObserveQueue, GetState, ChannelQueue, ChannelPublishQueue, ChannelState, CallOptions, QueryOptions } from './types/index.js'; | ||
restFallBack?: Settings['restFallBack']; | ||
lastForceId: number; | ||
storageSize: number; | ||
@@ -16,0 +17,0 @@ maxStorageSize: number; |
@@ -18,2 +18,3 @@ import connectWebsocket from './websocket/index.js'; | ||
const isBrowser = typeof window !== 'undefined'; | ||
let lastReloadSeqId = -1; | ||
if (isBrowser) { | ||
@@ -25,4 +26,7 @@ if (typeof global === 'undefined') { | ||
if (loc.includes(cacheId)) { | ||
const [url] = loc.split(cacheId); | ||
window.history.replaceState(null, document.title, url); | ||
const [url, lastSeqId] = loc.split(cacheId); | ||
if (lastSeqId) { | ||
lastReloadSeqId = Number(lastSeqId); | ||
window.history.replaceState(null, document.title, url); | ||
} | ||
} | ||
@@ -47,2 +51,4 @@ } | ||
restFallBack; | ||
// --------- Force reconnect | ||
lastForceId = lastReloadSeqId; | ||
// --------- Persistent Storage | ||
@@ -49,0 +55,0 @@ storageSize = 0; |
@@ -8,2 +8,3 @@ export type AuthState = { | ||
type?: string; | ||
t?: 0 | 1; | ||
}; | ||
@@ -10,0 +11,0 @@ export type AuthResponseListeners = { |
@@ -23,4 +23,4 @@ export type GenericObject = { | ||
restFallBack?: { | ||
pollInverval?: number; | ||
pollInterval?: number; | ||
}; | ||
}; |
@@ -10,2 +10,3 @@ import { BasedClient } from '../index.js'; | ||
_r: string; | ||
_t: string; | ||
_om: (x?: any) => void; | ||
@@ -12,0 +13,0 @@ _oe: (x?: any) => void; |
@@ -17,3 +17,3 @@ import fetch from '@based/fetch'; | ||
syncSubs(ws); | ||
}, ws.client.restFallBack.pollInverval ?? 1e3); | ||
}, ws.client.restFallBack.pollInterval ?? 1e3); | ||
} | ||
@@ -34,2 +34,3 @@ }; | ||
_r; | ||
_t; | ||
_om; | ||
@@ -63,3 +64,8 @@ _oe; | ||
} | ||
fetch(this.url + '/' + this._r + '/' + encodeAuthState(this.client.authState), { | ||
fetch(this.url + | ||
'/' + | ||
this._r + | ||
'/' + | ||
this._t + | ||
encodeAuthState(this.client.authState), { | ||
method: 'post', | ||
@@ -66,0 +72,0 @@ body: binary, |
@@ -45,3 +45,3 @@ import urlLoader from './urlLoader.js'; | ||
// remove the logs here | ||
const restPing = (ms = 500, realUrl, connection, fallback) => { | ||
const restPing = (ms = 1000, realUrl, connection, fallback) => { | ||
connection.fallBackTimer = setTimeout(() => { | ||
@@ -119,2 +119,5 @@ if (!connection.disconnected) { | ||
}); | ||
if (reconnect) { | ||
client.authState.t = 1; | ||
} | ||
const ws = (connection.ws = connection.useFallback | ||
@@ -121,0 +124,0 @@ ? new FakeWebsocket(realUrl, connection.useFallback, client) |
{ | ||
"name": "@based/client", | ||
"version": "6.7.1", | ||
"version": "6.8.0", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "scripts": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
218667
3495