This commit is contained in:
Martti Malmi
2023-12-21 21:50:43 +02:00
parent 782a2217b4
commit 9e6971423e
10 changed files with 85 additions and 21 deletions

View File

@ -1,6 +1,7 @@
import { io, Socket } from "socket.io-client";
import { WebRTCConnection } from "@/webrtc/WebRTCConnection";
import EventEmitter from "eventemitter3";
import { TaggedNostrEvent } from "@snort/system";
const MAX_CONNECTIONS = 5;
@ -22,7 +23,7 @@ class WebRTCPool extends EventEmitter {
this.signalingServer.emit("hello", this.peerId);
}
public send(data: any, recipients?: string[]): void {
public send(data: TaggedNostrEvent | string, recipients?: string[]): void {
this.peers.forEach(conn => {
if (!recipients || recipients.includes(conn.peerId)) {
try {
@ -39,7 +40,7 @@ class WebRTCPool extends EventEmitter {
throw new Error("Maximum connections reached");
}
const connection = new WebRTCConnection(this.signalingServer, this.configuration, peerId);
connection.on("event", (event: any) => this.emit("event", event));
connection.on("event", (event: TaggedNostrEvent | string) => this.emit("event", event));
this.peers.set(peerId, connection);
return connection;
}