Skip to content

Commit 050202f

Browse files
author
Kushagra Singh Bisen
committed
fixed linting issues
1 parent 01c8558 commit 050202f

File tree

4 files changed

+53
-9
lines changed

4 files changed

+53
-9
lines changed

src/server/NotificationServiceHTTPServer.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ export class NotificationServiceHTTPServer {
2424
/**
2525
* Creates an instance of NotificationServiceHTTPServer.
2626
* @param {number} port - The port where the HTTP server will listen.
27-
* @param {string[]} pod_url - The location of the Solid Pod from which the notifications are retrieved.
2827
* @param {*} logger - The logger object.
2928
* @memberof NotificationServiceHTTPServer
3029
*/
@@ -172,6 +171,10 @@ export class NotificationServiceHTTPServer {
172171
response.end('OK');
173172
}
174173

174+
/**
175+
* Sends a message to the WebSocket server.
176+
* @param {string} message - The message to send to the WebSocket server.
177+
*/
175178
public send_to_websocket_server(message: string) {
176179
if (this.connection.connected) {
177180
this.connection.sendUTF(message);
@@ -183,6 +186,10 @@ export class NotificationServiceHTTPServer {
183186
}
184187
}
185188

189+
/**
190+
* Connects to the WebSocket server.
191+
* @param {string} wss_url - The URL of the WebSocket server.
192+
*/
186193
public async connect_to_websocket_server(wss_url: string) {
187194
this.client.connect(wss_url, 'solid-stream-notifications-aggregator');
188195
this.client.on('connect', (connection: typeof websocket.connection) => {
@@ -195,6 +202,11 @@ export class NotificationServiceHTTPServer {
195202
});
196203
}
197204

205+
/**
206+
* Checks if the resource location is a container.
207+
* @param {string} resource_location - The location of the resource.
208+
* @returns {boolean} - Returns true if the resource location is a container. Returns false if the resource location is not a container.
209+
*/
198210
public check_if_container(resource_location: string): boolean {
199211
if (resource_location.endsWith('/')) {
200212
return true;

src/server/WebSocketServerHandler.ts

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,30 @@
11
import * as WebSocket from 'websocket';
2-
import { CacheService } from '../service/CacheService';
32
import { SubscribeNotification } from '../service/SubscribeNotification';
43
import { extract_ldp_inbox } from '../utils/Util';
54

5+
/**
6+
*
7+
*/
68
export class WebSocketServerHandler {
79

810
public websocket_server: any;
911
public websocket_connections: Map<string, WebSocket[]>;
1012
public subscribe_notification: SubscribeNotification;
1113

12-
14+
/**
15+
* Creates an instance of WebSocketServerHandler.
16+
* @param {WebSocket.server} websocket_server - The WebSocket server.
17+
*/
1318
constructor(websocket_server: WebSocket.server) {
1419
this.websocket_server = websocket_server;
1520
this.websocket_connections = new Map<string, WebSocket[]>();
1621
this.subscribe_notification = new SubscribeNotification();
1722
}
1823

19-
public async handle_communication(cache_service: CacheService) {
24+
/**
25+
* Handles the communication for the WebSocket server.
26+
*/
27+
public async handle_communication() {
2028
console.log(`Handling the communication for the WebSocket server.`);
2129
this.websocket_server.on('connect', (connection: any) => {
2230
console.log(`Connection received from the client with address: ${connection.remoteAddress}`);
@@ -30,19 +38,19 @@ export class WebSocketServerHandler {
3038
const ws_message = JSON.parse(message_utf8);
3139
if (Object.keys(ws_message).includes('subscribe')) {
3240
console.log(`Received a subscribe message from the client.`);
33-
let stream_to_subscribe = ws_message.subscribe;
34-
for (let stream of stream_to_subscribe) {
41+
const stream_to_subscribe = ws_message.subscribe;
42+
for (const stream of stream_to_subscribe) {
3543
console.log(`Subscribed to the stream: ${stream}`);
3644
this.set_connections(stream, connection);
3745
}
3846
}
3947
else if (Object.keys(ws_message).includes('event')) {
4048
console.log(`Received a new event message from the client.`);
41-
let connection = this.websocket_connections.get(ws_message.stream);
49+
const connection = this.websocket_connections.get(ws_message.stream);
4250
if (connection !== undefined) {
4351
for (const [stream, connections] of this.websocket_connections) {
4452
if (stream == ws_message.stream) {
45-
for (let connection of connections) {
53+
for (const connection of connections) {
4654
connection.send(JSON.stringify(ws_message));
4755
}
4856
}
@@ -64,9 +72,14 @@ export class WebSocketServerHandler {
6472
});
6573
}
6674

75+
/**
76+
* Sets the connections for the WebSocket server's Map.
77+
* @param {string} subscribed_stream - The subscribed stream.
78+
* @param {WebSocket} connection - The WebSocket connection.
79+
*/
6780
public async set_connections(subscribed_stream: string, connection: WebSocket){
6881
if (!this.websocket_connections.has(subscribed_stream)) {
69-
let stream_inbox = await extract_ldp_inbox(subscribed_stream) as string;
82+
const stream_inbox = await extract_ldp_inbox(subscribed_stream) as string;
7083
this.subscribe_notification.subscribe_inbox(stream_inbox);
7184
this.websocket_connections.set(subscribed_stream, [connection]);
7285
}

src/service/CacheService.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,11 @@ export class CacheService {
118118
}
119119

120120

121+
/**
122+
* Get the most recent key-value pair from the Redis cache.
123+
* @param {string} ldes_stream - The LDES stream to get the most recent key-value pair from.
124+
* @returns {Promise<{ key: string, value: string }>} - A promise that resolves to an object containing the most recent key-value pair in the cache.
125+
*/
121126
async get_recent_key_value(ldes_stream: string): Promise<{ key: string, value: string }> {
122127
try {
123128
// example of a key is, stream:http://localhost:3000/aggregation_pod/aggregation/:1710250027636
@@ -143,11 +148,20 @@ export class CacheService {
143148

144149

145150

151+
/**
152+
* Sets the time to live for a key in the Redis cache.
153+
* @param {string} key - The key to set the time to live for.
154+
* @param {number} time_to_live - The time to live in seconds.
155+
* @returns {Promise<void>} - A promise that resolves when the time to live is set.
156+
*/
146157
async setTimeToLive(key: string, time_to_live: number) {
147158
// setting the time to live for the key in seconds.
148159
await this.client.expire(key, time_to_live);
149160
}
150161

162+
/**
163+
* Clears the cache.
164+
*/
151165
async clearCache() {
152166
await this.client.flushall();
153167
}

src/service/SubscribeNotification.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ export class SubscribeNotification {
4747
}
4848
}
4949

50+
/**
51+
* Subscribes to the notification server for a specific inbox location.
52+
* @param {string} inbox_location - The inbox location to subscribe to.
53+
* @returns {(Promise<boolean | undefined>)} - Returns a promise with a boolean or undefined. If the subscription is successful, it returns true. If the subscription fails, it throws an error.
54+
*/
5055
public async subscribe_inbox(inbox_location:string): Promise<boolean | undefined> {
5156
const subscription_server = await extract_subscription_server(inbox_location);
5257
if (subscription_server === undefined) {

0 commit comments

Comments
 (0)