gemercheung 3 年之前
父节点
当前提交
ee3170d092

+ 3 - 0
libs/utils/src/utils.d.ts

@@ -0,0 +1,3 @@
+interface Number {
+  padLeft(n: number, str: string): string;
+}

+ 11 - 1
libs/utils/src/utils.module.ts

@@ -5,4 +5,14 @@ import { UtilsService } from './utils.service';
   providers: [UtilsService],
   exports: [UtilsService],
 })
-export class UtilsModule {}
+export class UtilsModule {
+  initPadleft(): void {
+    // function padLeft(nr, n, str) {
+    //   return Array(n - String(nr).length + 1).join(str || '0') + nr;
+    // };
+    //or as a Number prototype method:
+    Number.prototype.padLeft = function (n, str) {
+      return Array(n - String(this).length + 1).join(str || '0') + this;
+    };
+  }
+}

+ 124 - 0
package-lock.json

@@ -14,6 +14,7 @@
         "@nestjs/common": "^8.0.0",
         "@nestjs/config": "^2.0.0",
         "@nestjs/core": "^8.0.0",
+        "@nestjs/microservices": "^8.4.4",
         "@nestjs/platform-express": "^8.0.0",
         "@nestjs/platform-socket.io": "^8.4.4",
         "@nestjs/platform-ws": "^8.4.4",
@@ -39,6 +40,7 @@
         "eslint-plugin-prettier": "^4.0.0",
         "jest": "^27.2.5",
         "prettier": "^2.3.2",
+        "rollup-plugin-string": "^3.0.0",
         "source-map-support": "^0.5.20",
         "supertest": "^6.1.3",
         "ts-jest": "^27.0.3",
@@ -1518,6 +1520,60 @@
         }
       }
     },
+    "node_modules/@nestjs/microservices": {
+      "version": "8.4.4",
+      "resolved": "https://registry.npmmirror.com/@nestjs/microservices/-/microservices-8.4.4.tgz",
+      "integrity": "sha512-V1xBs5mBFaWGF7RuLSQBG9ydcvX+j8RxHnk9pYF2I5kBdWt7AyTuG2qMt7es06HXEbgUmavw/zn+P6Q2WQIS5A==",
+      "dependencies": {
+        "iterare": "1.2.1",
+        "json-socket": "0.3.0",
+        "tslib": "2.3.1"
+      },
+      "peerDependencies": {
+        "@grpc/grpc-js": "*",
+        "@nestjs/common": "^8.0.0",
+        "@nestjs/core": "^8.0.0",
+        "@nestjs/websockets": "^8.0.0",
+        "amqp-connection-manager": "*",
+        "amqplib": "*",
+        "cache-manager": "*",
+        "kafkajs": "*",
+        "mqtt": "*",
+        "nats": "*",
+        "redis": "*",
+        "reflect-metadata": "^0.1.12",
+        "rxjs": "^7.1.0"
+      },
+      "peerDependenciesMeta": {
+        "@grpc/grpc-js": {
+          "optional": true
+        },
+        "@nestjs/websockets": {
+          "optional": true
+        },
+        "amqp-connection-manager": {
+          "optional": true
+        },
+        "amqplib": {
+          "optional": true
+        },
+        "cache-manager": {
+          "optional": true
+        },
+        "kafkajs": {
+          "optional": true
+        },
+        "mqtt": {
+          "optional": true
+        },
+        "nats": {
+          "optional": true
+        },
+        "redis": {
+          "optional": true
+        }
+      }
+    },
     "node_modules/@nestjs/platform-express": {
       "version": "8.4.4",
       "resolved": "https://registry.npmmirror.com/@nestjs/platform-express/-/platform-express-8.4.4.tgz",
@@ -4409,6 +4465,12 @@
         "node": ">=4.0"
       }
     },
+    "node_modules/estree-walker": {
+      "version": "0.6.1",
+      "resolved": "https://registry.npmmirror.com/estree-walker/-/estree-walker-0.6.1.tgz",
+      "integrity": "sha512-SqmZANLWS0mnatqbSfRP5g8OXZC12Fgg1IwNtLsyHDzJizORW4khDfjPqJZsemPWBB2uqykUah5YpQ6epsqC/w==",
+      "dev": true
+    },
     "node_modules/esutils": {
       "version": "2.0.3",
       "resolved": "https://registry.npmmirror.com/esutils/-/esutils-2.0.3.tgz",
@@ -6390,6 +6452,11 @@
       "dev": true,
       "license": "MIT"
     },
