|
| 1 | +import { createRobotClient } from '../../src/main'; |
| 2 | + |
| 3 | +const main = async () => { |
| 4 | + const machine = await createRobotClient({ |
| 5 | + host: 'e2e-ts-sdk', |
| 6 | + signalingAddress: 'http://localhost:9090', |
| 7 | + iceServers: [{ urls: 'stun:global.stun.twilio.com:3478' }], |
| 8 | + }); |
| 9 | + const resourceNames = await machine.resourceNames(); |
| 10 | + |
| 11 | + const resNamesDiv = document.createElement('div'); |
| 12 | + resNamesDiv.dataset.testid = 'resource-names'; |
| 13 | + for (const resourceName of resourceNames) { |
| 14 | + const resNameDiv = document.createElement('div'); |
| 15 | + resNameDiv.textContent = resourceName.name; |
| 16 | + resNameDiv.dataset.testid = 'resource-name'; |
| 17 | + resNamesDiv.append(resNameDiv); |
| 18 | + } |
| 19 | + document.body.append(resNamesDiv); |
| 20 | + |
| 21 | + const stream = machine.streamStatus(resourceNames); |
| 22 | + const statusesDiv = document.createElement('div'); |
| 23 | + statusesDiv.dataset.testid = 'statuses'; |
| 24 | + |
| 25 | + let i = 0; |
| 26 | + for await (const statuses of stream) { |
| 27 | + for await (const status of statuses) { |
| 28 | + const statusDiv = document.createElement('div'); |
| 29 | + statusDiv.textContent = status.toJsonString(); |
| 30 | + statusDiv.dataset.testid = 'status'; |
| 31 | + statusesDiv.append(statusDiv); |
| 32 | + } |
| 33 | + |
| 34 | + i += 1; |
| 35 | + if (i >= 3) { |
| 36 | + break; |
| 37 | + } |
| 38 | + } |
| 39 | + document.body.append(statusesDiv); |
| 40 | +}; |
| 41 | + |
| 42 | +main().catch(console.error); // eslint-disable-line no-console |
0 commit comments