@vuu-ui/vuu-data-remote 0.13.74 → 0.13.75
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/ConnectionManager.js +2 -0
- package/cjs/ConnectionManager.js.map +1 -1
- package/cjs/DedicatedWorker.js +5 -0
- package/cjs/DedicatedWorker.js.map +1 -1
- package/cjs/WebSocketConnection.js.map +1 -1
- package/cjs/inlined-worker.js +5 -7
- package/cjs/inlined-worker.js.map +1 -1
- package/esm/ConnectionManager.js +2 -0
- package/esm/ConnectionManager.js.map +1 -1
- package/esm/DedicatedWorker.js +5 -0
- package/esm/DedicatedWorker.js.map +1 -1
- package/esm/WebSocketConnection.js.map +1 -1
- package/esm/inlined-worker.js +5 -7
- package/esm/inlined-worker.js.map +1 -1
- package/package.json +7 -7
- package/types/ConnectionManager.d.ts +2 -2
- package/types/DedicatedWorker.d.ts +2 -1
- package/types/WebSocketConnection.d.ts +6 -2
- package/types/inlined-worker.d.ts +1 -1
- package/types/server-proxy/server-proxy.d.ts +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConnectionManager.js","sources":["../../../packages/vuu-data-remote/src/ConnectionManager.ts"],"sourcesContent":["import {\n ConnectOptions,\n DataSourceCallbackMessage,\n ServerAPI,\n ServerProxySubscribeMessage,\n TableSchema,\n VuuUIMessageIn,\n} from \"@vuu-ui/vuu-data-types\";\nimport {\n SelectRequest,\n SelectResponse,\n VuuCreateVisualLink,\n VuuLoginResponse,\n VuuRemoveVisualLink,\n VuuRpcMenuRequest,\n VuuRpcServiceRequest,\n VuuTableList,\n VuuTableListRequest,\n VuuTableMetaRequest,\n} from \"@vuu-ui/vuu-protocol-types\";\nimport {\n DeferredPromise,\n EventEmitter,\n isConnectionQualityMetrics,\n isLoginResponse,\n isRequestResponse,\n isTableSchemaMessage,\n messageHasResult,\n uuid,\n} from \"@vuu-ui/vuu-utils\";\nimport {\n WebSocketConnectionEvents,\n WebSocketConnectionState,\n isWebSocketConnectionMessage,\n} from \"./WebSocketConnection\";\nimport { DedicatedWorker } from \"./DedicatedWorker\";\nimport { shouldMessageBeRoutedToDataSource } from \"./data-source\";\n\nimport { ConnectionQualityMetrics } from \"@vuu-ui/vuu-data-types\";\n\nexport type PostMessageToClientCallback = (\n msg: DataSourceCallbackMessage,\n) => void;\n\nexport type ConnectionEvents = WebSocketConnectionEvents & {\n \"connection-metrics\": (message: ConnectionQualityMetrics) => void;\n \"session-status\": (loginResponse: VuuLoginResponse) => void;\n};\n\ntype RegisteredViewport = {\n postMessageToClientDataSource: PostMessageToClientCallback;\n request: ServerProxySubscribeMessage;\n status: \"subscribing\";\n};\n\nclass ConnectionManager extends EventEmitter<ConnectionEvents> {\n #connectionState: WebSocketConnectionState = {\n connectionPhase: \"connecting\",\n connectionStatus: \"closed\",\n retryAttemptsTotal: -1,\n retryAttemptsRemaining: -1,\n secondsToNextRetry: -1,\n };\n static #instance: ConnectionManager;\n #deferredServerAPI = new DeferredPromise<ServerAPI>();\n #pendingRequests = new Map();\n #viewports = new Map<string, RegisteredViewport>();\n // #worker?: Worker;\n #worker: DedicatedWorker;\n\n private constructor() {\n super();\n this.#worker = new DedicatedWorker(this.handleMessageFromWorker);\n }\n\n public static get instance(): ConnectionManager {\n if (!ConnectionManager.#instance) {\n ConnectionManager.#instance = new ConnectionManager();\n }\n return ConnectionManager.#instance;\n }\n\n /**\n * Open a connection to the VuuServer. This method opens the websocket connection\n * and logs in. It can be called from whichever client code has access to the auth\n * token (eg. the login page, or just a hardcoded login script in a sample).\n * This will unblock any DataSources which may have already tried to subscribe to data,\n * but lacked access to the auth token.\n *\n * @param serverUrl\n * @param token\n */\n async connect(options: ConnectOptions, throwOnRejected = false) {\n const result = await this.#worker.connect(options);\n if (result === \"connected\") {\n this.#deferredServerAPI.resolve(this.connectedServerAPI);\n } else if (result === \"rejected\" && throwOnRejected) {\n throw Error(\"[ConnectionManager] connection rejected\");\n }\n return result;\n }\n\n private handleMessageFromWorker = (\n message: VuuUIMessageIn | DataSourceCallbackMessage,\n ) => {\n if (shouldMessageBeRoutedToDataSource(message)) {\n const viewport = this.#viewports.get(message.clientViewportId);\n if (viewport) {\n viewport.postMessageToClientDataSource(message);\n } else {\n console.error(\n `[ConnectionManager] ${message.type} message received, viewport not found`,\n );\n }\n } else if (isLoginResponse(message)) {\n this.emit(\"session-status\", message);\n } else if (isWebSocketConnectionMessage(message)) {\n this.#connectionState = message;\n this.emit(\"connection-status\", message);\n } else if (isConnectionQualityMetrics(message)) {\n this.emit(\"connection-metrics\", message);\n } else if (isRequestResponse(message)) {\n const { requestId } = message;\n if (this.#pendingRequests.has(requestId)) {\n const { resolve } = this.#pendingRequests.get(requestId);\n this.#pendingRequests.delete(requestId);\n const { requestId: _, ...messageWithoutRequestId } = message;\n\n if (messageHasResult(message)) {\n resolve(message.result);\n } else if (\n message.type === \"VP_EDIT_RPC_RESPONSE\" ||\n message.type === \"VP_EDIT_RPC_REJECT\"\n ) {\n resolve(message);\n } else if (isTableSchemaMessage(message)) {\n resolve(message.tableSchema);\n } else {\n resolve(messageWithoutRequestId);\n }\n } else {\n console.warn(\n \"%cConnectionManager Unexpected message from the worker\",\n \"color:red;font-weight:bold;\",\n );\n }\n }\n };\n\n get connectionStatus() {\n return this.#connectionState.connectionStatus;\n }\n\n get serverAPI() {\n return this.#deferredServerAPI.promise;\n }\n\n private connectedServerAPI: ServerAPI = {\n subscribe: (message, callback) => {\n if (this.#viewports.get(message.viewport)) {\n throw Error(\n `ConnectionManager attempting to subscribe with an existing viewport id`,\n );\n }\n // TODO we never use this status\n this.#viewports.set(message.viewport, {\n status: \"subscribing\",\n request: message,\n postMessageToClientDataSource: callback,\n });\n this.#worker.send({ type: \"subscribe\", ...message });\n },\n\n unsubscribe: (viewport) => {\n this.#worker.send({ type: \"unsubscribe\", viewport });\n },\n\n send: (message) => {\n this.#worker.send(message);\n },\n\n destroy: (viewportId?: string) => {\n if (viewportId && this.#viewports.has(viewportId)) {\n this.#viewports.delete(viewportId);\n }\n },\n\n rpcCall: async <T = unknown>(\n message:\n | VuuRpcServiceRequest\n | VuuRpcMenuRequest\n | VuuCreateVisualLink\n | VuuRemoveVisualLink,\n ) => this.asyncRequest<T>(message),\n\n select: async (selectRequest: SelectRequest) =>\n this.asyncRequest<SelectResponse>(selectRequest),\n\n getTableList: async () =>\n this.asyncRequest<VuuTableList>({ type: \"GET_TABLE_LIST\" }),\n\n getTableSchema: async (table) =>\n this.asyncRequest<TableSchema>({\n type: \"GET_TABLE_META\",\n table,\n }),\n };\n\n private asyncRequest = <T = unknown>(\n msg:\n | VuuRpcServiceRequest\n | VuuRpcMenuRequest\n | VuuTableListRequest\n | VuuTableMetaRequest\n | VuuCreateVisualLink\n | VuuRemoveVisualLink\n | SelectRequest,\n ): Promise<T> => {\n const requestId = uuid();\n this.#worker.send({\n requestId,\n ...msg,\n });\n return new Promise((resolve, reject) => {\n this.#pendingRequests.set(requestId, { resolve, reject });\n });\n };\n\n async disconnect() {\n try {\n this.#worker.send({ type: \"disconnect\" });\n this.#deferredServerAPI = new DeferredPromise<ServerAPI>();\n return \"disconnected\";\n } catch (err: unknown) {\n return \"rejected\";\n }\n }\n\n destroy() {\n this.#worker.terminate();\n }\n}\n\nexport default ConnectionManager.instance;\n"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,IAAA,gBAAA,EAAA,SAAA,EAAA,kBAAA,EAAA,gBAAA,EAAA,UAAA,EAAA,OAAA;AAuDA,MAAM,kBAAA,GAAN,MAAM,kBAAA,SAA0B,YAA+B,CAAA;AAAA,EAerD,WAAc,GAAA;AACpB,IAAM,KAAA,EAAA;AAfR,IAA6C,YAAA,CAAA,IAAA,EAAA,gBAAA,EAAA;AAAA,MAC3C,eAAiB,EAAA,YAAA;AAAA,MACjB,gBAAkB,EAAA,QAAA;AAAA,MAClB,kBAAoB,EAAA,CAAA,CAAA;AAAA,MACpB,sBAAwB,EAAA,CAAA,CAAA;AAAA,MACxB,kBAAoB,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AAmB,CAAA,CAAA,OAAA;AAAA;AACjC,EAyEA,MAAM,UAAa,GAAA;AACjB,IAAI,IAAA;AACF,MAAA,YAAA,CAAA,IAAA,EAAK,OAAQ,CAAA,CAAA,IAAA,CAAK,EAAE,IAAA,EAAM,cAAc,CAAA;AACxC,MAAK,YAAA,CAAA,IAAA,EAAA,kBAAA,EAAqB,IAAI,eAA2B,EAAA,CAAA;AACzD,MAAO,OAAA,cAAA;AAAA,aACA,GAAc,EAAA;AACrB,MAAO,OAAA,UAAA;AAAA;AACT;AACF,EAEA,OAAU,GAAA;AACR,IAAA,YAAA,CAAA,IAAA,EAAK,SAAQ,SAAU,EAAA;AAAA;AAE3B,CAAA;AAzLE,gBAAA,GAAA,IAAA,OAAA,EAAA;AAOO,SAAA,GAAA,IAAA,OAAA,EAAA;AACP,kBAAA,GAAA,IAAA,OAAA,EAAA;AACA,gBAAA,GAAA,IAAA,OAAA,EAAA;AACA,UAAA,GAAA,IAAA,OAAA,EAAA;AAEA,OAAA,GAAA,IAAA,OAAA,EAAA;AALA,YAAA,CARI,kBAQG,EAAA,SAAA,CAAA;AART,IAAM,iBAAN,GAAA,kBAAA;AA4LA,0BAAe,iBAAkB,CAAA,QAAA;;;;"}
|
|
1
|
+
{"version":3,"file":"ConnectionManager.js","sources":["../../../packages/vuu-data-remote/src/ConnectionManager.ts"],"sourcesContent":["import {\n ConnectOptions,\n DataSourceCallbackMessage,\n ServerAPI,\n ServerProxySubscribeMessage,\n TableSchema,\n VuuUIMessageIn,\n} from \"@vuu-ui/vuu-data-types\";\nimport {\n SelectRequest,\n SelectResponse,\n VuuCreateVisualLink,\n VuuLoginResponse,\n VuuRemoveVisualLink,\n VuuRpcMenuRequest,\n VuuRpcServiceRequest,\n VuuTableList,\n VuuTableListRequest,\n VuuTableMetaRequest,\n} from \"@vuu-ui/vuu-protocol-types\";\nimport {\n DeferredPromise,\n EventEmitter,\n isConnectionQualityMetrics,\n isLoginResponse,\n isRequestResponse,\n isTableSchemaMessage,\n messageHasResult,\n uuid,\n} from \"@vuu-ui/vuu-utils\";\nimport {\n WebSocketCloseMessage,\n WebSocketConnectionEvents,\n WebSocketConnectionState,\n isWebSocketConnectionMessage,\n} from \"./WebSocketConnection\";\nimport { DedicatedWorker } from \"./DedicatedWorker\";\nimport { shouldMessageBeRoutedToDataSource } from \"./data-source\";\n\nimport { ConnectionQualityMetrics } from \"@vuu-ui/vuu-data-types\";\n\nexport type PostMessageToClientCallback = (\n msg: DataSourceCallbackMessage,\n) => void;\n\nexport type ConnectionEvents = WebSocketConnectionEvents & {\n \"connection-metrics\": (message: ConnectionQualityMetrics) => void;\n \"session-status\": (\n loginResponse: VuuLoginResponse | WebSocketCloseMessage,\n ) => void;\n};\n\ntype RegisteredViewport = {\n postMessageToClientDataSource: PostMessageToClientCallback;\n request: ServerProxySubscribeMessage;\n status: \"subscribing\";\n};\n\nclass ConnectionManager extends EventEmitter<ConnectionEvents> {\n #connectionState: WebSocketConnectionState = {\n connectionPhase: \"connecting\",\n connectionStatus: \"closed\",\n retryAttemptsTotal: -1,\n retryAttemptsRemaining: -1,\n secondsToNextRetry: -1,\n };\n static #instance: ConnectionManager;\n #deferredServerAPI = new DeferredPromise<ServerAPI>();\n #pendingRequests = new Map();\n #viewports = new Map<string, RegisteredViewport>();\n // #worker?: Worker;\n #worker: DedicatedWorker;\n\n private constructor() {\n super();\n this.#worker = new DedicatedWorker(this.handleMessageFromWorker);\n }\n\n public static get instance(): ConnectionManager {\n if (!ConnectionManager.#instance) {\n ConnectionManager.#instance = new ConnectionManager();\n }\n return ConnectionManager.#instance;\n }\n\n /**\n * Open a connection to the VuuServer. This method opens the websocket connection\n * and logs in. It can be called from whichever client code has access to the auth\n * token (eg. the login page, or just a hardcoded login script in a sample).\n * This will unblock any DataSources which may have already tried to subscribe to data,\n * but lacked access to the auth token.\n *\n * @param serverUrl\n * @param token\n */\n async connect(options: ConnectOptions, throwOnRejected = false) {\n const result = await this.#worker.connect(options);\n if (result === \"connected\") {\n this.#deferredServerAPI.resolve(this.connectedServerAPI);\n } else if (result === \"rejected\" && throwOnRejected) {\n throw Error(\"[ConnectionManager] connection rejected\");\n }\n return result;\n }\n\n private handleMessageFromWorker = (\n message: VuuUIMessageIn | DataSourceCallbackMessage | WebSocketCloseMessage,\n ) => {\n if (shouldMessageBeRoutedToDataSource(message)) {\n const viewport = this.#viewports.get(message.clientViewportId);\n if (viewport) {\n viewport.postMessageToClientDataSource(message);\n } else {\n console.error(\n `[ConnectionManager] ${message.type} message received, viewport not found`,\n );\n }\n } else if (message.type === \"websocket-closed\") {\n this.emit(\"session-status\", message);\n } else if (isLoginResponse(message)) {\n this.emit(\"session-status\", message);\n } else if (isWebSocketConnectionMessage(message)) {\n this.#connectionState = message;\n this.emit(\"connection-status\", message);\n } else if (isConnectionQualityMetrics(message)) {\n this.emit(\"connection-metrics\", message);\n } else if (isRequestResponse(message)) {\n const { requestId } = message;\n if (this.#pendingRequests.has(requestId)) {\n const { resolve } = this.#pendingRequests.get(requestId);\n this.#pendingRequests.delete(requestId);\n const { requestId: _, ...messageWithoutRequestId } = message;\n\n if (messageHasResult(message)) {\n resolve(message.result);\n } else if (\n message.type === \"VP_EDIT_RPC_RESPONSE\" ||\n message.type === \"VP_EDIT_RPC_REJECT\"\n ) {\n resolve(message);\n } else if (isTableSchemaMessage(message)) {\n resolve(message.tableSchema);\n } else {\n resolve(messageWithoutRequestId);\n }\n } else {\n console.warn(\n \"%cConnectionManager Unexpected message from the worker\",\n \"color:red;font-weight:bold;\",\n );\n }\n }\n };\n\n get connectionStatus() {\n return this.#connectionState.connectionStatus;\n }\n\n get serverAPI() {\n return this.#deferredServerAPI.promise;\n }\n\n private connectedServerAPI: ServerAPI = {\n subscribe: (message, callback) => {\n if (this.#viewports.get(message.viewport)) {\n throw Error(\n `ConnectionManager attempting to subscribe with an existing viewport id`,\n );\n }\n // TODO we never use this status\n this.#viewports.set(message.viewport, {\n status: \"subscribing\",\n request: message,\n postMessageToClientDataSource: callback,\n });\n this.#worker.send({ type: \"subscribe\", ...message });\n },\n\n unsubscribe: (viewport) => {\n this.#worker.send({ type: \"unsubscribe\", viewport });\n },\n\n send: (message) => {\n this.#worker.send(message);\n },\n\n destroy: (viewportId?: string) => {\n if (viewportId && this.#viewports.has(viewportId)) {\n this.#viewports.delete(viewportId);\n }\n },\n\n rpcCall: async <T = unknown>(\n message:\n | VuuRpcServiceRequest\n | VuuRpcMenuRequest\n | VuuCreateVisualLink\n | VuuRemoveVisualLink,\n ) => this.asyncRequest<T>(message),\n\n select: async (selectRequest: SelectRequest) =>\n this.asyncRequest<SelectResponse>(selectRequest),\n\n getTableList: async () =>\n this.asyncRequest<VuuTableList>({ type: \"GET_TABLE_LIST\" }),\n\n getTableSchema: async (table) =>\n this.asyncRequest<TableSchema>({\n type: \"GET_TABLE_META\",\n table,\n }),\n };\n\n private asyncRequest = <T = unknown>(\n msg:\n | VuuRpcServiceRequest\n | VuuRpcMenuRequest\n | VuuTableListRequest\n | VuuTableMetaRequest\n | VuuCreateVisualLink\n | VuuRemoveVisualLink\n | SelectRequest,\n ): Promise<T> => {\n const requestId = uuid();\n this.#worker.send({\n requestId,\n ...msg,\n });\n return new Promise((resolve, reject) => {\n this.#pendingRequests.set(requestId, { resolve, reject });\n });\n };\n\n async disconnect() {\n try {\n this.#worker.send({ type: \"disconnect\" });\n this.#deferredServerAPI = new DeferredPromise<ServerAPI>();\n return \"disconnected\";\n } catch (err: unknown) {\n return \"rejected\";\n }\n }\n\n destroy() {\n this.#worker.terminate();\n }\n}\n\nexport default ConnectionManager.instance;\n"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,IAAA,gBAAA,EAAA,SAAA,EAAA,kBAAA,EAAA,gBAAA,EAAA,UAAA,EAAA,OAAA;AA0DA,MAAM,kBAAA,GAAN,MAAM,kBAAA,SAA0B,YAA+B,CAAA;AAAA,EAerD,WAAc,GAAA;AACpB,IAAM,KAAA,EAAA;AAfR,IAA6C,YAAA,CAAA,IAAA,EAAA,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AkB,CAAA;AAAA,KACzD,MAAA,IAAW,MAAW,KAAA,UAAA,IAAc,eAAiB,EAAA;AACnD,MAAA,MAAM,MAAM,yCAAyC,CAAA;AAAA;AAEvD,IAAO,OAAA,MAAA;AAAA;AACT,EAmDA,IAAI,gBAAmB,GAAA;AACrB,IAAA,OAAO,mBAAK,gBAAiB,CAAA,CAAA,gBAAA;AAAA;AAC/B,EAEA,IAAI,SAAY,GAAA;AACd,IAAA,OAAO,mBAAK,kBAAmB,CAAA,CAAA,OAAA;AAAA;AACjC,EAyEA,MAAM,UAAa,GAAA;AACjB,IAAI,IAAA;AACF,MAAA,YAAA,CAAA,IAAA,EAAK,OAAQ,CAAA,CAAA,IAAA,CAAK,EAAE,IAAA,EAAM,cAAc,CAAA;AACxC,MAAK,YAAA,CAAA,IAAA,EAAA,kBAAA,EAAqB,IAAI,eAA2B,EAAA,CAAA;AACzD,MAAO,OAAA,cAAA;AAAA,aACA,GAAc,EAAA;AACrB,MAAO,OAAA,UAAA;AAAA;AACT;AACF,EAEA,OAAU,GAAA;AACR,IAAA,YAAA,CAAA,IAAA,EAAK,SAAQ,SAAU,EAAA;AAAA;AAE3B,CAAA;AA3LE,gBAAA,GAAA,IAAA,OAAA,EAAA;AAOO,SAAA,GAAA,IAAA,OAAA,EAAA;AACP,kBAAA,GAAA,IAAA,OAAA,EAAA;AACA,gBAAA,GAAA,IAAA,OAAA,EAAA;AACA,UAAA,GAAA,IAAA,OAAA,EAAA;AAEA,OAAA,GAAA,IAAA,OAAA,EAAA;AALA,YAAA,CARI,kBAQG,EAAA,SAAA,CAAA;AART,IAAM,iBAAN,GAAA,kBAAA;AA8LA,0BAAe,iBAAkB,CAAA,QAAA;;;;"}
|
package/esm/DedicatedWorker.js
CHANGED
|
@@ -32,6 +32,11 @@ class DedicatedWorker {
|
|
|
32
32
|
__privateGet(this, _deferredConnection)?.resolve("connected");
|
|
33
33
|
} else if (message.type === "connection-failed") {
|
|
34
34
|
__privateGet(this, _deferredConnection)?.resolve("rejected");
|
|
35
|
+
} else if (message.type === "websocket-closed") {
|
|
36
|
+
if (message.reason === "token-expired") {
|
|
37
|
+
console.log(`websocket closed ${message.reason}`);
|
|
38
|
+
onMessage(message);
|
|
39
|
+
}
|
|
35
40
|
} else {
|
|
36
41
|
onMessage(message);
|
|
37
42
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DedicatedWorker.js","sources":["../../../packages/vuu-data-remote/src/DedicatedWorker.ts"],"sourcesContent":["import {\n ConnectOptions,\n VuuUIMessageIn,\n VuuUIMessageOut,\n WithRequestId,\n} from \"@vuu-ui/vuu-data-types\";\nimport { DeferredPromise, getLoggingConfigForWorker } from \"@vuu-ui/vuu-utils\";\n\n// Note: inlined-worker is a generated file, it must be built\nimport { workerSourceCode } from \"./inlined-worker\";\nimport {\n SelectRequest,\n VuuCreateVisualLink,\n VuuRemoveVisualLink,\n VuuRpcMenuRequest,\n VuuRpcServiceRequest,\n} from \"@vuu-ui/vuu-protocol-types\";\n\nconst workerBlob = new Blob([getLoggingConfigForWorker() + workerSourceCode], {\n type: \"text/javascript\",\n});\nconst workerBlobUrl = URL.createObjectURL(workerBlob);\n\nexport class DedicatedWorker {\n #deferredConnection?: DeferredPromise<\n \"connected\" | \"reconnected\" | \"rejected\"\n >;\n #worker: Promise<Worker>;\n\n constructor(onMessage: (msg: VuuUIMessageIn) => void) {\n const deferredWorker = new DeferredPromise<Worker>();\n this.#worker = deferredWorker.promise;\n const worker = new Worker(workerBlobUrl);\n const timer: number | null = window.setTimeout(() => {\n console.warn(\"timed out waiting for worker to load\");\n }, 1000);\n worker.onmessage = (msg: MessageEvent<VuuUIMessageIn
|
|
1
|
+
{"version":3,"file":"DedicatedWorker.js","sources":["../../../packages/vuu-data-remote/src/DedicatedWorker.ts"],"sourcesContent":["import {\n ConnectOptions,\n VuuUIMessageIn,\n VuuUIMessageOut,\n WithRequestId,\n} from \"@vuu-ui/vuu-data-types\";\nimport { DeferredPromise, getLoggingConfigForWorker } from \"@vuu-ui/vuu-utils\";\n\n// Note: inlined-worker is a generated file, it must be built\nimport { workerSourceCode } from \"./inlined-worker\";\nimport {\n SelectRequest,\n VuuCreateVisualLink,\n VuuRemoveVisualLink,\n VuuRpcMenuRequest,\n VuuRpcServiceRequest,\n} from \"@vuu-ui/vuu-protocol-types\";\nimport { WebSocketCloseMessage } from \"./WebSocketConnection\";\n\nconst workerBlob = new Blob([getLoggingConfigForWorker() + workerSourceCode], {\n type: \"text/javascript\",\n});\nconst workerBlobUrl = URL.createObjectURL(workerBlob);\n\nexport class DedicatedWorker {\n #deferredConnection?: DeferredPromise<\n \"connected\" | \"reconnected\" | \"rejected\"\n >;\n #worker: Promise<Worker>;\n\n constructor(\n onMessage: (msg: VuuUIMessageIn | WebSocketCloseMessage) => void,\n ) {\n const deferredWorker = new DeferredPromise<Worker>();\n this.#worker = deferredWorker.promise;\n const worker = new Worker(workerBlobUrl);\n const timer: number | null = window.setTimeout(() => {\n console.warn(\"timed out waiting for worker to load\");\n }, 1000);\n worker.onmessage = (\n msg: MessageEvent<VuuUIMessageIn | WebSocketCloseMessage>,\n ) => {\n const { data: message } = msg;\n if (message.type === \"ready\") {\n window.clearTimeout(timer);\n deferredWorker.resolve(worker);\n } else if (message.type === \"connected\") {\n // how do we detect reconnected\n this.#deferredConnection?.resolve(\"connected\");\n } else if (message.type === \"connection-failed\") {\n this.#deferredConnection?.resolve(\"rejected\");\n // this.#deferredConnection?.reject(message.reason);\n } else if (message.type === \"websocket-closed\") {\n if (message.reason === \"token-expired\") {\n console.log(`websocket closed ${message.reason}`);\n onMessage(message);\n }\n } else {\n onMessage(message);\n }\n };\n }\n\n async connect(options: ConnectOptions) {\n this.#deferredConnection = new DeferredPromise<\n \"connected\" | \"reconnected\" | \"rejected\"\n >();\n this.send({\n ...options,\n type: \"connect\",\n });\n return this.#deferredConnection.promise;\n }\n\n async send(\n message:\n | VuuUIMessageOut\n | WithRequestId<\n | VuuCreateVisualLink\n | VuuRemoveVisualLink\n | VuuRpcServiceRequest\n | VuuRpcMenuRequest\n | SelectRequest\n >,\n ) {\n (await this.#worker).postMessage(message);\n }\n\n async terminate() {\n (await this.#worker).terminate();\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;AAAA,IAAA,mBAAA,EAAA,OAAA;AAmBA,MAAM,aAAa,IAAI,IAAA,CAAK,CAAC,yBAA0B,EAAA,GAAI,gBAAgB,CAAG,EAAA;AAAA,EAC5E,IAAM,EAAA;AACR,CAAC,CAAA;AACD,MAAM,aAAA,GAAgB,GAAI,CAAA,eAAA,CAAgB,UAAU,CAAA;AAE7C,MAAM,eAAgB,CAAA;AAAA,EAM3B,YACE,SACA,EAAA;AAPF,IAAA,YAAA,CAAA,IAAA,EAAA,mBAAA,CAAA;AAGA,IAAA,YAAA,CAAA,IAAA,EAAA,OAAA,CAAA;AAKE,IAAM,MAAA,cAAA,GAAiB,IAAI,eAAwB,EAAA;AACnD,IAAA,YAAA,CAAA,IAAA,EAAK,SAAU,cAAe,CAAA,OAAA,CAAA;AAC9B,IAAM,MAAA,MAAA,GAAS,IAAI,MAAA,CAAO,aAAa,CAAA;AACvC,IAAM,MAAA,KAAA,GAAuB,MAAO,CAAA,UAAA,CAAW,MAAM;AACnD,MAAA,OAAA,CAAQ,KAAK,sCAAsC,CAAA;AAAA,OAClD,GAAI,CAAA;AACP,IAAO,MAAA,CAAA,SAAA,GAAY,CACjB,GACG,KAAA;AACH,MAAM,MAAA,EAAE,IAAM,EAAA,OAAA,EAAY,GAAA,GAAA;AAC1B,MAAI,IAAA,OAAA,CAAQ,SAAS,OAAS,EAAA;AAC5B,QAAA,MAAA,CAAO,aAAa,KAAK,CAAA;AACzB,QAAA,cAAA,CAAe,QAAQ,MAAM,CAAA;AAAA,OAC/B,MAAA,IAAW,OAAQ,CAAA,IAAA,KAAS,WAAa,EAAA;AAEvC,QAAK,YAAA,CAAA,IAAA,EAAA,mBAAA,CAAA,EAAqB,QAAQ,WAAW,CAAA;AAAA,OAC/C,MAAA,IAAW,OAAQ,CAAA,IAAA,KAAS,mBAAqB,EAAA;AAC/C,QAAK,YAAA,CAAA,IAAA,EAAA,mBAAA,CAAA,EAAqB,QAAQ,UAAU,CAAA;AAAA,OAE9C,MAAA,IAAW,OAAQ,CAAA,IAAA,KAAS,kBAAoB,EAAA;AAC9C,QAAI,IAAA,OAAA,CAAQ,WAAW,eAAiB,EAAA;AACtC,UAAA,OAAA,CAAQ,GAAI,CAAA,CAAA,iBAAA,EAAoB,OAAQ,CAAA,MAAM,CAAE,CAAA,CAAA;AAChD,UAAA,SAAA,CAAU,OAAO,CAAA;AAAA;AACnB,OACK,MAAA;AACL,QAAA,SAAA,CAAU,OAAO,CAAA;AAAA;AACnB,KACF;AAAA;AACF,EAEA,MAAM,QAAQ,OAAyB,EAAA;AACrC,IAAK,YAAA,CAAA,IAAA,EAAA,mBAAA,EAAsB,IAAI,eAE7B,EAAA,CAAA;AACF,IAAA,IAAA,CAAK,IAAK,CAAA;AAAA,MACR,GAAG,OAAA;AAAA,MACH,IAAM,EAAA;AAAA,KACP,CAAA;AACD,IAAA,OAAO,mBAAK,mBAAoB,CAAA,CAAA,OAAA;AAAA;AAClC,EAEA,MAAM,KACJ,OASA,EAAA;AACA,IAAA,CAAC,MAAM,YAAA,CAAA,IAAA,EAAK,OAAS,CAAA,EAAA,WAAA,CAAY,OAAO,CAAA;AAAA;AAC1C,EAEA,MAAM,SAAY,GAAA;AAChB,IAAC,CAAA,MAAM,YAAK,CAAA,IAAA,EAAA,OAAA,CAAA,EAAS,SAAU,EAAA;AAAA;AAEnC;AAlEE,mBAAA,GAAA,IAAA,OAAA,EAAA;AAGA,OAAA,GAAA,IAAA,OAAA,EAAA;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WebSocketConnection.js","sources":["../../../packages/vuu-data-remote/src/WebSocketConnection.ts"],"sourcesContent":["import { WebSocketProtocol } from \"@vuu-ui/vuu-data-types\";\nimport { VuuClientMessage, VuuServerMessage } from \"@vuu-ui/vuu-protocol-types\";\nimport { DeferredPromise, EventEmitter, logger } from \"@vuu-ui/vuu-utils\";\n\nexport type ConnectingStatus = \"connecting\" | \"reconnecting\";\nexport type ConnectedStatus = \"connected\" | \"reconnected\";\nexport type ConnectionStatus =\n | ConnectedStatus\n | \"closed\"\n | \"connection-open-awaiting-session\"\n | \"disconnected\"\n | \"failed\"\n | \"inactive\";\n\ntype InternalConnectionStatus = ConnectionStatus | ConnectingStatus;\n\ntype ReconnectAttempts = {\n retryAttemptsTotal: number;\n retryAttemptsRemaining: number;\n secondsToNextRetry: number;\n};\n\nexport interface WebSocketConnectionState<\n T extends InternalConnectionStatus = ConnectionStatus,\n> extends ReconnectAttempts {\n connectionPhase: ConnectingStatus;\n connectionStatus: T;\n}\n\nconst { debug, debugEnabled, info } = logger(\"WebSocketConnection\");\n\nconst isNotConnecting = (\n connectionState: WebSocketConnectionState<InternalConnectionStatus>,\n): connectionState is WebSocketConnectionState<ConnectionStatus> =>\n connectionState.connectionStatus !== \"connecting\" &&\n connectionState.connectionStatus !== \"reconnecting\";\n\nexport const isWebSocketConnectionMessage = (\n msg: object | WebSocketConnectionState,\n): msg is WebSocketConnectionState => {\n if (\"connectionStatus\" in msg) {\n return [\n \"connecting\",\n \"connected\",\n \"connection-open-awaiting-session\",\n \"reconnecting\",\n \"reconnected\",\n \"disconnected\",\n \"closed\",\n \"failed\",\n ].includes(msg.connectionStatus);\n } else {\n return false;\n }\n};\n\nexport const isConnected = (\n status: ConnectionStatus,\n): status is ConnectedStatus =>\n status === \"connected\" || status === \"reconnected\";\n\nexport type VuuServerMessageCallback = (msg: VuuServerMessage) => void;\n\nexport type RetryLimits = {\n connect: number;\n reconnect: number;\n};\n\nexport type WebSocketConnectionConfig = {\n url: string;\n protocols: WebSocketProtocol;\n callback: VuuServerMessageCallback;\n connectionTimeout?: number;\n retryLimits?: RetryLimits;\n};\n\nconst DEFAULT_RETRY_LIMITS: RetryLimits = {\n connect: 5,\n reconnect: 8,\n};\n\nconst DEFAULT_CONNECTION_TIMEOUT = 10000;\n\nconst ConnectingEndState: Record<ConnectingStatus, ConnectedStatus> = {\n connecting: \"connected\",\n reconnecting: \"reconnected\",\n} as const;\n\nconst parseWebSocketMessage = (message: string): VuuServerMessage => {\n try {\n return JSON.parse(message) as VuuServerMessage;\n } catch (e) {\n throw Error(`Error parsing JSON response from server ${message}`);\n }\n};\n\nexport type WebSocketConnectionCloseReason = \"failure\" | \"shutdown\";\nexport type WebSocketConnectionEvents = {\n closed: (reason: WebSocketConnectionCloseReason) => void;\n connected: () => void;\n \"connection-status\": (message: WebSocketConnectionState) => void;\n reconnected: () => void;\n};\n\nexport class WebSocketConnection extends EventEmitter<WebSocketConnectionEvents> {\n #callback;\n /**\n We are not confirmedOpen until we receive the first message from the\n server. If we get an unexpected close event before that, we consider\n the reconnect attempts as still within the connection phase, not true\n reconnection. This can happen e.g. when connecting to remote host via\n a proxy.\n */\n #confirmedOpen = false;\n #connectionState: WebSocketConnectionState<InternalConnectionStatus>;\n #connectionTimeout;\n #deferredConnection?: DeferredPromise;\n #protocols;\n #reconnectAttempts: ReconnectAttempts;\n #requiresLogin = true;\n #url;\n #ws?: WebSocket;\n\n constructor({\n callback,\n connectionTimeout = DEFAULT_CONNECTION_TIMEOUT,\n protocols,\n retryLimits = DEFAULT_RETRY_LIMITS,\n url,\n }: WebSocketConnectionConfig) {\n super();\n\n this.#callback = callback;\n this.#connectionTimeout = connectionTimeout;\n this.#url = url;\n this.#protocols = protocols;\n\n this.#reconnectAttempts = {\n retryAttemptsTotal: retryLimits.reconnect,\n retryAttemptsRemaining: retryLimits.reconnect,\n secondsToNextRetry: 1,\n };\n\n /**\n * Initial retryAttempts are for the 'connecting' phase. These will\n * be replaced with 'reconnecting' phase retry attempts only once\n * initial connection succeeds.\n */\n this.#connectionState = {\n connectionPhase: \"connecting\",\n connectionStatus: \"closed\",\n retryAttemptsTotal: retryLimits.connect,\n retryAttemptsRemaining: retryLimits.connect,\n secondsToNextRetry: 1,\n };\n }\n\n get connectionTimeout() {\n return this.#connectionTimeout;\n }\n\n get protocols() {\n return this.#protocols;\n }\n\n get requiresLogin() {\n return this.#requiresLogin;\n }\n\n get isClosed() {\n return this.status === \"closed\";\n }\n get isDisconnected() {\n return this.status === \"disconnected\";\n }\n\n get isConnecting() {\n return this.#connectionState.connectionPhase === \"connecting\";\n }\n\n get status() {\n return this.#connectionState.connectionStatus;\n }\n\n private set status(connectionStatus: InternalConnectionStatus) {\n this.#connectionState = {\n ...this.#connectionState,\n connectionStatus,\n };\n // we don't publish the connecting states. They have little meaning for clients\n // and are will generally be very short-lived.\n if (isNotConnecting(this.#connectionState)) {\n this.emit(\"connection-status\", this.#connectionState);\n }\n }\n\n get connectionState() {\n return this.#connectionState;\n }\n\n private get hasConnectionAttemptsRemaining() {\n return this.#connectionState.retryAttemptsRemaining > 0;\n }\n\n private get confirmedOpen() {\n return this.#confirmedOpen;\n }\n\n /**\n * We are 'confirmedOpen' when we see the first message transmitted\n * from the server. This ensures that even if we have one or more\n * proxies in our route to the endPoint, all connections have been\n * opened successfully.\n * First time in here (on our initial successful connection) we switch\n * from 'connect' phase to 'reconnect' phase. We may have different\n * retry configurations for these two phases.\n */\n private set confirmedOpen(confirmedOpen: boolean) {\n this.#confirmedOpen = confirmedOpen;\n\n if (confirmedOpen && this.isConnecting) {\n this.#connectionState = {\n ...this.#connectionState,\n connectionPhase: \"reconnecting\",\n ...this.#reconnectAttempts,\n };\n } else if (confirmedOpen) {\n // we have successfully reconnected after a failure.\n // Reset the retry attempts, ready for next failure\n // Note: this retry is shared with 'disconnected' status\n this.#connectionState = {\n ...this.#connectionState,\n ...this.#reconnectAttempts,\n };\n }\n }\n\n get url() {\n return this.#url;\n }\n\n async connect(clientCall = true) {\n const state = this.#connectionState;\n if (this.isConnecting && this.#deferredConnection === undefined) {\n // We block on the first connecting call, this will be the\n // initial connect call from app. Any other calls will be\n // reconnect attempts. The initial connecting call returns a promise.\n // This promise is resolved either on that initial call or on a\n // subsequent successful retry attempt within nthat same initial\n // connecting phase.\n this.#deferredConnection = new DeferredPromise();\n }\n const { connectionTimeout, protocols, url } = this;\n this.status = state.connectionPhase;\n const timer = setTimeout(() => {\n throw Error(\n `Failed to open WebSocket connection to ${url}, timed out after ${connectionTimeout}ms`,\n );\n }, connectionTimeout);\n\n const ws = (this.#ws = new WebSocket(url, protocols));\n\n ws.onopen = () => {\n const connectedStatus = ConnectingEndState[state.connectionPhase];\n this.status = connectedStatus;\n clearTimeout(timer);\n if (this.#deferredConnection) {\n this.#deferredConnection.resolve(undefined);\n this.#deferredConnection = undefined;\n }\n if (this.isConnecting) {\n this.emit(\"connected\");\n } else {\n this.emit(\"reconnected\");\n }\n };\n ws.onerror = () => {\n clearTimeout(timer);\n };\n\n ws.onclose = () => {\n if (!this.isClosed) {\n this.confirmedOpen = false;\n this.status = \"disconnected\";\n if (this.hasConnectionAttemptsRemaining) {\n this.reconnect();\n } else {\n this.close(\"failure\");\n }\n }\n };\n\n ws.onmessage = (evt) => {\n if (!this.confirmedOpen) {\n // Now that we are confirmedOpen any subsequent close events\n // will be treated as part of a reconnection phase.\n this.confirmedOpen = true;\n }\n this.receive(evt);\n };\n\n if (clientCall) {\n return this.#deferredConnection?.promise;\n }\n }\n\n private reconnect() {\n const { retryAttemptsRemaining, secondsToNextRetry } =\n this.#connectionState;\n setTimeout(() => {\n this.#connectionState = {\n ...this.#connectionState,\n retryAttemptsRemaining: retryAttemptsRemaining - 1,\n secondsToNextRetry: secondsToNextRetry * 2,\n };\n this.connect(false);\n }, secondsToNextRetry * 1000);\n }\n\n private receive = (evt: MessageEvent) => {\n if (evt.data === \"Invalid token\") {\n throw Error(\"[WebSocketConnection] Invalid token\");\n } else {\n const vuuMessageFromServer = parseWebSocketMessage(evt.data);\n if (vuuMessageFromServer.body.type === \"CHANGE_VP_RANGE_SUCCESS\") {\n info?.(`CHANGE_VP_RANGE_SUCCESS<#${vuuMessageFromServer.requestId}>`);\n }\n if (debugEnabled) {\n if (vuuMessageFromServer.body.type !== \"HB\") {\n debug(`${vuuMessageFromServer.body.type}`);\n if (vuuMessageFromServer.body.type === \"CHANGE_VP_SUCCESS\") {\n debug(JSON.stringify(vuuMessageFromServer.body));\n }\n }\n }\n this.#callback(vuuMessageFromServer);\n }\n };\n\n send = (msg: VuuClientMessage) => {\n if (msg.body.type === \"CHANGE_VP_RANGE\") {\n info?.(\n `CHANGE_VP_RANGE<#${msg.requestId}> ${msg.body.from}-${msg.body.to}`,\n );\n }\n this.#ws?.send(JSON.stringify(msg));\n };\n\n close(reason: WebSocketConnectionCloseReason = \"shutdown\") {\n this.status = \"closed\";\n if (reason === \"failure\") {\n if (this.#deferredConnection) {\n this.#deferredConnection.reject(Error(\"connection failed\"));\n this.#deferredConnection = undefined;\n }\n } else {\n this.#ws?.close();\n }\n this.emit(\"closed\", reason);\n this.#ws = undefined;\n }\n}\n"],"names":[],"mappings":";;AA6BsC,OAAO,qBAAqB;AAQrD,MAAA,4BAAA,GAA+B,CAC1C,GACoC,KAAA;AACpC,EAAA,IAAI,sBAAsB,GAAK,EAAA;AAC7B,IAAO,OAAA;AAAA,MACL,YAAA;AAAA,MACA,WAAA;AAAA,MACA,kCAAA;AAAA,MACA,cAAA;AAAA,MACA,aAAA;AAAA,MACA,cAAA;AAAA,MACA,QAAA;AAAA,MACA;AAAA,KACF,CAAE,QAAS,CAAA,GAAA,CAAI,gBAAgB,CAAA;AAAA,GAC1B,MAAA;AACL,IAAO,OAAA,KAAA;AAAA;AAEX;AAEO,MAAM,WAAc,GAAA,CACzB,MAEA,KAAA,MAAA,KAAW,eAAe,MAAW,KAAA;;;;"}
|
|
1
|
+
{"version":3,"file":"WebSocketConnection.js","sources":["../../../packages/vuu-data-remote/src/WebSocketConnection.ts"],"sourcesContent":["import { WebSocketProtocol } from \"@vuu-ui/vuu-data-types\";\nimport { VuuClientMessage, VuuServerMessage } from \"@vuu-ui/vuu-protocol-types\";\nimport { DeferredPromise, EventEmitter, logger } from \"@vuu-ui/vuu-utils\";\n\nexport type ConnectingStatus = \"connecting\" | \"reconnecting\";\nexport type ConnectedStatus = \"connected\" | \"reconnected\";\nexport type ConnectionStatus =\n | ConnectedStatus\n | \"closed\"\n | \"connection-open-awaiting-session\"\n | \"disconnected\"\n | \"failed\"\n | \"inactive\";\n\ntype InternalConnectionStatus = ConnectionStatus | ConnectingStatus;\n\ntype ReconnectAttempts = {\n retryAttemptsTotal: number;\n retryAttemptsRemaining: number;\n secondsToNextRetry: number;\n};\n\nexport interface WebSocketConnectionState<\n T extends InternalConnectionStatus = ConnectionStatus,\n> extends ReconnectAttempts {\n connectionPhase: ConnectingStatus;\n connectionStatus: T;\n}\n\nconst { debug, debugEnabled, info } = logger(\"WebSocketConnection\");\n\nconst isNotConnecting = (\n connectionState: WebSocketConnectionState<InternalConnectionStatus>,\n): connectionState is WebSocketConnectionState<ConnectionStatus> =>\n connectionState.connectionStatus !== \"connecting\" &&\n connectionState.connectionStatus !== \"reconnecting\";\n\nexport const isWebSocketConnectionMessage = (\n msg: object | WebSocketConnectionState,\n): msg is WebSocketConnectionState => {\n if (\"connectionStatus\" in msg) {\n return [\n \"connecting\",\n \"connected\",\n \"connection-open-awaiting-session\",\n \"reconnecting\",\n \"reconnected\",\n \"disconnected\",\n \"closed\",\n \"failed\",\n ].includes(msg.connectionStatus);\n } else {\n return false;\n }\n};\n\nexport const isConnected = (\n status: ConnectionStatus,\n): status is ConnectedStatus =>\n status === \"connected\" || status === \"reconnected\";\n\nexport type VuuServerMessageCallback = (msg: VuuServerMessage) => void;\n\nexport type RetryLimits = {\n connect: number;\n reconnect: number;\n};\n\nexport type WebSocketConnectionConfig = {\n url: string;\n protocols: WebSocketProtocol;\n callback: VuuServerMessageCallback;\n connectionTimeout?: number;\n retryLimits?: RetryLimits;\n};\n\nconst DEFAULT_RETRY_LIMITS: RetryLimits = {\n connect: 5,\n reconnect: 8,\n};\n\nconst DEFAULT_CONNECTION_TIMEOUT = 10000;\n\nconst ConnectingEndState: Record<ConnectingStatus, ConnectedStatus> = {\n connecting: \"connected\",\n reconnecting: \"reconnected\",\n} as const;\n\nconst parseWebSocketMessage = (message: string): VuuServerMessage => {\n try {\n return JSON.parse(message) as VuuServerMessage;\n } catch (e) {\n throw Error(`Error parsing JSON response from server ${message}`);\n }\n};\n\nexport type WebSocketCloseMessage = {\n type: \"websocket-closed\";\n reason: WebSocketConnectionCloseReason;\n};\n\nexport type WebSocketConnectionCloseReason =\n | \"failure\"\n | \"shutdown\"\n | \"invalid-token\"\n | \"token-expired\";\nexport type WebSocketConnectionEvents = {\n closed: (message: WebSocketCloseMessage) => void;\n connected: () => void;\n \"connection-status\": (message: WebSocketConnectionState) => void;\n reconnected: () => void;\n};\n\nexport class WebSocketConnection extends EventEmitter<WebSocketConnectionEvents> {\n #callback;\n /**\n We are not confirmedOpen until we receive the first message from the\n server. If we get an unexpected close event before that, we consider\n the reconnect attempts as still within the connection phase, not true\n reconnection. This can happen e.g. when connecting to remote host via\n a proxy.\n */\n #confirmedOpen = false;\n #connectionState: WebSocketConnectionState<InternalConnectionStatus>;\n #connectionTimeout;\n #deferredConnection?: DeferredPromise;\n #protocols;\n #reconnectAttempts: ReconnectAttempts;\n #requiresLogin = true;\n #url;\n #ws?: WebSocket;\n\n constructor({\n callback,\n connectionTimeout = DEFAULT_CONNECTION_TIMEOUT,\n protocols,\n retryLimits = DEFAULT_RETRY_LIMITS,\n url,\n }: WebSocketConnectionConfig) {\n super();\n\n this.#callback = callback;\n this.#connectionTimeout = connectionTimeout;\n this.#url = url;\n this.#protocols = protocols;\n\n this.#reconnectAttempts = {\n retryAttemptsTotal: retryLimits.reconnect,\n retryAttemptsRemaining: retryLimits.reconnect,\n secondsToNextRetry: 1,\n };\n\n /**\n * Initial retryAttempts are for the 'connecting' phase. These will\n * be replaced with 'reconnecting' phase retry attempts only once\n * initial connection succeeds.\n */\n this.#connectionState = {\n connectionPhase: \"connecting\",\n connectionStatus: \"closed\",\n retryAttemptsTotal: retryLimits.connect,\n retryAttemptsRemaining: retryLimits.connect,\n secondsToNextRetry: 1,\n };\n }\n\n get connectionTimeout() {\n return this.#connectionTimeout;\n }\n\n get protocols() {\n return this.#protocols;\n }\n\n get requiresLogin() {\n return this.#requiresLogin;\n }\n\n get isClosed() {\n return this.status === \"closed\";\n }\n get isDisconnected() {\n return this.status === \"disconnected\";\n }\n\n get isConnecting() {\n return this.#connectionState.connectionPhase === \"connecting\";\n }\n\n get status() {\n return this.#connectionState.connectionStatus;\n }\n\n private set status(connectionStatus: InternalConnectionStatus) {\n this.#connectionState = {\n ...this.#connectionState,\n connectionStatus,\n };\n // we don't publish the connecting states. They have little meaning for clients\n // and are will generally be very short-lived.\n if (isNotConnecting(this.#connectionState)) {\n this.emit(\"connection-status\", this.#connectionState);\n }\n }\n\n get connectionState() {\n return this.#connectionState;\n }\n\n private get hasConnectionAttemptsRemaining() {\n return this.#connectionState.retryAttemptsRemaining > 0;\n }\n\n private get confirmedOpen() {\n return this.#confirmedOpen;\n }\n\n /**\n * We are 'confirmedOpen' when we see the first message transmitted\n * from the server. This ensures that even if we have one or more\n * proxies in our route to the endPoint, all connections have been\n * opened successfully.\n * First time in here (on our initial successful connection) we switch\n * from 'connect' phase to 'reconnect' phase. We may have different\n * retry configurations for these two phases.\n */\n private set confirmedOpen(confirmedOpen: boolean) {\n this.#confirmedOpen = confirmedOpen;\n\n if (confirmedOpen && this.isConnecting) {\n this.#connectionState = {\n ...this.#connectionState,\n connectionPhase: \"reconnecting\",\n ...this.#reconnectAttempts,\n };\n } else if (confirmedOpen) {\n // we have successfully reconnected after a failure.\n // Reset the retry attempts, ready for next failure\n // Note: this retry is shared with 'disconnected' status\n this.#connectionState = {\n ...this.#connectionState,\n ...this.#reconnectAttempts,\n };\n }\n }\n\n get url() {\n return this.#url;\n }\n\n async connect(clientCall = true) {\n const state = this.#connectionState;\n if (this.isConnecting && this.#deferredConnection === undefined) {\n // We block on the first connecting call, this will be the\n // initial connect call from app. Any other calls will be\n // reconnect attempts. The initial connecting call returns a promise.\n // This promise is resolved either on that initial call or on a\n // subsequent successful retry attempt within nthat same initial\n // connecting phase.\n this.#deferredConnection = new DeferredPromise();\n }\n const { connectionTimeout, protocols, url } = this;\n this.status = state.connectionPhase;\n const timer = setTimeout(() => {\n throw Error(\n `Failed to open WebSocket connection to ${url}, timed out after ${connectionTimeout}ms`,\n );\n }, connectionTimeout);\n\n const ws = (this.#ws = new WebSocket(url, protocols));\n\n ws.onopen = () => {\n const connectedStatus = ConnectingEndState[state.connectionPhase];\n this.status = connectedStatus;\n clearTimeout(timer);\n if (this.#deferredConnection) {\n this.#deferredConnection.resolve(undefined);\n this.#deferredConnection = undefined;\n }\n if (this.isConnecting) {\n this.emit(\"connected\");\n } else {\n this.emit(\"reconnected\");\n }\n };\n ws.onerror = () => {\n clearTimeout(timer);\n };\n\n ws.onclose = () => {\n if (!this.isClosed) {\n this.confirmedOpen = false;\n this.status = \"disconnected\";\n if (this.hasConnectionAttemptsRemaining) {\n this.reconnect();\n } else {\n this.close(\"failure\");\n }\n }\n };\n\n ws.onmessage = (evt) => {\n if (!this.confirmedOpen) {\n // Now that we are confirmedOpen any subsequent close events\n // will be treated as part of a reconnection phase.\n this.confirmedOpen = true;\n }\n this.receive(evt);\n };\n\n if (clientCall) {\n return this.#deferredConnection?.promise;\n }\n }\n\n private reconnect() {\n const { retryAttemptsRemaining, secondsToNextRetry } =\n this.#connectionState;\n setTimeout(() => {\n this.#connectionState = {\n ...this.#connectionState,\n retryAttemptsRemaining: retryAttemptsRemaining - 1,\n secondsToNextRetry: secondsToNextRetry * 2,\n };\n this.connect(false);\n }, secondsToNextRetry * 1000);\n }\n\n private receive = (evt: MessageEvent) => {\n if (evt.data === \"Invalid token\" || evt.data === \"Token has expired\") {\n const closeReason: WebSocketConnectionCloseReason =\n evt.data === \"Invalid token\" ? \"invalid-token\" : \"token-expired\";\n this.close(closeReason);\n } else {\n const vuuMessageFromServer = parseWebSocketMessage(evt.data);\n if (vuuMessageFromServer.body.type === \"CHANGE_VP_RANGE_SUCCESS\") {\n info?.(`CHANGE_VP_RANGE_SUCCESS<#${vuuMessageFromServer.requestId}>`);\n }\n if (debugEnabled) {\n if (vuuMessageFromServer.body.type !== \"HB\") {\n debug(`${vuuMessageFromServer.body.type}`);\n if (vuuMessageFromServer.body.type === \"CHANGE_VP_SUCCESS\") {\n debug(JSON.stringify(vuuMessageFromServer.body));\n }\n }\n }\n this.#callback(vuuMessageFromServer);\n }\n };\n\n send = (msg: VuuClientMessage) => {\n if (msg.body.type === \"CHANGE_VP_RANGE\") {\n info?.(\n `CHANGE_VP_RANGE<#${msg.requestId}> ${msg.body.from}-${msg.body.to}`,\n );\n }\n this.#ws?.send(JSON.stringify(msg));\n };\n\n close(reason: WebSocketConnectionCloseReason = \"shutdown\") {\n this.status = \"closed\";\n if (reason === \"failure\") {\n if (this.#deferredConnection) {\n this.#deferredConnection.reject(Error(\"connection failed\"));\n this.#deferredConnection = undefined;\n }\n } else {\n this.#ws?.close();\n }\n this.emit(\"closed\", { type: \"websocket-closed\", reason });\n this.#ws = undefined;\n }\n}\n"],"names":[],"mappings":";;AA6BsC,OAAO,qBAAqB;AAQrD,MAAA,4BAAA,GAA+B,CAC1C,GACoC,KAAA;AACpC,EAAA,IAAI,sBAAsB,GAAK,EAAA;AAC7B,IAAO,OAAA;AAAA,MACL,YAAA;AAAA,MACA,WAAA;AAAA,MACA,kCAAA;AAAA,MACA,cAAA;AAAA,MACA,aAAA;AAAA,MACA,cAAA;AAAA,MACA,QAAA;AAAA,MACA;AAAA,KACF,CAAE,QAAS,CAAA,GAAA,CAAI,gBAAgB,CAAA;AAAA,GAC1B,MAAA;AACL,IAAO,OAAA,KAAA;AAAA;AAEX;AAEO,MAAM,WAAc,GAAA,CACzB,MAEA,KAAA,MAAA,KAAW,eAAe,MAAW,KAAA;;;;"}
|
package/esm/inlined-worker.js
CHANGED
|
@@ -1594,9 +1594,6 @@ var ServerProxy = class {
|
|
|
1594
1594
|
__publicField(this, "cachedTableMetaRequests", /* @__PURE__ */ new Map());
|
|
1595
1595
|
__publicField(this, "cachedTableSchemas", /* @__PURE__ */ new Map());
|
|
1596
1596
|
__publicField(this, "tableList");
|
|
1597
|
-
__publicField(this, "connectionClosed", (reason) => {
|
|
1598
|
-
console.log(\`[ServerProxy] connectionClosed reason \${reason}\`);
|
|
1599
|
-
});
|
|
1600
1597
|
__publicField(this, "connectionStatusChanged", (message) => {
|
|
1601
1598
|
if (message.connectionStatus === "disconnected") {
|
|
1602
1599
|
this.clearAllViewports();
|
|
@@ -1640,7 +1637,6 @@ var ServerProxy = class {
|
|
|
1640
1637
|
this.viewports = /* @__PURE__ */ new Map();
|
|
1641
1638
|
this.mapClientToServerViewport = /* @__PURE__ */ new Map();
|
|
1642
1639
|
connection.on("reconnected", this.reconnect);
|
|
1643
|
-
connection.on("closed", this.connectionClosed);
|
|
1644
1640
|
connection.on("connection-status", this.connectionStatusChanged);
|
|
1645
1641
|
}
|
|
1646
1642
|
async login(authToken) {
|
|
@@ -2616,8 +2612,9 @@ var WebSocketConnection = class extends EventEmitter {
|
|
|
2616
2612
|
__privateAdd(this, _url);
|
|
2617
2613
|
__privateAdd(this, _ws);
|
|
2618
2614
|
__publicField(this, "receive", (evt) => {
|
|
2619
|
-
if (evt.data === "Invalid token") {
|
|
2620
|
-
|
|
2615
|
+
if (evt.data === "Invalid token" || evt.data === "Token has expired") {
|
|
2616
|
+
const closeReason = evt.data === "Invalid token" ? "invalid-token" : "token-expired";
|
|
2617
|
+
this.close(closeReason);
|
|
2621
2618
|
} else {
|
|
2622
2619
|
const vuuMessageFromServer = parseWebSocketMessage(evt.data);
|
|
2623
2620
|
if (vuuMessageFromServer.body.type === "CHANGE_VP_RANGE_SUCCESS") {
|
|
@@ -2800,7 +2797,7 @@ var WebSocketConnection = class extends EventEmitter {
|
|
|
2800
2797
|
} else {
|
|
2801
2798
|
(_a = __privateGet(this, _ws)) == null ? void 0 : _a.close();
|
|
2802
2799
|
}
|
|
2803
|
-
this.emit("closed", reason);
|
|
2800
|
+
this.emit("closed", { type: "websocket-closed", reason });
|
|
2804
2801
|
__privateSet(this, _ws, void 0);
|
|
2805
2802
|
}
|
|
2806
2803
|
};
|
|
@@ -2856,6 +2853,7 @@ async function connectToServer(url, protocols, token, retryLimitDisconnect, retr
|
|
|
2856
2853
|
url
|
|
2857
2854
|
});
|
|
2858
2855
|
websocketConnection.on("connection-status", postMessage);
|
|
2856
|
+
websocketConnection.on("closed", postMessage);
|
|
2859
2857
|
await websocketConnection.connect();
|
|
2860
2858
|
server = new ServerProxy(websocketConnection, sendMessageToClient);
|
|
2861
2859
|
if (websocketConnection.requiresLogin) {
|