chore: return void for sds.sendMessage()

This commit is contained in:
Danish Arora 2025-08-30 17:25:12 +05:30
parent c64bcff475
commit 14d333ff0d
No known key found for this signature in database
GPG Key ID: 1C6EF37CDAE1426E
4 changed files with 22 additions and 24 deletions

View File

@ -1,3 +1,3 @@
export { AuthService, type AuthServiceInterface } from './AuthService'; export { AuthService, type AuthServiceInterface, type AuthResult } from './AuthService';
export { MessageService, type MessageServiceInterface } from './MessageService'; export { MessageService, type MessageServiceInterface } from './MessageService';
export { CryptoService, type CryptoServiceInterface, type DelegationDuration } from './CryptoService'; export { CryptoService, type CryptoServiceInterface, type DelegationDuration } from './CryptoService';

View File

@ -76,7 +76,7 @@ export class ReliableMessaging {
}); });
} }
public async sendMessage(message: OpchanMessage, statusCallback?: MessageStatusCallback): Promise<string> { public async sendMessage(message: OpchanMessage, statusCallback?: MessageStatusCallback): Promise<void> {
const channel = this.channels.get(message.type); const channel = this.channels.get(message.type);
if (!channel) { if (!channel) {
throw new Error(`No reliable channel for message type: ${message.type}`); throw new Error(`No reliable channel for message type: ${message.type}`);
@ -90,8 +90,7 @@ export class ReliableMessaging {
} }
try { try {
await channel.send(encodedMessage); return channel.send(encodedMessage);
return messageId;
} catch (error) { } catch (error) {
this.messageCallbacks.delete(messageId); this.messageCallbacks.delete(messageId);
throw error; throw error;

View File

@ -90,11 +90,12 @@ class MessageManager {
return this.nodeManager.onHealthChange(callback); return this.nodeManager.onHealthChange(callback);
} }
public async sendMessage(message: OpchanMessage, statusCallback?: MessageStatusCallback): Promise<string> { //TODO: return event handlers?
public async sendMessage(message: OpchanMessage, statusCallback?: MessageStatusCallback): Promise<void> {
if (!this.messageService) { if (!this.messageService) {
throw new Error("MessageManager not fully initialized"); throw new Error("MessageManager not fully initialized");
} }
return this.messageService.sendMessage(message, statusCallback); this.messageService.sendMessage(message, statusCallback);
} }
public onMessageReceived(callback: (message: OpchanMessage) => void): () => void { public onMessageReceived(callback: (message: OpchanMessage) => void): () => void {

View File

@ -28,7 +28,7 @@ export class MessageService {
} }
} }
public async sendMessage(message: OpchanMessage, statusCallback?: MessageStatusCallback): Promise<string> { public async sendMessage(message: OpchanMessage, statusCallback?: MessageStatusCallback): Promise<void> {
if (!this.reliableMessaging) { if (!this.reliableMessaging) {
throw new Error("Reliable messaging not initialized"); throw new Error("Reliable messaging not initialized");
} }
@ -41,23 +41,21 @@ export class MessageService {
this.cacheService.updateCache(message); this.cacheService.updateCache(message);
// Send via reliable messaging with status tracking // Send via reliable messaging with status tracking
const messageId = await this.reliableMessaging.sendMessage(message, { await this.reliableMessaging.sendMessage(message, {
onSent: (id) => { onSent: (id) => {
console.log(`Message ${id} sent`); console.log(`Message ${id} sent`);
statusCallback?.onSent?.(id); statusCallback?.onSent?.(id);
}, },
onAcknowledged: (id) => { onAcknowledged: (id) => {
console.log(`Message ${id} acknowledged`); console.log(`Message ${id} acknowledged`);
statusCallback?.onAcknowledged?.(id); statusCallback?.onAcknowledged?.(id);
}, },
onError: (id, error) => { onError: (id, error) => {
console.error(`Message ${id} failed:`, error); console.error(`Message ${id} failed:`, error);
statusCallback?.onError?.(id, error); statusCallback?.onError?.(id, error);
} }
}); });
}
return messageId;
}
public onMessageReceived(callback: MessageReceivedCallback): () => void { public onMessageReceived(callback: MessageReceivedCallback): () => void {
this.messageReceivedCallbacks.add(callback); this.messageReceivedCallbacks.add(callback);