pluto-rtc 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core/Client.d.ts +1 -1
- package/dist/core/Client.js +5 -4
- package/dist/core/Room.js +15 -6
- package/package.json +1 -1
package/dist/core/Client.d.ts
CHANGED
|
@@ -42,7 +42,7 @@ export declare class Client {
|
|
|
42
42
|
}[]>;
|
|
43
43
|
onDevicesChange(callback: any): () => void;
|
|
44
44
|
init(): Promise<void>;
|
|
45
|
-
connect(ticket: string): Promise<Connection>;
|
|
45
|
+
connect(ticket: string, timeoutMs?: number): Promise<Connection>;
|
|
46
46
|
openBi(nodeId: string): Promise<{
|
|
47
47
|
readable: ReadableStream<Uint8Array>;
|
|
48
48
|
writable: WritableStream<Uint8Array>;
|
package/dist/core/Client.js
CHANGED
|
@@ -98,7 +98,7 @@ export class Client {
|
|
|
98
98
|
this.localNodeId = addr.node_id || addr.id;
|
|
99
99
|
}
|
|
100
100
|
}
|
|
101
|
-
async connect(ticket) {
|
|
101
|
+
async connect(ticket, timeoutMs = 20000) {
|
|
102
102
|
if (!this.wasmLoaded)
|
|
103
103
|
await this.init();
|
|
104
104
|
if (!this.node)
|
|
@@ -149,7 +149,8 @@ export class Client {
|
|
|
149
149
|
// Retry open_bi loop
|
|
150
150
|
let biStream = null;
|
|
151
151
|
let retries = 0;
|
|
152
|
-
const
|
|
152
|
+
const interval = 500;
|
|
153
|
+
const maxRetries = Math.ceil(timeoutMs / interval);
|
|
153
154
|
while (retries < maxRetries) {
|
|
154
155
|
try {
|
|
155
156
|
biStream = await this.node.open_bi(nodeId);
|
|
@@ -157,11 +158,11 @@ export class Client {
|
|
|
157
158
|
}
|
|
158
159
|
catch (e) {
|
|
159
160
|
retries++;
|
|
160
|
-
await new Promise(r => setTimeout(r,
|
|
161
|
+
await new Promise(r => setTimeout(r, interval));
|
|
161
162
|
}
|
|
162
163
|
}
|
|
163
164
|
if (!biStream) {
|
|
164
|
-
throw new Error(`Failed to establish connection to ${nodeId} after ${
|
|
165
|
+
throw new Error(`Failed to establish connection to ${nodeId} after ${timeoutMs}ms`);
|
|
165
166
|
}
|
|
166
167
|
const connection = new Connection(connId, this.localNodeId, // Local
|
|
167
168
|
nodeId, // Remote
|
package/dist/core/Room.js
CHANGED
|
@@ -148,9 +148,9 @@ export class RoomManager {
|
|
|
148
148
|
const membersRef = collection(this.db, `custom/${this.tag}/rooms`, targetRoomId, 'members');
|
|
149
149
|
const membersSnap = await getDocs(membersRef);
|
|
150
150
|
const connections = [];
|
|
151
|
-
|
|
151
|
+
const connectionPromises = membersSnap.docs.map(async (doc) => {
|
|
152
152
|
if (doc.id === myNodeId)
|
|
153
|
-
|
|
153
|
+
return null; // Skip self
|
|
154
154
|
const data = doc.data();
|
|
155
155
|
// Check expiration
|
|
156
156
|
let isExpired = false;
|
|
@@ -166,20 +166,29 @@ export class RoomManager {
|
|
|
166
166
|
isExpired = true;
|
|
167
167
|
}
|
|
168
168
|
if (isExpired)
|
|
169
|
-
|
|
169
|
+
return null;
|
|
170
170
|
const ticket = data.ticket;
|
|
171
171
|
if (ticket) {
|
|
172
172
|
try {
|
|
173
173
|
console.log(`Bootstrapping: Connecting to peer ${doc.id}...`);
|
|
174
|
-
|
|
174
|
+
// Use 5s timeout for bootstrapping
|
|
175
|
+
const conn = await this.client.connect(ticket, 5000);
|
|
175
176
|
conn.send({ type: 'chat', text: `Use ${userId} joined the room.` });
|
|
176
|
-
|
|
177
|
+
return conn;
|
|
177
178
|
}
|
|
178
179
|
catch (e) {
|
|
179
180
|
console.warn(`Failed to connect to peer ${doc.id}:`, e);
|
|
181
|
+
return null;
|
|
180
182
|
}
|
|
181
183
|
}
|
|
182
|
-
|
|
184
|
+
return null;
|
|
185
|
+
});
|
|
186
|
+
const results = await Promise.allSettled(connectionPromises);
|
|
187
|
+
results.forEach(result => {
|
|
188
|
+
if (result.status === 'fulfilled' && result.value) {
|
|
189
|
+
connections.push(result.value);
|
|
190
|
+
}
|
|
191
|
+
});
|
|
183
192
|
// Start Heartbeat
|
|
184
193
|
this.startHeartbeat(targetRoomId, myNodeId);
|
|
185
194
|
// Prune Stale Members (Lazy cleanup)
|