+    "node_modules/json-socket": {
+      "version": "0.3.0",
+      "resolved": "https://registry.npmmirror.com/json-socket/-/json-socket-0.3.0.tgz",
+      "integrity": "sha512-jc8ZbUnYIWdxERFWQKVgwSLkGSe+kyzvmYxwNaRgx/c8NNyuHes4UHnPM3LUrAFXUx1BhNJ94n1h/KCRlbvV0g=="
+    },
     "node_modules/json-stable-stringify-without-jsonify": {
       "version": "1.0.1",
       "resolved": "https://registry.npmmirror.com/json-stable-stringify-without-jsonify/-/json-stable-stringify-without-jsonify-1.0.1.tgz",
@@ -8433,6 +8500,24 @@
         "url": "https://github.com/sponsors/isaacs"
       }
     },
+    "node_modules/rollup-plugin-string": {
+      "version": "3.0.0",
+      "resolved": "https://registry.npmmirror.com/rollup-plugin-string/-/rollup-plugin-string-3.0.0.tgz",
+      "integrity": "sha512-vqyzgn9QefAgeKi+Y4A7jETeIAU1zQmS6VotH6bzm/zmUQEnYkpIGRaOBPY41oiWYV4JyBoGAaBjYMYuv+6wVw==",
+      "dev": true,
+      "dependencies": {
+        "rollup-pluginutils": "^2.4.1"
+      }
+    },
+    "node_modules/rollup-pluginutils": {
+      "version": "2.8.2",
+      "resolved": "https://registry.npmmirror.com/rollup-pluginutils/-/rollup-pluginutils-2.8.2.tgz",
+      "integrity": "sha512-EEp9NhnUkwY8aif6bxgovPHMoMoNr2FulJziTndpt5H9RdwC47GSGuII9XxpSdzVGM0GWrNPHV6ie1LTNJPaLQ==",
+      "dev": true,
+      "dependencies": {
+        "estree-walker": "^0.6.1"
+      }
+    },
     "node_modules/run-async": {
       "version": "2.4.1",
       "resolved": "https://registry.npmmirror.com/run-async/-/run-async-2.4.1.tgz",
@@ -11045,6 +11130,16 @@
         "uuid": "8.3.2"
       }
     },
+    "@nestjs/microservices": {
+      "version": "8.4.4",
+      "resolved": "https://registry.npmmirror.com/@nestjs/microservices/-/microservices-8.4.4.tgz",
+      "integrity": "sha512-V1xBs5mBFaWGF7RuLSQBG9ydcvX+j8RxHnk9pYF2I5kBdWt7AyTuG2qMt7es06HXEbgUmavw/zn+P6Q2WQIS5A==",
+      "requires": {
+        "iterare": "1.2.1",
+        "json-socket": "0.3.0",
+        "tslib": "2.3.1"
+      }
+    },
     "@nestjs/platform-express": {
       "version": "8.4.4",
       "resolved": "https://registry.npmmirror.com/@nestjs/platform-express/-/platform-express-8.4.4.tgz",
@@ -13082,6 +13177,12 @@
       "integrity": "sha512-MMdARuVEQziNTeJD8DgMqmhwR11BRQ/cBP+pLtYdSTnf3MIO8fFeiINEbX36ZdNlfU/7A9f3gUw49B3oQsvwBA==",
       "dev": true
     },
+    "estree-walker": {
+      "version": "0.6.1",
+      "resolved": "https://registry.npmmirror.com/estree-walker/-/estree-walker-0.6.1.tgz",
+      "integrity": "sha512-SqmZANLWS0mnatqbSfRP5g8OXZC12Fgg1IwNtLsyHDzJizORW4khDfjPqJZsemPWBB2uqykUah5YpQ6epsqC/w==",
+      "dev": true
+    },
     "esutils": {
       "version": "2.0.3",
       "resolved": "https://registry.npmmirror.com/esutils/-/esutils-2.0.3.tgz",
@@ -14479,6 +14580,11 @@
       "integrity": "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==",
       "dev": true
     },
