🐛(y-webrtc) fix prob connection

Sometimes the connection was not established correctly,
because multiple connections were created at the
same time. This commit fixes this issue by ensuring
that only one connection is created at a time.
This commit is contained in:
Anthony LC
2024-08-01 16:54:08 +02:00
committed by Anthony LC
parent bef541f956
commit 713d9e48c8

View File

@@ -68,7 +68,7 @@ const onconnection = (conn: WebSocket, url: string) => {
subscribedTopics.forEach((topicName) => {
const subs = topics.get(topicName) || new Set();
subs.forEach((sub) => {
if (sub.conn === conn) {
if (sub.url === url && sub.conn === conn) {
subs.delete(sub);
}
});
@@ -96,9 +96,18 @@ const onconnection = (conn: WebSocket, url: string) => {
topicName,
() => new Set(),
);
topic.add({ url, conn });
// add topic to conn
subscribedTopics.add(topicName);
let isAlreadyAdded = false;
topic.forEach((sub) => {
if (sub.url === url && sub.conn === conn) {
isAlreadyAdded = true;
}
});
if (!isAlreadyAdded) {
topic.add({ url, conn });
subscribedTopics.add(topicName);
}
}
});
break;