Skip to content

Commit 6491138

Browse files
committed
Added a new method U.aistreamer(on_line, on_message).
1 parent bee2b26 commit 6491138

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
- fixed Total error handling
2020
- improved compiling navigation in the CMS compiler
2121
- fixed filling of the `template` property in the CMS compiler
22+
- added a new method `U.aistreamer(on_line, on_message)`
2223

2324
========================
2425
0.0.15

utils.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1565,6 +1565,27 @@ exports.streamer2 = function(beg, end, callback, skip, stream) {
15651565
return exports.streamer(beg, end, callback, skip, stream, true);
15661566
};
15671567

1568+
exports.aistreamer = function(online, onmessage) {
1569+
let buffer = '';
1570+
let c = '\n';
1571+
let date = onmessage != null;
1572+
return U.streamer(c, function(line) {
1573+
let obj = line.parseJSON(date);
1574+
if (obj) {
1575+
buffer += obj.message.content;
1576+
let index = 0;
1577+
while (index != -1) {
1578+
index = buffer.indexOf(c);
1579+
if (index != -1) {
1580+
online && online(buffer.substring(0, index));
1581+
buffer = buffer.substring(index + 1);
1582+
}
1583+
}
1584+
onmessage && onmessage(obj);
1585+
}
1586+
});
1587+
};
1588+
15681589
exports.filestreamer = function(filename, onbuffer, onend, size) {
15691590

15701591
if (typeof(onend) === 'number') {

0 commit comments

Comments
 (0)