gemercheung 3 years ago
parent
commit
4f9dd2c07b
2 changed files with 20 additions and 8 deletions
  1. 3 1
      .gitignore
  2. 17 7
      src/meta.gateway.ts

+ 3 - 1
.gitignore

@@ -32,4 +32,6 @@ lerna-debug.log*
 !.vscode/settings.json
 !.vscode/settings.json
 !.vscode/tasks.json
 !.vscode/tasks.json
 !.vscode/launch.json
 !.vscode/launch.json
-!.vscode/extensions.json
+!.vscode/extensions.json
+
+ws/*

+ 17 - 7
src/meta.gateway.ts

@@ -118,7 +118,7 @@ export class MetaGateway
     this.peer.onGatheringStateChange((state) => {
     this.peer.onGatheringStateChange((state) => {
       console.log('GatheringState:', state);
       console.log('GatheringState:', state);
     });
     });
-    this.gameChanel = this.peer.createDataChannel('start-game');
+    this.gameChanel = this.peer.createDataChannel('game-input');
 
 
     this.peer.onDataChannel((dc) => {
     this.peer.onDataChannel((dc) => {
       console.log('onDataChannel', dc);
       console.log('onDataChannel', dc);
@@ -127,8 +127,8 @@ export class MetaGateway
     this.gameChanel.onOpen(() => {
     this.gameChanel.onOpen(() => {
       console.log('channel is open');
       console.log('channel is open');
       clearInterval(this.timer);
       clearInterval(this.timer);
-      let i = 0;
-      const paths = path.join(__dirname, '../ws/video/earth');
+      let i = 1;
+      const paths = path.join(__dirname, '../ws/video/v11');
       console.error('__dirname', __dirname);
       console.error('__dirname', __dirname);
       console.error('paths', paths);
       console.error('paths', paths);
       if (this.gameChanel.isOpen()) {
       if (this.gameChanel.isOpen()) {
@@ -136,10 +136,18 @@ export class MetaGateway
         this.sendWertcHeartPack(this.gameChanel);
         this.sendWertcHeartPack(this.gameChanel);
       }
       }
       this.timer = setInterval(() => {
       this.timer = setInterval(() => {
-        if (i < 10) {
-          const steam = createReadStream(paths + `/${i}`);
+        if (i < 9) {
+          const steam = createReadStream(paths + `/${i}.h264`);
+          // const steam = createReadStream(paths + `/test2`);
           steam.on('data', (data: Buffer) => {
           steam.on('data', (data: Buffer) => {
-            this.gameChanel.sendMessageBinary(data);
+            // console.log(data.buffer);
+            const frame = new DataView(data.buffer);
+            // frame.setUint32(0, 1437227610);
+            // frame.setUint16(6, 36);
+            // frame.setUint16(24, 0);
+            // frame.setUint16(26, 0);
+            // frame.setUint32(28, 0);
+            this.gameChanel.sendMessageBinary(Buffer.from(frame.buffer));
           });
           });
         }
         }
         i++;
         i++;
@@ -149,6 +157,9 @@ export class MetaGateway
       console.log('gameChanel close');
       console.log('gameChanel close');
       this.stopSendWertcHeartPack();
       this.stopSendWertcHeartPack();
     });
     });
+    this.gameChanel.onMessage((event) => {
+      console.log('gameChanel onMessage', event);
+    });
     this.gameChanel.onError(() => {
     this.gameChanel.onError(() => {
       console.log('gameChanel close');
       console.log('gameChanel close');
       this.stopSendWertcHeartPack();
       this.stopSendWertcHeartPack();
@@ -189,7 +200,6 @@ export class MetaGateway
   @SubscribeMessage('start')
   @SubscribeMessage('start')
   handlerWebrtcStart(client: any, payload: any) {
   handlerWebrtcStart(client: any, payload: any) {
     console.log('start', payload);
     console.log('start', payload);
-
   }
   }
 
 
   afterInit(server: Server) {
   afterInit(server: Server) {