| b69ab31 | | | 1 | /** |
| b69ab31 | | | 2 | * This software contains information and intellectual property that is |
| b69ab31 | | | 3 | * confidential and proprietary to Facebook, Inc. and its affiliates. |
| b69ab31 | | | 4 | * |
| b69ab31 | | | 5 | * @generated |
| b69ab31 | | | 6 | */ |
| b69ab31 | | | 7 | |
| b69ab31 | | | 8 | /* |
| b69ab31 | | | 9 | * This file is synced between fbcode/eden/fs/facebook/prototypes/node-edenfs-notifications-client/example.js. |
| b69ab31 | | | 10 | * The authoritative copy is the one in eden/fs/. |
| b69ab31 | | | 11 | * Use `yarn sync-edenfs-notifications` to perform the sync. |
| b69ab31 | | | 12 | * |
| b69ab31 | | | 13 | * This file is intended to be self contained so it may be copied/referenced from other extensions, |
| b69ab31 | | | 14 | * which is why it should not import anything and why it reimplements many types. |
| b69ab31 | | | 15 | */ |
| b69ab31 | | | 16 | |
| b69ab31 | | | 17 | /** |
| b69ab31 | | | 18 | * Example usage of the EdenFS Notify JavaScript interface |
| b69ab31 | | | 19 | */ |
| b69ab31 | | | 20 | |
| b69ab31 | | | 21 | const {EdenFSNotificationsClient, EdenFSUtils} = require('./index.js'); |
| b69ab31 | | | 22 | |
| b69ab31 | | | 23 | async function basicExample() { |
| b69ab31 | | | 24 | console.log('=== Basic EdenFS Notify Example ==='); |
| b69ab31 | | | 25 | |
| b69ab31 | | | 26 | // Create a client instance |
| b69ab31 | | | 27 | const client = new EdenFSNotificationsClient({ |
| b69ab31 | | | 28 | mountPoint: null, |
| b69ab31 | | | 29 | timeout: 1000, // 1 second timeout |
| b69ab31 | | | 30 | edenBinaryPath: process.env.EDEN_PATH ? process.env.EDEN_PATH : 'eden', |
| b69ab31 | | | 31 | }); |
| b69ab31 | | | 32 | |
| b69ab31 | | | 33 | try { |
| b69ab31 | | | 34 | // Get current journal position |
| b69ab31 | | | 35 | console.log('Getting current journal position...'); |
| b69ab31 | | | 36 | const position = await client.getPosition(); |
| b69ab31 | | | 37 | console.log('Current position:', position); |
| b69ab31 | | | 38 | } catch (error) { |
| b69ab31 | | | 39 | console.error('Error:', error.message); |
| b69ab31 | | | 40 | } |
| b69ab31 | | | 41 | } |
| b69ab31 | | | 42 | |
| b69ab31 | | | 43 | async function waitReadyExample() { |
| b69ab31 | | | 44 | console.log('\n=== EdenFS Wait Ready Example ==='); |
| b69ab31 | | | 45 | |
| b69ab31 | | | 46 | // Create a client instance with a short timeout for demonstration |
| b69ab31 | | | 47 | const client = new EdenFSNotificationsClient({ |
| b69ab31 | | | 48 | mountPoint: null, |
| b69ab31 | | | 49 | timeout: 5000, // 5 second default timeout |
| b69ab31 | | | 50 | edenBinaryPath: process.env.EDEN_PATH ? process.env.EDEN_PATH : 'eden', |
| b69ab31 | | | 51 | }); |
| b69ab31 | | | 52 | |
| b69ab31 | | | 53 | try { |
| b69ab31 | | | 54 | // Wait for EdenFS to be ready (useful after restart or initial setup) |
| b69ab31 | | | 55 | console.log('Waiting for EdenFS to be ready...'); |
| b69ab31 | | | 56 | const isReady = await client.waitReady({ |
| b69ab31 | | | 57 | timeout: 10000, // Wait up to 10 seconds |
| b69ab31 | | | 58 | }); |
| b69ab31 | | | 59 | |
| b69ab31 | | | 60 | if (isReady) { |
| b69ab31 | | | 61 | console.log('EdenFS is ready!'); |
| b69ab31 | | | 62 | // Now safe to perform operations |
| b69ab31 | | | 63 | const position = await client.getPosition(); |
| b69ab31 | | | 64 | console.log('Current position:', position); |
| b69ab31 | | | 65 | } else { |
| b69ab31 | | | 66 | console.log('EdenFS did not become ready within timeout'); |
| b69ab31 | | | 67 | } |
| b69ab31 | | | 68 | } catch (error) { |
| b69ab31 | | | 69 | console.error('Error:', error.message); |
| b69ab31 | | | 70 | } |
| b69ab31 | | | 71 | } |
| b69ab31 | | | 72 | |
| b69ab31 | | | 73 | async function changesExample(position) { |
| b69ab31 | | | 74 | console.log('=== EdenFS Notify changesSince Example ==='); |
| b69ab31 | | | 75 | |
| b69ab31 | | | 76 | // Create a client instance |
| b69ab31 | | | 77 | const client = new EdenFSNotificationsClient({ |
| b69ab31 | | | 78 | mountPoint: null, |
| b69ab31 | | | 79 | timeout: 1000, // 1 second timeout |
| b69ab31 | | | 80 | edenBinaryPath: process.env.EDEN_PATH ? process.env.EDEN_PATH : 'eden', |
| b69ab31 | | | 81 | }); |
| b69ab31 | | | 82 | |
| b69ab31 | | | 83 | try { |
| b69ab31 | | | 84 | // Get changes since a specific position (if you have one) |
| b69ab31 | | | 85 | console.log('\nGetting recent changes...'); |
| b69ab31 | | | 86 | const changes = await client.getChangesSince({ |
| b69ab31 | | | 87 | position: position, // Start from current position |
| b69ab31 | | | 88 | }); |
| b69ab31 | | | 89 | console.log('Changes:', JSON.stringify(changes, null, 2)); |
| b69ab31 | | | 90 | |
| b69ab31 | | | 91 | // Extract file paths from changes |
| b69ab31 | | | 92 | if (changes.changes && changes.changes.length > 0) { |
| b69ab31 | | | 93 | const paths = EdenFSUtils.extractPaths(changes.changes); |
| b69ab31 | | | 94 | console.log('Changed files:', paths); |
| b69ab31 | | | 95 | } |
| b69ab31 | | | 96 | } catch (error) { |
| b69ab31 | | | 97 | console.error('Error:', error.message); |
| b69ab31 | | | 98 | } |
| b69ab31 | | | 99 | } |
| b69ab31 | | | 100 | |
| b69ab31 | | | 101 | async function subscriptionExample() { |
| b69ab31 | | | 102 | console.log('\n=== Subscription Example ==='); |
| b69ab31 | | | 103 | |
| b69ab31 | | | 104 | const client = new EdenFSNotificationsClient({ |
| b69ab31 | | | 105 | // mountPoint: '/path/to/your/eden/mount' // Replace with your actual mount point |
| b69ab31 | | | 106 | edenBinaryPath: process.env.EDEN_PATH ? process.env.EDEN_PATH : 'eden', |
| b69ab31 | | | 107 | }); |
| b69ab31 | | | 108 | |
| b69ab31 | | | 109 | try { |
| b69ab31 | | | 110 | // Create a subscription for real-time changes |
| b69ab31 | | | 111 | const subscription = client.subscribe( |
| b69ab31 | | | 112 | { |
| b69ab31 | | | 113 | throttle: 100, // 100ms throttle between events |
| b69ab31 | | | 114 | includedSuffixes: ['.js', '.ts', '.py'], // Only watch specific file types |
| b69ab31 | | | 115 | excludedRoots: ['node_modules', '.git'], // Exclude certain directories |
| b69ab31 | | | 116 | deferredStates: ['test'], // Wait for these states to be deasserted |
| b69ab31 | | | 117 | }, |
| b69ab31 | | | 118 | (error, resp) => { |
| b69ab31 | | | 119 | if (error) { |
| b69ab31 | | | 120 | console.error('Subscription error:', error.message); |
| b69ab31 | | | 121 | return; |
| b69ab31 | | | 122 | } else if (resp === null) { |
| b69ab31 | | | 123 | console.error('Subscription closed'); |
| b69ab31 | | | 124 | return; |
| b69ab31 | | | 125 | } else { |
| b69ab31 | | | 126 | console.log('\n--- File System Change Detected ---'); |
| b69ab31 | | | 127 | if (resp.to_position) { |
| b69ab31 | | | 128 | console.log('Position:', resp.to_position); |
| b69ab31 | | | 129 | } else if (resp.position) { |
| b69ab31 | | | 130 | console.log('Position:', resp.position); |
| b69ab31 | | | 131 | } else { |
| b69ab31 | | | 132 | console.error('Unknown response'); |
| b69ab31 | | | 133 | } |
| b69ab31 | | | 134 | |
| b69ab31 | | | 135 | if (resp.changes && resp.changes.length > 0) { |
| b69ab31 | | | 136 | resp.changes.forEach(change => { |
| b69ab31 | | | 137 | const changeType = EdenFSUtils.getChangeType(change); |
| b69ab31 | | | 138 | if (change.SmallChange) { |
| b69ab31 | | | 139 | const paths = EdenFSUtils.extractPaths([change]); |
| b69ab31 | | | 140 | console.log(`${changeType.toUpperCase()}: ${paths.join(', ')}`); |
| b69ab31 | | | 141 | } else if (change.LargeChange) { |
| b69ab31 | | | 142 | if (changeType == 'directory renamed') { |
| b69ab31 | | | 143 | console.log( |
| b69ab31 | | | 144 | `${changeType.toUpperCase()}: From ${EdenFSUtils.bytesToPath(change.LargeChange.DirectoryRenamed.from)} to ${EdenFSUtils.bytesToPath(change.LargeChange.DirectoryRenamed.to)}`, |
| b69ab31 | | | 145 | ); |
| b69ab31 | | | 146 | } else if (changeType == 'commit transition') { |
| b69ab31 | | | 147 | console.log( |
| b69ab31 | | | 148 | `${changeType.toUpperCase()}: From ${EdenFSUtils.bytesToHex(change.LargeChange.CommitTransition.from)} to ${EdenFSUtils.bytesToHex(change.LargeChange.CommitTransition.to)}`, |
| b69ab31 | | | 149 | ); |
| b69ab31 | | | 150 | } else if (changeType == 'lost changes') { |
| b69ab31 | | | 151 | console.log( |
| b69ab31 | | | 152 | `${changeType.toUpperCase()}: ${change.LargeChange.LostChanges.reason}`, |
| b69ab31 | | | 153 | ); |
| b69ab31 | | | 154 | } else { |
| b69ab31 | | | 155 | console.log(`Unknown large change: ${JSON.stringify(change)}`); |
| b69ab31 | | | 156 | } |
| b69ab31 | | | 157 | } |
| b69ab31 | | | 158 | }); |
| b69ab31 | | | 159 | } else if (resp.state) { |
| b69ab31 | | | 160 | console.log(`State change: ${resp.event_type} ${resp.state}`); |
| b69ab31 | | | 161 | } else { |
| b69ab31 | | | 162 | console.error(`Unknown response: ${JSON.stringify(resp)}`); |
| b69ab31 | | | 163 | } |
| b69ab31 | | | 164 | } |
| b69ab31 | | | 165 | }, |
| b69ab31 | | | 166 | ); |
| b69ab31 | | | 167 | |
| b69ab31 | | | 168 | // Start the subscription |
| b69ab31 | | | 169 | console.log('Starting subscription...'); |
| b69ab31 | | | 170 | await subscription.start(); |
| b69ab31 | | | 171 | console.log('Subscription active. Make some file changes to see events.'); |
| b69ab31 | | | 172 | console.log('Press Ctrl+C to stop.'); |
| b69ab31 | | | 173 | |
| b69ab31 | | | 174 | // Keep the process running |
| b69ab31 | | | 175 | process.on('SIGINT', async () => { |
| b69ab31 | | | 176 | console.log('\nStopping subscription...'); |
| b69ab31 | | | 177 | // Wait until the subscription has fully exited before terminating |
| b69ab31 | | | 178 | subscription.on('exit', () => { |
| b69ab31 | | | 179 | console.log('Subscription exited'); |
| b69ab31 | | | 180 | process.exit(0); |
| b69ab31 | | | 181 | }); |
| b69ab31 | | | 182 | subscription.stop(); |
| b69ab31 | | | 183 | }); |
| b69ab31 | | | 184 | |
| b69ab31 | | | 185 | // Prevent the script from exiting |
| b69ab31 | | | 186 | await new Promise(() => {}); |
| b69ab31 | | | 187 | } catch (error) { |
| b69ab31 | | | 188 | console.error('Subscription error:', error.message); |
| b69ab31 | | | 189 | } |
| b69ab31 | | | 190 | } |
| b69ab31 | | | 191 | |
| b69ab31 | | | 192 | async function stateExample() { |
| b69ab31 | | | 193 | console.log('\n=== State Management Example ==='); |
| b69ab31 | | | 194 | |
| b69ab31 | | | 195 | const client = new EdenFSNotificationsClient({ |
| b69ab31 | | | 196 | // mountPoint: '/path/to/your/eden/mount' // Replace with your actual mount point |
| b69ab31 | | | 197 | edenBinaryPath: process.env.EDEN_PATH ? process.env.EDEN_PATH : 'eden', |
| b69ab31 | | | 198 | }); |
| b69ab31 | | | 199 | |
| b69ab31 | | | 200 | try { |
| b69ab31 | | | 201 | // Enter a state for 10 seconds |
| b69ab31 | | | 202 | console.log('Entering "build" state for 10 seconds...'); |
| b69ab31 | | | 203 | await client.enterState('build', {duration: 10}); |
| b69ab31 | | | 204 | console.log('State entered successfully'); |
| b69ab31 | | | 205 | } catch (error) { |
| b69ab31 | | | 206 | console.error('State error:', error.message); |
| b69ab31 | | | 207 | } |
| b69ab31 | | | 208 | } |
| b69ab31 | | | 209 | |
| b69ab31 | | | 210 | async function advancedSubscriptionExample() { |
| b69ab31 | | | 211 | console.log('\n=== Advanced Subscription with States ==='); |
| b69ab31 | | | 212 | |
| b69ab31 | | | 213 | const client = new EdenFSNotificationsClient({ |
| b69ab31 | | | 214 | // mountPoint: '/path/to/your/eden/mount' // Replace with your actual mount point |
| b69ab31 | | | 215 | edenBinaryPath: process.env.EDEN_PATH ? process.env.EDEN_PATH : 'eden', |
| b69ab31 | | | 216 | }); |
| b69ab31 | | | 217 | |
| b69ab31 | | | 218 | try { |
| b69ab31 | | | 219 | // Create a subscription that waits for certain states to be deasserted |
| b69ab31 | | | 220 | const subscription = client.subscribe( |
| b69ab31 | | | 221 | { |
| b69ab31 | | | 222 | deferredStates: ['build', 'test'], // Wait for these states to be deasserted |
| b69ab31 | | | 223 | throttle: 50, |
| b69ab31 | | | 224 | includedSuffixes: ['.js', '.ts', '.json'], |
| b69ab31 | | | 225 | }, |
| b69ab31 | | | 226 | (error, resp) => { |
| b69ab31 | | | 227 | if (error) { |
| b69ab31 | | | 228 | console.error('Subscription error:', error.message); |
| b69ab31 | | | 229 | return; |
| b69ab31 | | | 230 | } |
| b69ab31 | | | 231 | |
| b69ab31 | | | 232 | console.log('\n--- File System Change Detected ---'); |
| b69ab31 | | | 233 | if (resp.to_position) { |
| b69ab31 | | | 234 | console.log('Position:', resp.to_position); |
| b69ab31 | | | 235 | } else if (resp.position) { |
| b69ab31 | | | 236 | console.log('Position:', resp.position); |
| b69ab31 | | | 237 | } else { |
| b69ab31 | | | 238 | console.error('Unknown response: ', resp); |
| b69ab31 | | | 239 | } |
| b69ab31 | | | 240 | |
| b69ab31 | | | 241 | if (resp.changes) { |
| b69ab31 | | | 242 | if (resp.changes.length === 0) { |
| b69ab31 | | | 243 | console.log('no changes'); |
| b69ab31 | | | 244 | } |
| b69ab31 | | | 245 | resp.changes.forEach(change => { |
| b69ab31 | | | 246 | const changeType = EdenFSUtils.getChangeType(change); |
| b69ab31 | | | 247 | if (change.SmallChange) { |
| b69ab31 | | | 248 | const paths = EdenFSUtils.extractPaths([change]); |
| b69ab31 | | | 249 | console.log(`${changeType.toUpperCase()}: ${paths.join(', ')}`); |
| b69ab31 | | | 250 | } else if (change.LargeChange) { |
| b69ab31 | | | 251 | if (changeType == 'directory renamed') { |
| b69ab31 | | | 252 | console.log( |
| b69ab31 | | | 253 | `${changeType.toUpperCase()}: From ${EdenFSUtils.bytesToPath(change.LargeChange.DirectoryRenamed.from)} to ${EdenFSUtils.bytesToPath(change.LargeChange.DirectoryRenamed.to)}`, |
| b69ab31 | | | 254 | ); |
| b69ab31 | | | 255 | } else if (changeType == 'commit transition') { |
| b69ab31 | | | 256 | console.log( |
| b69ab31 | | | 257 | `${changeType.toUpperCase()}: From ${EdenFSUtils.bytesToHex(change.LargeChange.CommitTransition.from)} to ${EdenFSUtils.bytesToHex(change.LargeChange.CommitTransition.to)}`, |
| b69ab31 | | | 258 | ); |
| b69ab31 | | | 259 | } else if (changeType == 'lost changes') { |
| b69ab31 | | | 260 | console.log( |
| b69ab31 | | | 261 | `${changeType.toUpperCase()}: ${change.LargeChange.LostChanges.reason}`, |
| b69ab31 | | | 262 | ); |
| b69ab31 | | | 263 | } else { |
| b69ab31 | | | 264 | console.log(`Unknown large change: ${JSON.stringify(change)}`); |
| b69ab31 | | | 265 | } |
| b69ab31 | | | 266 | } |
| b69ab31 | | | 267 | }); |
| b69ab31 | | | 268 | } else if (resp.state) { |
| b69ab31 | | | 269 | console.log(`State change: ${resp.event_type} ${resp.state}`); |
| b69ab31 | | | 270 | } else { |
| b69ab31 | | | 271 | console.error(`Unknown response: ${JSON.stringify(resp)}`); |
| b69ab31 | | | 272 | } |
| b69ab31 | | | 273 | }, |
| b69ab31 | | | 274 | ); |
| b69ab31 | | | 275 | |
| b69ab31 | | | 276 | await subscription.start(); |
| b69ab31 | | | 277 | console.log('Advanced subscription started. Try entering/exiting states.'); |
| b69ab31 | | | 278 | |
| b69ab31 | | | 279 | // Simulate entering and exiting states |
| b69ab31 | | | 280 | setTimeout(async () => { |
| b69ab31 | | | 281 | console.log('\nEntering build state...'); |
| b69ab31 | | | 282 | await client.enterState('build', {duration: 5}); |
| b69ab31 | | | 283 | }, 2000); |
| b69ab31 | | | 284 | |
| b69ab31 | | | 285 | setTimeout(async () => { |
| b69ab31 | | | 286 | console.log('\nEntering test state...'); |
| b69ab31 | | | 287 | await client.enterState('test', {duration: 3}); |
| b69ab31 | | | 288 | }, 8000); |
| b69ab31 | | | 289 | |
| b69ab31 | | | 290 | // Keep running for demo |
| b69ab31 | | | 291 | setTimeout(() => { |
| b69ab31 | | | 292 | subscription.stop(); |
| b69ab31 | | | 293 | console.log('\nDemo completed'); |
| b69ab31 | | | 294 | process.exit(0); |
| b69ab31 | | | 295 | }, 15000); |
| b69ab31 | | | 296 | } catch (error) { |
| b69ab31 | | | 297 | console.error('Advanced subscription error:', error.message); |
| b69ab31 | | | 298 | } |
| b69ab31 | | | 299 | } |
| b69ab31 | | | 300 | |
| b69ab31 | | | 301 | async function utilityExample() { |
| b69ab31 | | | 302 | console.log('\n=== Utility Functions Example ==='); |
| b69ab31 | | | 303 | |
| b69ab31 | | | 304 | // Example change data (as returned by EdenFS) |
| b69ab31 | | | 305 | const exampleChanges = [ |
| b69ab31 | | | 306 | { |
| b69ab31 | | | 307 | SmallChange: { |
| b69ab31 | | | 308 | Added: { |
| b69ab31 | | | 309 | file_type: 'Regular', |
| b69ab31 | | | 310 | path: [104, 101, 108, 108, 111, 46, 116, 120, 116], // "hello.txt" in bytes |
| b69ab31 | | | 311 | }, |
| b69ab31 | | | 312 | }, |
| b69ab31 | | | 313 | }, |
| b69ab31 | | | 314 | { |
| b69ab31 | | | 315 | SmallChange: { |
| b69ab31 | | | 316 | Modified: { |
| b69ab31 | | | 317 | file_type: 'Regular', |
| b69ab31 | | | 318 | path: [119, 111, 114, 108, 100, 46, 106, 115], // "world.js" in bytes |
| b69ab31 | | | 319 | }, |
| b69ab31 | | | 320 | }, |
| b69ab31 | | | 321 | }, |
| b69ab31 | | | 322 | { |
| b69ab31 | | | 323 | SmallChange: { |
| b69ab31 | | | 324 | Renamed: { |
| b69ab31 | | | 325 | file_type: 'Regular', |
| b69ab31 | | | 326 | from: [111, 108, 100, 46, 116, 120, 116], // "old.txt" in bytes |
| b69ab31 | | | 327 | to: [110, 101, 119, 46, 116, 120, 116], // "new.txt" in bytes |
| b69ab31 | | | 328 | }, |
| b69ab31 | | | 329 | }, |
| b69ab31 | | | 330 | }, |
| b69ab31 | | | 331 | { |
| b69ab31 | | | 332 | LargeChange: { |
| b69ab31 | | | 333 | CommitTransition: { |
| b69ab31 | | | 334 | from: [111, 108, 100, 46, 116, 120, 116], // "old.txt" in bytes |
| b69ab31 | | | 335 | to: [110, 101, 119, 46, 116, 120, 116], // "new.txt" in bytes |
| b69ab31 | | | 336 | }, |
| b69ab31 | | | 337 | }, |
| b69ab31 | | | 338 | }, |
| b69ab31 | | | 339 | { |
| b69ab31 | | | 340 | StateChange: { |
| b69ab31 | | | 341 | StateEntered: { |
| b69ab31 | | | 342 | name: 'meerkat', |
| b69ab31 | | | 343 | }, |
| b69ab31 | | | 344 | }, |
| b69ab31 | | | 345 | }, |
| b69ab31 | | | 346 | ]; |
| b69ab31 | | | 347 | |
| b69ab31 | | | 348 | // Extract paths from changes |
| b69ab31 | | | 349 | console.log('Extracting single path'); |
| b69ab31 | | | 350 | const [path1, path2] = EdenFSUtils.extractPath(exampleChanges[0].SmallChange); |
| b69ab31 | | | 351 | console.log('Extracted paths:', path1, path2); |
| b69ab31 | | | 352 | console.log('Extracting multiple paths:'); |
| b69ab31 | | | 353 | const paths = EdenFSUtils.extractPaths(exampleChanges); |
| b69ab31 | | | 354 | console.log('Extracted paths:', paths); |
| b69ab31 | | | 355 | console.log('Extracting types:'); |
| b69ab31 | | | 356 | const type = EdenFSUtils.extractFileType(exampleChanges[0].SmallChange); |
| b69ab31 | | | 357 | console.log('Extracted file type:', type); |
| b69ab31 | | | 358 | |
| b69ab31 | | | 359 | // Get change types |
| b69ab31 | | | 360 | exampleChanges.forEach((change, index) => { |
| b69ab31 | | | 361 | const changeType = EdenFSUtils.getChangeType(change); |
| b69ab31 | | | 362 | console.log(`Change ${index + 1} type:`, changeType); |
| b69ab31 | | | 363 | }); |
| b69ab31 | | | 364 | } |
| b69ab31 | | | 365 | |
| b69ab31 | | | 366 | // Run examples |
| b69ab31 | | | 367 | async function runExamples() { |
| b69ab31 | | | 368 | console.log('EdenFS Notify JavaScript Interface Examples'); |
| b69ab31 | | | 369 | console.log('=========================================='); |
| b69ab31 | | | 370 | |
| b69ab31 | | | 371 | // Note: Update the mount point in each example before running |
| b69ab31 | | | 372 | console.log('\nNOTE: Please update the mount point paths in the examples before running!'); |
| b69ab31 | | | 373 | |
| b69ab31 | | | 374 | try { |
| b69ab31 | | | 375 | await basicExample(); |
| b69ab31 | | | 376 | await waitReadyExample(); |
| b69ab31 | | | 377 | if (process.argv.length > 2) { |
| b69ab31 | | | 378 | await changesExample(process.argv[2]); |
| b69ab31 | | | 379 | } |
| b69ab31 | | | 380 | await utilityExample(); |
| b69ab31 | | | 381 | |
| b69ab31 | | | 382 | // Uncomment these to run interactive examples: |
| b69ab31 | | | 383 | // await subscriptionExample(); |
| b69ab31 | | | 384 | // await stateExample(); |
| b69ab31 | | | 385 | // await advancedSubscriptionExample(); |
| b69ab31 | | | 386 | } catch (error) { |
| b69ab31 | | | 387 | console.error('Example error:', error.message); |
| b69ab31 | | | 388 | } |
| b69ab31 | | | 389 | } |
| b69ab31 | | | 390 | |
| b69ab31 | | | 391 | // Run if this file is executed directly |
| b69ab31 | | | 392 | if (require.main === module) { |
| b69ab31 | | | 393 | runExamples(); |
| b69ab31 | | | 394 | } |