+    "json-socket": {
+      "version": "0.3.0",
+      "resolved": "https://registry.npmmirror.com/json-socket/-/json-socket-0.3.0.tgz",
+      "integrity": "sha512-jc8ZbUnYIWdxERFWQKVgwSLkGSe+kyzvmYxwNaRgx/c8NNyuHes4UHnPM3LUrAFXUx1BhNJ94n1h/KCRlbvV0g=="
+    },
     "json-stable-stringify-without-jsonify": {
       "version": "1.0.1",
       "resolved": "https://registry.npmmirror.com/json-stable-stringify-without-jsonify/-/json-stable-stringify-without-jsonify-1.0.1.tgz",
@@ -15879,6 +15985,24 @@
         "glob": "^7.1.3"
       }
     },
+    "rollup-plugin-string": {
+      "version": "3.0.0",
+      "resolved": "https://registry.npmmirror.com/rollup-plugin-string/-/rollup-plugin-string-3.0.0.tgz",
+      "integrity": "sha512-vqyzgn9QefAgeKi+Y4A7jETeIAU1zQmS6VotH6bzm/zmUQEnYkpIGRaOBPY41oiWYV4JyBoGAaBjYMYuv+6wVw==",
+      "dev": true,
+      "requires": {
+        "rollup-pluginutils": "^2.4.1"
+      }
+    },
+    "rollup-pluginutils": {
+      "version": "2.8.2",
+      "resolved": "https://registry.npmmirror.com/rollup-pluginutils/-/rollup-pluginutils-2.8.2.tgz",
+      "integrity": "sha512-EEp9NhnUkwY8aif6bxgovPHMoMoNr2FulJziTndpt5H9RdwC47GSGuII9XxpSdzVGM0GWrNPHV6ie1LTNJPaLQ==",
+      "dev": true,
+      "requires": {
+        "estree-walker": "^0.6.1"
+      }
+    },
     "run-async": {
       "version": "2.4.1",
       "resolved": "https://registry.npmmirror.com/run-async/-/run-async-2.4.1.tgz",

+ 1 - 0
package.json

@@ -52,6 +52,7 @@
     "eslint-plugin-prettier": "^4.0.0",
     "jest": "^27.2.5",
     "prettier": "^2.3.2",
+    "rollup-plugin-string": "^3.0.0",
     "source-map-support": "^0.5.20",
     "supertest": "^6.1.3",
     "ts-jest": "^27.0.3",

+ 239 - 18
proto/scene.proto

@@ -1,45 +1,266 @@
 //版本
 syntax = "proto3";
-
 package scene;
-
 option java_multiple_files = true;
 // grpc插件生成的类的报名,随便写
 option java_package = "com.fdkk.fdkkmeta.grpc";
 
 // grpc的方法
 service SceneGrpcService {
-  rpc testMethod (SceneRequest) returns (SceneReply){}
+  // rpc testMethod (SceneRequest) returns (SceneReply){}
   rpc getRoute (RouteRequest) returns (RouteReply){}
+  rpc init (InitRequest) returns (NormalReply){}
+  rpc rotate (RotateRequest) returns (NormalReply){}
+  rpc move (MoveRequest) returns (MoveReply){}
+  rpc getBreakPoint (BreakPointRequest) returns (BreakPointReply){}
+  rpc joystick (JoystickRequest) returns (NormalReply){} //操作杆
 }
-// 入参对象
+// 全局对象
 message Point {
-  string x=1;
+  string x=1;     //应该换成double
   string y=2;
   string z=3;
 }
-// 入参对象
-message RouteRequest {
-  Point s_location=1;
-  Point e_location=2;
-  string sceneCode=3;
+
+// 全局对象
+message AngleUe4 {
+  int32 pitch=1;
+  int32 yaw=2;
+  int32 roll=3;
 }
+
+// 全局对象
 message RouteArray{
   int32 id=1;
   Point location=2;
 }
-// 出参对象
+
+// getRoute入参对象
+message RouteRequest {
+  Point s_location=1;
+  Point e_location=2;
+  string sceneCode=3;
+}
+
+// getRoute出参对象
 message RouteReply{
   repeated RouteArray in=1;
 }
 
-// 入参对象
-message SceneRequest {
-  string id=1;
-  string name=2;
+// // 入参对象
+// message SceneRequest {
+//   string id=1;
+//   string name=2;
+// }
+// // 出参对象
+// message SceneReply {
+//   string res=1;
+// }
+
+/***********************************************************/
+message Space {
+   Point position=1;
+   AngleUe4 angle=2;
+}
+
+message State {
+   string roomTypeId=1;
+   int32 person=2;
+   string avatarId=3;
+   string skinId=4;
+   string roomId=5;
+   bool isHost=6;
+   bool isFollowHost=7;
+   string skinDataVersion=8;
+   string avatarComponents=9;
+   string nickName=10;
+   int32 movingMode=11;
+   string attitude=12;
+   string areaName=13;
+   string pathName=14;
+   string pathId=15;
+   int32 avatarSize=16;
+   string extra=17;
+   bool prioritySync=18;
+   Space player=19;
+   Space camera=20;
+   Point cameraCenter=21;
+}
+
+message RenderInfo{
+   int32 renderType=1;
+   string videoFrame=2;
+   int32 cameraStateType=3;
+   int32 isMoving=4;
+   int32 needIfr=5;
+   int32 isVideo=6;
+   int32 stillFrame=7;
+   int32 isRotating=8;
+   int32 isFollowing=9;
+   repeated string clientPanoTitlesBitmap=10;
+   string clientPanoTreceId=11;
+   string prefetchVideoId=12;
+   bool noMedia=13;
+} 
+
+message Event{
+   string id=1;
+   int32 type =2;
+   repeated Point points=3;
+   string rotateEvent=4;
+   string removeVisitorEvent=5;
+}
+
+message UserState{
+   string userId=1;
+   State playerState=2;
+   RenderInfo renderInfo=3;
+   Event event=4;
+   int32 relation=5;
 }
-// 出参对象
-message SceneReply {
-  string res=1;
+/***********************************************************/
+
+// init入参对象
+message InitRequest {
+  string user_id=1;
+  string nick_name=2;
+  string skin_id=3;
+  string avatar_id=4;
+  string room_id=5;
+  string app_id=6;
 }
 
+/**********************************************************/
+//全局对象,旋转的参数
+message rotation_action{
+  int32 vertical_move=1;
+  double horizontal_move=2;
+}
+
+// rotate入参对象
+message RotateRequest {
+  int32 action_type=1;
+  string rotation_action=2;
+  string trace_id=3;
+  string user_id=4;
+}
+
+/**********************************************************/
+//正常的反馈
+message NormalReply {
+   repeated string traceIds=1;
+   string vehicle=2;
+   repeated UserState newUserStates=3;
+   repeated int32 actionResponses=4;
+   int32 getStateType=5;
+   int32 code=6;
+   string msg=7;
+   string frameSrc=8;              //视频路径
+}
+
+/**********************************************************/
+//
+message ClickingAction {
+   Point clicking_point=1;
+   int32 clicking_type=2;
+   string extra=3;
+   string attitude=4;
+}
+message MoveRequest {
+  int32 action_type=1;
+  ClickingAction clicking_action=2;
+  State clicking_state=3;
+  string trace_id=4;
+  string user_id=5;
+}
+
+// 开始请求漫游
+message StartMoveRequest {
+  int32 action_type=1;
+  ClickingAction clicking_action=2;
+  State clicking_state=3;
+  string trace_id=4;
+  string user_id=5;
+}
+
+// 请求移动下一段
+message MoveNextNeighborRequest {
+  int32 user_id=1;
+  string trace_id=2;
+  bool next=3;
+}
+
+// 结束移动下一段(一般是有新的请求)
+message EndMoveNextNeighborRequest {
+  int32 user_id=1;
+  string trace_id=2;
+  bool next=3;
+}
+
+// move出参对象
+// 这需要自定义
+message MoveReply {
+   repeated string traceIds=1;
+   string vehicle=2;
+   repeated UserState newUserStates=3;      //自己的话,不要有player,camera和cameraCenter。自己对应的这三个属性在8,9,10上,到webrtc服务器上组装
+   repeated int32 actionResponses=4;
+   int32 getStateType=5;
+   int32 code=6;
+   string msg=7;
+   //每一段的人物和相机坐标,第一段可能还有初始旋转
+   repeated Space player=8;
+   repeated Space camera=9;
+   repeated Point cameraCenter=10;
+   bool isEnd=11;     //false表示可以继续移动,true表示这次移动已经结束
+}
+/**********************************************************/
+
+/**********************************************************/
+message DirAction{
+  int32 move_angle=1;
+  int32 speed_level=2;
+}
+
+//控制杆移动
+message JoystickRequest {
+  int32 action_type=1;
+  DirAction dir_action=2;
+  string trace_id=3;
+  string user_id=4;
+  string packet_id=5;
+}
+/**********************************************************/
+
+/**********************************************************/
+message NeighborPointsAction{
+  Point point=1;
+  int32 level=2;
+  bool containSelf=3;
+  int32 searchRange=4;
+}
+
+// move入参对象
+message BreakPointRequest{
+  int32 action_type=1;
+  NeighborPointsAction get_neighbor_points_action=2;
+  string trace_id=3;
+  string user_id=4;
+}
+// move出参对象
+message BreakPointReply {
+  int32 actionType=1;
+  int32 pointType=2;
+  string extra=3;
+  string traceId=4;
+  string packetId=5;
+  repeated Point nps=6;
+  int32 peopleNum=7;
+  string zoneId=8;
+  string echoMsg=9;
+  string reserveDetail=10;
+  repeated string userWithAvatarList=11;
+  repeated UserState newUserStates=12;
+  int32 code=13;
+  string msg=14;
+}
+/**********************************************************/

+ 4 - 16
src/app.controller.ts

@@ -4,40 +4,28 @@ import { AppService } from './app.service';
 import { grpcClientOptions } from './grpc-scene.options';
 
 import { ClientGrpc, Client } from '@nestjs/microservices';
-import { Observable } from 'rxjs';
 
 interface Point {
   x: string;
   y: string;
   z: string;
 }
-
-interface routeParam {
-  sLocation: Point;
-  eLocation: Point;
-  sceneCode: string;
-}
-interface SceneGrpcService {
-  getRoute(params: routeParam): Observable<any>;
-  testMethod(data: { id: string; name: string }): Observable<any>;
-}
-
 @Controller()
 export class AppController implements OnModuleInit {
   @Client(grpcClientOptions) private readonly client: ClientGrpc;
   private sceneGrpcService: SceneGrpcService;
 
-  constructor(private readonly appService: AppService) { }
+  constructor(private readonly appService: AppService) {}
 
   onModuleInit() {
-    console.log('this.client', this.client);
+    // console.log('this.client', this.client);
     this.sceneGrpcService =
       this.client.getService<SceneGrpcService>('SceneGrpcService');
   }
   @Get()
   getHello(): string {
     // console.log('UtilsModule', UtilsModule);
-    const params: routeParam = {
+    const params: RouteRequest = {
       sLocation: {
         x: '6.0',
         y: '0.0',
@@ -50,7 +38,7 @@ export class AppController implements OnModuleInit {
       },
       sceneCode: 'Hello',
     };
-    console.log('params', params);
+    // console.log('params', params);
     const test = this.sceneGrpcService.getRoute(params);
     test.subscribe((val) => {
       console.log('val', val);

+ 13 - 14
src/app.module.ts

@@ -4,27 +4,26 @@ import { AppController } from './app.controller';
 import { AppService } from './app.service';
 import { MetaGateway } from './meta.gateway';
 import { RoomModule } from './room/room.module';
-import { ClientsModule, Transport } from '@nestjs/microservices';
-import { join } from 'path';
+import { SceneModule } from './scene/scene.module';
 
 // const protodir = join(__dirname, '..', 'proto/scene.proto');
 
 // console.log('protodir', protodir);
 
-const grpcClientModule = ClientsModule.register([
-  {
-    name: 'SCENE_PACKAGE',
-    transport: Transport.GRPC,
-    options: {
-      url: '192.168.0.152:3000',
-      package: 'scene',
-      protoPath: join(__dirname, '..', 'proto/scene.proto'),
-    },
-  },
-]);
+// const grpcClientModule = ClientsModule.register([
+//   {
+//     name: 'SCENE_PACKAGE',
+//     transport: Transport.GRPC,
+//     options: {
+//       url: '192.168.0.152:3000',
+//       package: 'scene',
+//       protoPath: join(__dirname, '..', 'proto/scene.proto'),
+//     },
+//   },
+// ]);
 
 @Module({
-  imports: [ConfigModule.forRoot(), grpcClientModule, RoomModule],
+  imports: [ConfigModule.forRoot(), RoomModule, SceneModule],
   controllers: [AppController],
   providers: [AppService, MetaGateway],
 })

+ 0 - 18
src/meta.gateway.spec.ts

@@ -1,18 +0,0 @@
-import { Test, TestingModule } from '@nestjs/testing';
-import { MetaGateway } from './meta.gateway';
-
-describe('MetaGateway', () => {
-  let gateway: MetaGateway;
-
-  beforeEach(async () => {
-    const module: TestingModule = await Test.createTestingModule({
-      providers: [MetaGateway],
-    }).compile();
-
-    gateway = module.get<MetaGateway>(MetaGateway);
-  });
-
-  it('should be defined', () => {
-    expect(gateway).toBeDefined();
-  });
-});

+ 22 - 12
src/meta.gateway.ts

@@ -21,6 +21,7 @@ import { Buffer } from 'buffer';
 import { Logger } from '@nestjs/common';
 import * as path from 'path';
 import { createReadStream } from 'fs';
+// import { SceneService } from './scene/scene.service';
 // 'Verbose' | 'Debug' | 'Info' | 'Warning' | 'Error' | 'Fatal';
 initLogger('Debug');
 
@@ -33,6 +34,7 @@ initLogger('Debug');
 export class MetaGateway
   implements OnGatewayInit, OnGatewayConnection, OnGatewayDisconnect
 {
+  // constructor(private readonly sceneService: SceneService) {}
   private logger: Logger = new Logger('MetaGateway');
   private peer: PeerConnection = null;
   private timer: NodeJS.Timeout;
@@ -45,6 +47,12 @@ export class MetaGateway
   // handleMessage(client: any, payload: any) {
   //   this.logger.log(`payload: ${JSON.stringify(payload)}`);
   // }
+  afterInit(server: Server) {
+    this.logger.log('Init');
+    // console.log('sceneService', this.sceneService);
+    // console.log('gateway init', server);
+    // this.sceneService.getService('SceneGrpcService');
+  }
 
   @SubscribeMessage('init')
   handleInit(client: any, payload: any) {
@@ -179,30 +187,36 @@ export class MetaGateway
       console.log('配对成功', peers);
 
       let i = 1;
-      const paths = path.join(__dirname, '../ws/video/v11');
+      const paths = path.join(__dirname, '../ws/video/100');
       console.error('__dirname', __dirname);
       console.error('paths', paths);
       if (this.gameChanel.isOpen()) {
         console.log('gameChanel', this.gameChanel.isOpen());
         this.sendWertcHeartPack(this.gameChanel);
       }
+
+      Number.prototype.padLeft = function (n, str) {
+        return Array(n - String(this).length + 1).join(str || '0') + this;
+      };
       this.timer = setInterval(() => {
-        if (i < 9) {
-          const steam = createReadStream(paths + `/${i}.h264`);
+        if (i < 30) {
+          const steam = createReadStream(
+            paths + `/100.${Number(i).padLeft(4, '0')}.h264`,
+          );
           // const steam = createReadStream(paths + `/test2`);
           steam.on('data', (data: Buffer) => {
             // 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);
+            // frame.setUint16(6, 36);
+            // frame.setUint16(24, 0);
+            // frame.setUint16(26, 0);
+            // frame.setUint32(28, 0);
             this.gameChanel.sendMessageBinary(Buffer.from(frame.buffer));
           });
         }
         i++;
-      }, 10);
+      }, 1000 / 30);
     });
     this.gameChanel.onClosed(() => {
       console.log('gameChanel close');
@@ -254,10 +268,6 @@ export class MetaGateway
     console.log('start', payload);
   }
 
-  afterInit(server: Server) {
-    this.logger.log('Init');
-  }
-
   handleConnection(client: WebSocket, ...args: any[]) {
     this.logger.log(`Client connected: ${args}`);
     const connected = {

+ 11 - 0
src/scene/grpc-scene.options.ts

@@ -0,0 +1,11 @@
+import { Transport, ClientOptions } from '@nestjs/microservices';
+import { join } from 'path';
+
+export const grpcClientOptions: ClientOptions = {
+  transport: Transport.GRPC,
+  options: {
+    url: '192.168.0.152:3000',
+    package: 'scene',
+    protoPath: join(__dirname, '..', 'proto/scene.proto'),
+  },
+};

+ 102 - 0
src/scene/scene.d.ts

@@ -0,0 +1,102 @@
+interface SceneGrpcService {
+  getRoute(request: RouteRequest): Observable<any>;
+  init(request: InitRequest): Observable<any>;
+  rotate(request: RotateRequest): Observable<any>;
+  move(request: MoveRequest): Observable<any>;
+  getBreakPoint(request: GetBreakPointRequest): Observable<any>;
+  joystick(request: JoystickRequest): Observable<any>;
+}
+
+interface Point {
+  x: string;
+  y: string;
+  z: string;
+}
+
+interface RouteRequest {
+  sLocation: Point;
+  eLocation: Point;
+  sceneCode: string;
+}
+
+// interface RouteReply {
+
+// }
+
+interface RotateRequest {
+  actionType: number;
+  rotationAction: string;
+  traceId: string;
+  userId: string;
+}
+
+interface MoveRequest {
+  actionType: number;
+  clickingAction: {
+    clickingPoint: Point;
+    clickingType: number;
+    extra: string;
+    attitude: string;
+  };
+  clickingState: {
+    roomTypeId: string;
+    person: number;
+    avatarId: string;
+    skinId: string;
+    roomId: string;
+    isHost: boolean;
+    isFollowHost: boolean;
+    skinDataVersion: string;
+    avatarComponents: string;
+    nickName: string;
+    movingMode: number;
+    attitude: string;
+    areaName: string;
+    pathName: string;
+    pathId: string;
+    avatarSize: number;
+    extra: string;
+    prioritySync: true;
+    player: {
+      position: Point;
+      angle: {
+        pitch: number;
+        yaw: number;
+        roll: number;
+      };
+    };
+    camera: {
+      position: Point;
+      angle: {
+        pitch: number;
+        yaw: number;
+        roll: number;
+      };
+    };
+    cameraCenter: Point;
+  };
+  traceId: string;
+  userId: string;
+}
+
+interface GetBreakPointRequest {
+  actionType: number;
+  getNeighborPointsAction: {
+    point: Point;
+    level: number;
+    containSelf: boolean;
+    searchRange: number;
+  };
+  traceId: string;
+  userId: string;
+}
+interface JoystickRequest {
+  actionType: number;
+  dirAction: {
+    moveAngle: number;
+    speedLevel: number;
+  };
+  traceId: string;
+  userId: string;
+  packetId: string;
+}

+ 9 - 0
src/scene/scene.module.ts

@@ -0,0 +1,9 @@
+import { Module } from '@nestjs/common';
+import { SceneService } from './scene.service';
+@Module({
+  imports: [],
+  controllers: [],
+  providers: [SceneService],
+  exports: [SceneService],
+})
+export class SceneModule {}

+ 25 - 0
src/scene/scene.service.ts

@@ -0,0 +1,25 @@
+import { Injectable, OnModuleInit } from '@nestjs/common';
+import { ClientGrpc, Client } from '@nestjs/microservices';
+// import { Observable } from 'rxjs';
+import { grpcClientOptions } from './grpc-scene.options';
+
+@Injectable()
+export class SceneService implements OnModuleInit {
+  @Client(grpcClientOptions) private readonly client: ClientGrpc;
+  private sceneGrpcService: SceneGrpcService;
+
+  OnModuleInit() {
+    this.sceneGrpcService =
+      this.client.getService<SceneGrpcService>('SceneGrpcService');
+    debugger;
+  }
+
+  getService(name: string) {
+    this.sceneGrpcService = this.client.getService<SceneGrpcService>(name);
+    return this.sceneGrpcService;
+  }
+
+  getRoute() {
+    console.log('this.sceneGrpcService', this.sceneGrpcService);
+  }
+}

文件差异内容过多而无法显示
+ 4777 - 4680
yarn.lock