Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
addievo committed Oct 17, 2023
1 parent 6fc85e9 commit 3b195c8
Showing 1 changed file with 26 additions and 18 deletions.
44 changes: 26 additions & 18 deletions src/PolykeyClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Logger from '@matrixai/logger';
import { CreateDestroyStartStop } from '@matrixai/async-init/dist/CreateDestroyStartStop';
import { RPCClient } from '@matrixai/rpc';
import { middleware as rpcMiddleware } from '@matrixai/rpc';
import { WebSocketClient } from "@matrixai/ws";
import { WebSocketClient } from '@matrixai/ws';
import * as clientMiddleware from './client/middleware';
import { Session } from './sessions';
import * as utils from './utils';
Expand Down Expand Up @@ -35,21 +35,20 @@ interface PolykeyClient extends CreateDestroyStartStop {}
)
class PolykeyClient {
static async createPolykeyClient({
nodePath = config.defaultsUser.nodePath,
streamFactory,
streamKeepAliveTimeoutTime,
parserBufferByteLimit,
fs = require('fs'),
logger = new Logger(this.name),
fresh = false,
}: {
nodePath = config.defaultsUser.nodePath,
streamFactory,
streamKeepAliveTimeoutTime,
parserBufferByteLimit,
fs = require('fs'),
logger = new Logger(this.name),
fresh = false,
}: {
nodePath?: string;
streamFactory: StreamFactory;
streamKeepAliveTimeoutTime?: number;
parserBufferByteLimit?: number;
fs?: FileSystem;
logger?: Logger;
ws?: WebSocketClient
fresh?: boolean;
}): Promise<PolykeyClient> {
logger.info(`Creating ${this.name}`);
Expand All @@ -63,7 +62,11 @@ class PolykeyClient {
logger: logger.getChild(Session.name),
fresh,
});
const ws: WebSocketClient = new WebSocketClient();
const ws = await WebSocketClient.createWebSocketClient({
host: config.defaultsUser.clientServiceHost,
port: config.defaultsUser.clientServicePort,
logger: logger.getChild('WebSocketClient'),
});
const rpcClientClient = new RPCClient({
manifest: clientClientManifest,
streamFactory,
Expand All @@ -82,6 +85,7 @@ class PolykeyClient {
fs,
logger,
});
pkClient.ws = ws;
await pkClient.start();
logger.info(`Created ${this.name}`);
return pkClient;
Expand All @@ -95,20 +99,23 @@ class PolykeyClient {
protected fs: FileSystem;
protected logger: Logger;

public setWs(ws: WebSocketClient){
this.ws = ws;
}

constructor({
nodePath,
rpcClientClient,
session,
fs,
logger,
}: {
nodePath,
rpcClientClient,
session,
fs,
logger,
}: {
nodePath: string;
rpcClientClient: RPCClient<typeof clientClientManifest>;
session: Session;
fs: FileSystem;
logger: Logger;
}) {
this.ws = new WebSocketClient();
this.logger = logger;
this.nodePath = nodePath;
this.session = session;
Expand All @@ -129,6 +136,7 @@ class PolykeyClient {

public async destroy() {
this.logger.info(`Destroying ${this.constructor.name}`);
await this.ws.destroy({force: true});
await this.session.destroy();
this.logger.info(`Destroyed ${this.constructor.name}`);
}
Expand Down

0 comments on commit 3b195c8

Please sign in to comment.