@ejfdelgado/ejflab-back 1.22.2 → 1.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ejfdelgado/ejflab-back",
3
- "version": "1.22.2",
3
+ "version": "1.23.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/ejfdelgado/ejflab-back.git"
@@ -35,6 +35,8 @@ import { OpenVideoChatProcessor } from "./callprocessors/OpenVideoChatProcessor.
35
35
  import { CloseVideoChatProcessor } from "./callprocessors/CloseVideoChatProcessor.mjs";
36
36
  import { IncludeOtherPeersProcessor } from "./callprocessors/IncludeOtherPeersProcessor.mjs";
37
37
 
38
+ import stream from "stream";
39
+
38
40
  export class SocketIOCall {
39
41
  static io;
40
42
  static mutex = new Mutex();
@@ -417,7 +419,7 @@ export class SocketIOCall {
417
419
  decoded = decode(buffer);
418
420
  }
419
421
  //console.log(decoded);
420
- const { processorMethod, room, channel } = decoded;
422
+ const { processorMethod, room, channel, data } = decoded;
421
423
  const parts = /(^[^\d\.]+)(\d*)\.(.*)$/.exec(processorMethod);
422
424
  if (!parts) {
423
425
  throw Error(`processorMethod ${processorMethod} does not matches /(^[^\d\.]+)(\d*)\.(.*)$/`);
@@ -490,17 +492,48 @@ export class SocketIOCall {
490
492
  const encoded = encode(decoded);
491
493
  const buffer = Buffer.from(encoded);
492
494
  console.log(`POST to ${postUrl}...`);
493
- const temp = await axios.post(`${postUrl}/syncprocess`, buffer, options);
495
+ let isStream = false;
496
+ if (decoded.data?.streaming) {
497
+ isStream = true;
498
+ options['responseType'] = 'stream';
499
+ console.log("Prepare to receive streaming...");
500
+ }
501
+ const fullUrl = `${postUrl}/syncprocess`;
502
+ console.log(fullUrl);
503
+ const temp = await axios.post(fullUrl, buffer, options);
494
504
  console.log(`POST to ${postUrl}... OK!`);
495
- promesa = Promise.resolve({ data: temp.data });
505
+ //console.log('Response status:', temp.status);
506
+ //console.log('Response headers:', temp.headers);
507
+ promesa = Promise.resolve({ data: temp.data, isStream });
496
508
  }
497
509
 
498
-
499
510
  const respuesta = await promesa;
500
- res.status(200).send({
501
- status: "ok",
502
- response: respuesta
503
- });
511
+ if (!respuesta.isStream) {
512
+ res.status(200).send({
513
+ status: "ok",
514
+ response: respuesta
515
+ });
516
+ } else {
517
+
518
+ res.status(200);
519
+ res.setHeader('Content-Type', 'text/plain; charset=UTF-8');
520
+ res.setHeader('Transfer-Encoding', 'chunked');
521
+
522
+ const pass = new stream.PassThrough();
523
+ pass.on('data', (temp) => {
524
+ res.write(temp);
525
+ res.flush();
526
+ }).on("error", (error) => {
527
+ res.end();
528
+ }).on("finish", () => {
529
+ res.end();
530
+ });
531
+ stream.pipeline(
532
+ respuesta.data,
533
+ pass,
534
+ (err) => { }
535
+ );
536
+ }
504
537
  }
505
538
 
506
539
  static async introspect(req, res, next) {