Skip to content

Commit 2d10ced

Browse files
committed
Removed unused methods
Signed-off-by: Robert Gogete <gogeterobert@yahoo.com>
1 parent 20c1db4 commit 2d10ced

File tree

2 files changed

+0
-160
lines changed

2 files changed

+0
-160
lines changed

src/registry/gun-registry.ts

Lines changed: 0 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -315,77 +315,4 @@ export class GunRegistry {
315315
throw error;
316316
}
317317
}
318-
319-
/**
320-
* Send a signaling message to a peer (for WebRTC negotiation)
321-
*/
322-
public async sendSignalingMessage(targetPeer: string, message: Record<string, unknown>): Promise<void> {
323-
if (!this.isGunAvailable || !this.gun) {
324-
throw new Error("Gun.js registry not available");
325-
}
326-
327-
if (!targetPeer) {
328-
throw new Error("Target peer ID is required");
329-
}
330-
331-
try {
332-
const signalRef = this.gun
333-
.get(this.options.namespace!)
334-
.get('signaling')
335-
.get(targetPeer);
336-
337-
const signalData = {
338-
...message,
339-
timestamp: Date.now()
340-
};
341-
342-
signalRef.put(signalData);
343-
console.log(`📡 [GunRegistry] Sent signaling message to ${targetPeer}`);
344-
} catch (error) {
345-
console.error(`❌ [GunRegistry] Failed to send signaling message to ${targetPeer}:`, error);
346-
throw error;
347-
}
348-
}
349-
350-
/**
351-
* Listen for signaling messages for this peer
352-
*/
353-
public onSignalingMessage(peerId: string, callback: (message: Record<string, unknown>) => void): void {
354-
if (!this.isGunAvailable || !this.gun) {
355-
console.warn('Gun.js not available, signaling will not work');
356-
return;
357-
}
358-
359-
if (!peerId) {
360-
throw new Error("Peer ID is required");
361-
}
362-
363-
try {
364-
const signalRef = this.gun
365-
.get(this.options.namespace!)
366-
.get('signaling')
367-
.get(peerId);
368-
369-
signalRef.on((data: Record<string, unknown>) => {
370-
if (data && typeof data === 'object' && !Array.isArray(data)) {
371-
// Filter out Gun.js metadata
372-
const messageData = Object.keys(data)
373-
.filter(key => key !== '_')
374-
.reduce((obj, key) => {
375-
obj[key] = data[key];
376-
return obj;
377-
}, {} as Record<string, unknown>);
378-
379-
if (Object.keys(messageData).length > 0) {
380-
callback(messageData);
381-
}
382-
}
383-
});
384-
385-
console.log(`🎧 [GunRegistry] Listening for signaling messages for peer: ${peerId}`);
386-
} catch (error) {
387-
console.error(`❌ [GunRegistry] Failed to set up signaling listener for ${peerId}:`, error);
388-
throw error;
389-
}
390-
}
391318
}

tests/gun-registry.test.ts

Lines changed: 0 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -450,93 +450,6 @@ describe('GunRegistry', () => {
450450
});
451451
});
452452

453-
describe('sendSignalingMessage', () => {
454-
beforeEach(() => {
455-
registry = new GunRegistry();
456-
});
457-
458-
it('should throw error when Gun.js is not available', async () => {
459-
(registry as any).isGunAvailable = false;
460-
461-
await expect(registry.sendSignalingMessage('target-peer', { test: 'message' }))
462-
.rejects.toThrow('Gun.js registry not available');
463-
});
464-
465-
it('should send signaling message with timestamp', async () => {
466-
const targetPeer = 'target-peer';
467-
const message = { test: 'message', data: 'value' };
468-
469-
await registry.sendSignalingMessage(targetPeer, message);
470-
471-
expect(mockGunChain.get).toHaveBeenCalledWith('dig-nat-tools');
472-
expect(mockGunChain.get).toHaveBeenCalledWith('signaling');
473-
expect(mockGunChain.get).toHaveBeenCalledWith(targetPeer);
474-
expect(mockGunChain.put).toHaveBeenCalledWith({
475-
test: 'message',
476-
data: 'value',
477-
timestamp: expect.any(Number)
478-
});
479-
});
480-
});
481-
482-
describe('onSignalingMessage', () => {
483-
beforeEach(() => {
484-
registry = new GunRegistry();
485-
});
486-
487-
it('should warn when Gun.js is not available', () => {
488-
(registry as any).isGunAvailable = false;
489-
490-
const consoleSpy = jest.spyOn(console, 'warn').mockImplementation();
491-
const callback = jest.fn();
492-
493-
registry.onSignalingMessage('test-store-id', callback);
494-
495-
expect(consoleSpy).toHaveBeenCalledWith('Gun.js not available, signaling will not work');
496-
consoleSpy.mockRestore();
497-
});
498-
499-
it('should set up signaling message listener', () => {
500-
const callback = jest.fn();
501-
const storeId = 'test-store-id';
502-
503-
registry.onSignalingMessage(storeId, callback);
504-
505-
expect(mockGunChain.get).toHaveBeenCalledWith('dig-nat-tools');
506-
expect(mockGunChain.get).toHaveBeenCalledWith('signaling');
507-
expect(mockGunChain.get).toHaveBeenCalledWith(storeId);
508-
expect(mockGunChain.on).toHaveBeenCalled();
509-
});
510-
511-
it('should call callback when message with timestamp is received', () => {
512-
const callback = jest.fn();
513-
const storeId = 'test-store-id';
514-
const message = { test: 'message', timestamp: Date.now() };
515-
516-
registry.onSignalingMessage(storeId, callback);
517-
518-
// Simulate receiving a message
519-
const onCallback = Array.from(mockOnCallbacks.values())[0];
520-
if (onCallback) onCallback(message);
521-
522-
expect(callback).toHaveBeenCalledWith(message);
523-
});
524-
525-
it('should call callback when message is received', () => {
526-
const callback = jest.fn();
527-
const storeId = 'test-store-id';
528-
const message = { test: 'message' };
529-
530-
registry.onSignalingMessage(storeId, callback);
531-
532-
// Simulate receiving a message
533-
const onCallback = Array.from(mockOnCallbacks.values())[0];
534-
if (onCallback) onCallback(message);
535-
536-
expect(callback).toHaveBeenCalledWith(message);
537-
});
538-
});
539-
540453
describe('unregister', () => {
541454
beforeEach(() => {
542455
registry = new GunRegistry();

0 commit comments

Comments
 (0)