|
@@ -4,20 +4,7 @@ import { DataChannel } from 'node-datachannel';
|
|
|
import { existsSync, readFileSync } from 'fs';
|
|
|
import * as streamBuffers from 'stream-buffers';
|
|
|
import { BehaviorSubject } from 'rxjs';
|
|
|
-import { CacheService } from 'src/cache/cache.service';
|
|
|
import { join } from 'path';
|
|
|
-import {
|
|
|
- ReadableStream
|
|
|
-} from 'node:stream/web';
|
|
|
-
|
|
|
-import {
|
|
|
- arrayBuffer,
|
|
|
- blob,
|
|
|
- buffer,
|
|
|
- json,
|
|
|
- text,
|
|
|
-} from 'node:stream/consumers';
|
|
|
-
|
|
|
|
|
|
@Injectable()
|
|
|
export class StreamService {
|
|
@@ -40,6 +27,8 @@ export class StreamService {
|
|
|
closeChannel() {
|
|
|
this.channel = null;
|
|
|
}
|
|
|
+
|
|
|
+ public sleep = (ms: number) => new Promise((r) => setTimeout(r, ms));
|
|
|
/**
|
|
|
* stream core push normal stream
|
|
|
* @param data meta Json
|
|
@@ -180,8 +169,8 @@ export class StreamService {
|
|
|
|
|
|
const currentSlice = allData.slice(startSlot, sliceLength);
|
|
|
|
|
|
- console.log('startSlot', startSlot);
|
|
|
- console.log('sliceLength', sliceLength);
|
|
|
+ // console.log('startSlot', startSlot);
|
|
|
+ // console.log('sliceLength', sliceLength);
|
|
|
|
|
|
const blockBuffStart = Buffer.alloc(this.block);
|
|
|
const packBuffer = Buffer.concat([blockBuffStart, currentSlice]);
|
|
@@ -204,7 +193,7 @@ export class StreamService {
|
|
|
// statusPack.setUint32(12, buff.byteLength);
|
|
|
// this.logger.log('metaLen', coordBuff.byteLength);
|
|
|
// this.logger.log('metaLen', clipBuffer.byteLength);
|
|
|
- console.log('steamByteLength', steamByteLength);
|
|
|
+ // console.log('steamByteLength', steamByteLength);
|
|
|
framePack.setUint32(0, 1437227610);
|
|
|
framePack.setUint32(12, coordBuff.byteLength); // metaLen
|
|
|
framePack.setUint32(16, clipBuffer.byteLength); // mediaLen
|
|
@@ -220,6 +209,7 @@ export class StreamService {
|
|
|
const isPush = this.channel.sendMessageBinary(
|
|
|
Buffer.from(framePack.buffer),
|
|
|
);
|
|
|
+
|
|
|
if (i === slices) {
|
|
|
this.onSteaming.next(false);
|
|
|
steamByteLength = 0;
|
|
@@ -231,9 +221,17 @@ export class StreamService {
|
|
|
this.logger.log(
|
|
|
`[timer]-当前流:${stream.clipPath}流耗时-->${rounded}ms`,
|
|
|
);
|
|
|
- return resolve({ frame: stream.frame, done: true });
|
|
|
+ return resolve({
|
|
|
+ frame: stream.frame,
|
|
|
+ done: true,
|
|
|
+ clipPath: stream.clipPath,
|
|
|
+ });
|
|
|
} else {
|
|
|
- return resolve({ frame: stream.frame, done: false });
|
|
|
+ return resolve({
|
|
|
+ frame: stream.frame,
|
|
|
+ done: false,
|
|
|
+ clipPath: stream.clipPath,
|
|
|
+ });
|
|
|
}
|
|
|
}
|
|
|
} else {
|