|
12 | 12 | <body> |
13 | 13 | <main id="webchat"></main> |
14 | 14 | <script type="module"> |
| 15 | + const streamingFormat = new URL(window.location.href).searchParams.get('streamingFormat') ?? 'channelData'; // can be entity or channelData |
| 16 | + |
| 17 | + function addLivestreamingMetadata(activity, livestreamingMetadata) { |
| 18 | + return streamingFormat === 'entity' |
| 19 | + ? { |
| 20 | + ...activity, |
| 21 | + entities: [...(activity.entities ?? []), { ...livestreamingMetadata, type: 'streaminfo' }] |
| 22 | + } |
| 23 | + : { |
| 24 | + ...activity, |
| 25 | + channelData: { ...activity.channelData, ...livestreamingMetadata } |
| 26 | + }; |
| 27 | + } |
| 28 | + |
15 | 29 | run(async function () { |
16 | 30 | const { |
17 | 31 | React: { createElement }, |
|
61 | 75 | // WHEN: Bot is typing a message. |
62 | 76 | const firstTypingActivityId = 't-00001'; |
63 | 77 |
|
64 | | - await directLine.emulateIncomingActivity({ |
65 | | - channelData: { streamSequence: 1, streamType: 'streaming' }, |
66 | | - from: { id: 'u-00001', name: 'Bot', role: 'bot' }, |
67 | | - id: firstTypingActivityId, |
68 | | - text: 'A quick', |
69 | | - type: 'typing' |
70 | | - }); |
| 78 | + await directLine.emulateIncomingActivity( |
| 79 | + addLivestreamingMetadata( |
| 80 | + { |
| 81 | + from: { id: 'u-00001', name: 'Bot', role: 'bot' }, |
| 82 | + id: firstTypingActivityId, |
| 83 | + text: 'A quick', |
| 84 | + type: 'typing' |
| 85 | + }, |
| 86 | + { streamSequence: 1, streamType: 'streaming' } |
| 87 | + ) |
| 88 | + ); |
71 | 89 |
|
72 | 90 | let secondActivityKey = currentActivityKeysWithId[1][0]; |
73 | 91 |
|
|
123 | 141 | // --- |
124 | 142 |
|
125 | 143 | // WHEN: Bot continue typing the message. |
126 | | - await directLine.emulateIncomingActivity({ |
127 | | - channelData: { streamId: firstTypingActivityId, streamSequence: 2, streamType: 'streaming' }, |
128 | | - from: { id: 'u-00001', name: 'Bot', role: 'bot' }, |
129 | | - id: 't-00002', |
130 | | - text: 'A quick brown fox', |
131 | | - type: 'typing' |
132 | | - }); |
| 144 | + await directLine.emulateIncomingActivity( |
| 145 | + addLivestreamingMetadata( |
| 146 | + { |
| 147 | + from: { id: 'u-00001', name: 'Bot', role: 'bot' }, |
| 148 | + id: 't-00002', |
| 149 | + text: 'A quick brown fox', |
| 150 | + type: 'typing' |
| 151 | + }, |
| 152 | + { streamId: firstTypingActivityId, streamSequence: 2, streamType: 'streaming' } |
| 153 | + ) |
| 154 | + ); |
133 | 155 |
|
134 | 156 | // THEN: Should display 3 messages, the order should kept the same. |
135 | 157 | await pageConditions.numActivitiesShown(3); |
|
155 | 177 | // --- |
156 | 178 |
|
157 | 179 | // WHEN: Bot continue typing the message. |
158 | | - await directLine.emulateIncomingActivity({ |
159 | | - channelData: { streamId: firstTypingActivityId, streamSequence: 3, streamType: 'streaming' }, |
160 | | - from: { id: 'u-00001', name: 'Bot', role: 'bot' }, |
161 | | - id: 't-00003', |
162 | | - text: 'A quick brown fox jumped over', |
163 | | - type: 'typing' |
164 | | - }); |
| 180 | + await directLine.emulateIncomingActivity( |
| 181 | + addLivestreamingMetadata( |
| 182 | + { |
| 183 | + from: { id: 'u-00001', name: 'Bot', role: 'bot' }, |
| 184 | + id: 't-00003', |
| 185 | + text: 'A quick brown fox jumped over', |
| 186 | + type: 'typing' |
| 187 | + }, |
| 188 | + { streamId: firstTypingActivityId, streamSequence: 3, streamType: 'streaming' } |
| 189 | + ) |
| 190 | + ); |
165 | 191 |
|
166 | 192 | // THEN: Should display 3 messages, the order should kept the same. |
167 | 193 | await pageConditions.numActivitiesShown(3); |
|
187 | 213 | // --- |
188 | 214 |
|
189 | 215 | // WHEN: Bot finished typing the message. |
190 | | - await directLine.emulateIncomingActivity({ |
191 | | - channelData: { streamId: firstTypingActivityId, streamType: 'final' }, |
192 | | - from: { id: 'u-00001', name: 'Bot', role: 'bot' }, |
193 | | - id: 'a-00002', |
194 | | - text: 'A quick brown fox jumped over the lazy dogs.', |
195 | | - type: 'message' |
196 | | - }); |
| 216 | + await directLine.emulateIncomingActivity( |
| 217 | + addLivestreamingMetadata( |
| 218 | + { |
| 219 | + from: { id: 'u-00001', name: 'Bot', role: 'bot' }, |
| 220 | + id: 'a-00002', |
| 221 | + text: 'A quick brown fox jumped over the lazy dogs.', |
| 222 | + type: 'message' |
| 223 | + }, |
| 224 | + { streamId: firstTypingActivityId, streamType: 'final' } |
| 225 | + ) |
| 226 | + ); |
197 | 227 |
|
198 | 228 | // THEN: Should display 3 messages. |
199 | 229 | await pageConditions.numActivitiesShown(3); |
|
0 commit comments