gemercheung vor 3 Jahren
Ursprung
Commit
705ce831c4
2 geänderte Dateien mit 19 neuen und 95 gelöschten Zeilen
  1. 2 1
      config.production1.yaml
  2. 17 94
      src/scene/stream/stream.service.ts

+ 2 - 1
config.production1.yaml

@@ -36,7 +36,8 @@ redis:
 #  server: ['stun:4dage:4dage168@47.107.125.202:3478','stun:120.24.252.95:3478']
 # ['turn:4dage:4dage168@turn.4dage.com:4478', 'stun:stun.callwithus.com:3478']
 stun:
-  server: ['stun:stun.callwithus.com:3478', 'stun:47.107.125.202:3478']
+  # server: ['stun:stun.callwithus.com:3478', 'stun:47.107.125.202:3478']
+  server: ['175.178.12.158:3478','106.55.177.178:3478']
   portRangeBegin: 49152
   portRangeEnd: 65535
 

+ 17 - 94
src/scene/stream/stream.service.ts

@@ -160,24 +160,14 @@ export class StreamService {
 
         const metaDataString = metaData.replace(/\s/g, '');
         const coordBuff = Buffer.from(metaDataString, 'utf-8');
-        // console.warn('coordBuff', coordBuff.byteLength);
-        // const steamStat = statSync(clipPath);
-        // const steamTotalSize = metaData.length + steamStat.size;
-
         const clipBuffer = readFileSync(clipPath);
 
         const allData = Buffer.concat([coordBuff, clipBuffer]);
-        // console.log('allData', allData);
-        // const stream1 = new ReadableStream(allData, {
-        //   highWaterMark: this.chunk_size - this.block,
-        // });
+
         const slices = Math.floor(
           allData.byteLength / (this.chunk_size - this.block),
         );
 
-        console.log('allData', allData.byteLength);
-        console.log('slices', slices);
-
         let steamByteLength = 0;
 
         for (let i = 0; i <= slices; i++) {
@@ -224,28 +214,29 @@ export class StreamService {
           framePack.setUint32(this.block - 4, steamByteLength);
           steamByteLength += currentSlice.byteLength;
           // const isLastFrame = framePack.byteLength - this.chunk_size < 0;
-
+          let isPush: boolean;
           // this.logger.log('statusPack', statusPack);
           if (this.channel && this.channel.isOpen()) {
-            const isPush = this.channel.sendMessageBinary(
+            isPush = this.channel.sendMessageBinary(
               Buffer.from(framePack.buffer),
             );
-            if (isPush) {
-              console.log('slice push');
-            }
           }
 
           if (i === slices) {
-            this.onSteaming.next(false);
-            steamByteLength = 0;
-            // debugger;
-            const stop = performance.now();
-            const inMillSeconds = stop - start;
-            const rounded = Number(inMillSeconds).toFixed(3);
-            this.logger.log(
-              `[timer]-当前流:${stream.clipPath}流耗时-->${rounded}ms`,
-            );
-            return resolve({ frame: stream.frame, done: true });
+            if (isPush) {
+              this.onSteaming.next(false);
+              steamByteLength = 0;
+              // debugger;
+              const stop = performance.now();
+              const inMillSeconds = stop - start;
+              const rounded = Number(inMillSeconds).toFixed(3);
+              this.logger.log(
+                `[timer]-当前流:${stream.clipPath}流耗时-->${rounded}ms`,
+              );
+              return resolve({ frame: stream.frame, done: true });
+            } else {
+              return resolve({ frame: stream.frame, done: false });
+            }
           }
         }
         // let steamByteLength = 0;
@@ -256,74 +247,6 @@ export class StreamService {
           frame,
           dir,
         );
-        // steam.on('data', (data: Buffer) => {
-        //   this.onSteaming.next(true);
-
-        //   // this.logger.log('data', data, data.byteLength);
-        //   const blockBuffStart = Buffer.alloc(this.block);
-        //   const packBuffer = Buffer.concat([blockBuffStart, data]);
-
-        //   const framePack = new DataView(
-        //     packBuffer.buffer.slice(
-        //       packBuffer.byteOffset,
-        //       packBuffer.byteOffset + packBuffer.byteLength,
-        //     ),
-        //   );
-
-        //   // 16 bit slot
-        //   // framePack.setUint32(4)
-        //   framePack.setUint16(6, this.block);
-        //   framePack.setUint16(8, frame); // first render cnt
-        //   framePack.setUint16(10, dir); // isDIR
-        //   framePack.setUint16(24, 0);
-        //   framePack.setUint16(26, 0);
-
-        //   // 32 bit slot
-        //   // statusPack.setUint32(12, buff.byteLength);
-        //   // this.logger.log('metaLen', coordBuff.byteLength);
-        //   // this.logger.log('metaLen', clipBuffer.byteLength);
-
-        //   framePack.setUint32(0, 1437227610);
-        //   framePack.setUint32(12, coordBuff.byteLength); // metaLen
-        //   framePack.setUint32(16, clipBuffer.byteLength); // mediaLen
-        //   framePack.setUint32(20, serverTime); //server_time
-        //   framePack.setUint32(24, 0);
-        //   framePack.setUint32(28, 0);
-        //   framePack.setUint32(this.block - 4, steamByteLength);
-        //   const isLastFrame = framePack.byteLength - this.chunk_size < 0;
-
-        //   // this.logger.log('statusPack', statusPack);
-        //   if (this.channel && this.channel.isOpen()) {
-        //     this.channel.sendMessageBinary(Buffer.from(framePack.buffer));
-        //   }
-        //   steamByteLength += data.byteLength;
-        //   if (isLastFrame) {
-        //     // this.logger.log('isLastFrame', isLastFrame);
-        //     // steamByteLength = 0;
-        //     // this.onSteaming.next(false);
-        //     steam.stop();
-        //   }
-        // });
-        // //TODO steam can't trigger end
-        // steam.on('end', () => {
-        //   steamByteLength = 0;
-        //   // this.logger.log('stream end');
-        //   const stop = performance.now();
-        //   const inMillSeconds = stop - start;
-        //   const rounded = Number(inMillSeconds).toFixed(3);
-        //   this.logger.log(
-        //     `[timer]-当前流:${stream.clipPath}流耗时-->${rounded}ms`,
-        //   );
-        //   if (this.onSteaming.value) {
-        //     this.onSteaming.next(false);
-        //   }
-
-        //   return resolve({ frame: stream.frame, done: true });
-        // });
-        // steam.on('error', (error) => {
-        //   this.logger.error('steam-error', error.message);
-        //   return reject({ frame: stream.frame, done: false });
-        // });
       } catch (error) {
         this.logger.error(error);
         return reject({ frame: stream.frame, done: false });