Skip to content

Commit

Permalink
client: support passing in custom worker url
Browse files Browse the repository at this point in the history
  • Loading branch information
matlin authored and pbohlman committed Apr 5, 2024
1 parent f9f580b commit bc9d6ee
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
5 changes: 5 additions & 0 deletions packages/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
"types": "./dist/worker-client.d.ts",
"import": "./dist/worker-client.js",
"default": "./dist/worker-client.js"
},
"./worker-client-operator": {
"types": "./dist/worker-client-operator.d.ts",
"import": "./dist/worker-client-operator.js",
"default": "./dist/worker-client-operator.js"
}
},
"scripts": {
Expand Down
7 changes: 4 additions & 3 deletions packages/client/src/worker-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@ export class WorkerClient<M extends ClientSchema | undefined = undefined> {
onConnectionStatusChange: () => () => {},
};
clientWorker: ComLink.Remote<Client<M>>;
constructor(options?: ClientOptions<M>) {
constructor(options?: ClientOptions<M> & { workerUrl?: string }) {
const worker = new SharedWorker(
new URL('worker-client-operator.js', import.meta.url),
{ type: 'module' }
options?.workerUrl ??
new URL('worker-client-operator.js', import.meta.url),
{ type: 'module', name: 'triplit-client' }
);
this.clientWorker = ComLink.wrap<Client<M>>(worker.port);
const { schema } = options || {};
Expand Down

0 comments on commit bc9d6ee

Please sign in to comment.