* Wait for a specific event to be captured * @param {string} eventType - The event type to wait for * @param {number} timeout - Timeout in milliseconds (default: 5000) * @returns {Promise} Promise that resolves with the event when found
(eventType, timeout = 5000)
| 195 | * @returns {Promise} Promise that resolves with the event when found |
| 196 | */ |
| 197 | waitForEvent(eventType, timeout = 5000) { |
| 198 | return new Promise((resolve, reject) => { |
| 199 | const timeoutId = setTimeout(() => { |
| 200 | reject(new Error(`Timeout waiting for event: ${eventType}`)); |
| 201 | }, timeout); |
| 202 | |
| 203 | const checkEvent = () => { |
| 204 | const event = this._capturedEvents.find(e => e.event === eventType); |
| 205 | if (event) { |
| 206 | clearTimeout(timeoutId); |
| 207 | resolve(event); |
| 208 | } else { |
| 209 | setTimeout(checkEvent, 10); |
| 210 | } |
| 211 | }; |
| 212 | checkEvent(); |
| 213 | }); |
| 214 | } |
| 215 | |
| 216 | /** |
| 217 | * Static method to create a connection |
no outgoing calls