Skip to content

Commit

Permalink
client: Fix connection status not working with web worker
Browse files Browse the repository at this point in the history
  • Loading branch information
matlin committed Jun 15, 2024
1 parent 09fbb43 commit fef88d1
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/loud-mayflies-approve.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@triplit/client': patch
---

Fix connection status listening when using web worker client
2 changes: 1 addition & 1 deletion packages/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"test:unit": "vitest run",
"typecheck": "vitest --typecheck.only --no-watch",
"publish-pkg": "node ../../scripts/npm-check-version-and-publish.js",
"build-worker": "esbuild ./src/worker-client/worker-client-operator.ts --bundle --minify --platform=browser --outfile=./dist/worker-client/worker-client-operator.js --format=esm --sourcemap",
"build-worker": "esbuild ./src/worker-client/worker-client-operator.ts --bundle --minify --platform=browser --outfile=./dist/worker-client/worker-client-operator.js --format=esm",
"validate:types": "node ../../scripts/check-for-local-references-in-declarations.js dist"
},
"files": [
Expand Down
4 changes: 1 addition & 3 deletions packages/client/src/transport/websocket-transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,7 @@ function friendlyReadyState(conn: WebSocket): ConnectionStatus {
}
}

// temporary defensive check for node env
// only run in browser for now
if (typeof document !== 'undefined') {
if (typeof WebSocket !== 'undefined') {
// Add any changes to the WebSocket type here (ex more event handlers)
var WebSocketProxy = new Proxy(WebSocket, {
construct: function (target, args) {
Expand Down
1 change: 0 additions & 1 deletion packages/client/src/worker-client/worker-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ export class WorkerClient<M extends ClientSchema | undefined = undefined> {
});
this._connectionStatus = 'CLOSED';
this.onConnectionStatusChange((status) => {
console.log('connection status:', status);
this._connectionStatus = status;
}, true);
this.db.updateGlobalVariables = (variables) => {
Expand Down

0 comments on commit fef88d1

Please sign in to comment.