Skip to content

Commit

Permalink
refactored
Browse files Browse the repository at this point in the history
  • Loading branch information
andorsk committed Oct 2, 2023
1 parent 6e02d41 commit 800b285
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 24 deletions.
1 change: 0 additions & 1 deletion src/json-rpc-handlers/dwn/process-message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ export const handleDwnProcessMessage: JsonRpcHandler = async (
messageType === DwnInterfaceName.Records + DwnMethodName.Write &&
!dataStream
) {
console.log('sending');
reply = await dwn.synchronizePrunedInitialRecordsWrite(target, message);
} else if (
messageType ===
Expand Down
24 changes: 1 addition & 23 deletions src/subscription-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { Dwn, SubscriptionFilter } from '@tbd54566975/dwn-sdk-js';
import type { EventMessage, PermissionsGrant } from '@tbd54566975/dwn-sdk-js';

Check failure on line 2 in src/subscription-manager.ts

View workflow job for this annotation

GitHub Actions / test

'"@tbd54566975/dwn-sdk-js"' has no exported member named 'EventMessage'. Did you mean 'EventsGetMessage'?

import type { JsonRpcSuccessResponse } from './lib/json-rpc.js';
import { SubscriptionRequest } from '@tbd54566975/dwn-sdk-js';
import type { SubscriptionRequest } from '@tbd54566975/dwn-sdk-js';

Check failure on line 5 in src/subscription-manager.ts

View workflow job for this annotation

GitHub Actions / test

Module '"@tbd54566975/dwn-sdk-js"' has no exported member 'SubscriptionRequest'.
import type { SubscriptionRequestReply } from '@tbd54566975/dwn-sdk-js';

Check failure on line 6 in src/subscription-manager.ts

View workflow job for this annotation

GitHub Actions / test

Module '"@tbd54566975/dwn-sdk-js"' has no exported member 'SubscriptionRequestReply'.
import type WebSocket from 'ws';
import { WebSocketServer } from 'ws';
Expand Down Expand Up @@ -60,12 +60,6 @@ export class SubscriptionManager {
this.connections = new Map();
this.dwn = options?.dwn;
this.options = options;

this.wss.on('connection', (socket: WebSocket) => {
socket.on('message', async (data) => {
await this.handleSubscribe(socket, data);
});
});
}

async clear(): Promise<void> {
Expand Down Expand Up @@ -102,20 +96,6 @@ export class SubscriptionManager {
};
}

async handleSubscribe(
socket: WebSocket,
data: any,
): Promise<RegisterSubscriptionReply> {
// parse message
const req = await SubscriptionRequest.parse(data);

return await this.subscribe({
request: req,
socket: socket,
from: req.author,
});
}

createJSONRPCEvent(e: EventMessage): JsonRpcSuccessResponse {
return {
id: uuidv4(),
Expand All @@ -137,10 +117,8 @@ export class SubscriptionManager {
const subscription = await this.createSubscription(req.from, req);
this.registerSubscription(subscription);
// set up forwarding.
// console.log('---------', subscriptionReply.subscription.emitter);
subscriptionReply.subscription.emitter.on(
async (e: EventMessage): Promise<void> => {
// console.log('got a record', e);
const jsonRpcResponse = this.createJSONRPCEvent(e);
const str = JSON.stringify(jsonRpcResponse);
return req.socket.send(Buffer.from(str));
Expand Down

0 comments on commit 800b285

Please sign in to comment.