Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions src/routes/ws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -926,17 +926,24 @@ export function setupWebSocket(server: Server): WebSocketServer {
message: "Please use channels array. Subscribing to all channels for this slab."
}));

const subscribed: string[] = [];
for (const channel of channels) {
if (client.subscriptions.has(channel)) continue;
if (globalSubscriptionCount >= MAX_GLOBAL_SUBSCRIPTIONS) break;
if (client.subscriptions.size >= MAX_SUBSCRIPTIONS_PER_CLIENT) break;

client.subscriptions.add(channel);
globalSubscriptionCount++;
subscribed.push(channel);
}

if (subscribed.length > 0) {
addClientToSlab(client, sanitized);
}
ws.send(JSON.stringify({ type: "subscribed", slabAddress: sanitized, channels: subscribed }));
if (subscribed.length < channels.length) {
ws.send(JSON.stringify({ type: "error", message: "Subscription limit reached — some channels were not subscribed" }));
}

addClientToSlab(client, sanitized);
ws.send(JSON.stringify({ type: "subscribed", slabAddress: sanitized, channels }));
}
// Handle unsubscribe with channels array
else if (msg.type === "unsubscribe" && msg.channels && Array.isArray(msg.channels)) {
Expand Down
Loading