fix(streaming): Convert smartrequest v5 web ReadableStreams to Node.js streams and update deps for streaming compatibility
This commit is contained in:
@@ -182,8 +182,12 @@ export class DockerHost {
|
||||
*/
|
||||
public async getEventObservable(): Promise<plugins.rxjs.Observable<any>> {
|
||||
const response = await this.requestStreaming('GET', '/events');
|
||||
|
||||
// requestStreaming now returns Node.js stream, not web stream
|
||||
const nodeStream = response as plugins.smartstream.stream.Readable;
|
||||
|
||||
return plugins.rxjs.Observable.create((observer) => {
|
||||
response.on('data', (data) => {
|
||||
nodeStream.on('data', (data) => {
|
||||
const eventString = data.toString();
|
||||
try {
|
||||
const eventObject = JSON.parse(eventString);
|
||||
@@ -193,7 +197,7 @@ export class DockerHost {
|
||||
}
|
||||
});
|
||||
return () => {
|
||||
response.emit('end');
|
||||
nodeStream.emit('end');
|
||||
};
|
||||
});
|
||||
}
|
||||
@@ -347,7 +351,7 @@ export class DockerHost {
|
||||
}
|
||||
|
||||
// Execute the request based on method
|
||||
let response;
|
||||
let response: plugins.smartrequest.ICoreResponse;
|
||||
switch (methodArg.toUpperCase()) {
|
||||
case 'GET':
|
||||
response = await smartRequest.get();
|
||||
@@ -367,10 +371,10 @@ export class DockerHost {
|
||||
|
||||
console.log(response.status);
|
||||
|
||||
// For streaming responses, get the Node.js stream
|
||||
const nodeStream = response.streamNode();
|
||||
// For streaming responses, get the web stream
|
||||
const webStream = response.stream();
|
||||
|
||||
if (!nodeStream) {
|
||||
if (!webStream) {
|
||||
// If no stream is available, consume the body as text
|
||||
const body = await response.text();
|
||||
console.log(body);
|
||||
@@ -383,7 +387,10 @@ export class DockerHost {
|
||||
};
|
||||
}
|
||||
|
||||
// For streaming responses, return the stream with added properties
|
||||
// Convert web ReadableStream to Node.js stream for backward compatibility
|
||||
const nodeStream = plugins.smartstream.nodewebhelpers.convertWebReadableToNodeReadable(webStream);
|
||||
|
||||
// Add properties for compatibility
|
||||
(nodeStream as any).statusCode = response.status;
|
||||
(nodeStream as any).body = ''; // For compatibility
|
||||
|
||||
|
||||
Reference in New Issue
Block a user