app.controller.ts 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. import { Controller, Get, OnModuleInit } from '@nestjs/common';
  2. import { AppService } from './app.service';
  3. // import { UtilsModule } from '@app/utils';
  4. import { grpcClientOptions } from './scene/grpc-scene.options';
  5. import { ClientGrpc, Client } from '@nestjs/microservices';
  6. interface Point {
  7. x: string;
  8. y: string;
  9. z: string;
  10. }
  11. @Controller()
  12. export class AppController implements OnModuleInit {
  13. @Client(grpcClientOptions) private readonly client: ClientGrpc;
  14. private sceneGrpcService: SceneGrpcService;
  15. constructor(private readonly appService: AppService) { }
  16. onModuleInit() {
  17. // console.log('this.client', this.client);
  18. this.sceneGrpcService =
  19. this.client.getService<SceneGrpcService>('SceneGrpcService');
  20. console.log('this.sceneGrpcService', this.sceneGrpcService);
  21. }
  22. @Get()
  23. getHello(): string {
  24. // console.log('UtilsModule', UtilsModule);
  25. // const params: RouteRequest = {
  26. // sLocation: {
  27. // x: '6.0',
  28. // y: '0.0',
  29. // z: '-4.0',
  30. // },
  31. // eLocation: {
  32. // x: '4.0',
  33. // y: '0.0',
  34. // z: '-3.0',
  35. // },
  36. // sceneCode: 'Hello',
  37. // };
  38. // // // console.log('params', params);
  39. // const test = this.sceneGrpcService.getRoute(params);
  40. // test.subscribe((val) => {
  41. // console.log('val', val);
  42. // });
  43. try {
  44. // const demo_test = {
  45. // user_id: '92dd7e2f-cca9-495d-8f16-458e628ea827',
  46. // nick_name: 'Hello',
  47. // skin_id: 'ce098a8f-a7fc-4721-9c37-31bdbc580c59',
  48. // avatar_id: 'c961561e-78e5-4478-b158-944e3b9c9287',
  49. // room_id: 'c38187b6-d4af-44bb-8028-7ad1e5461cd8',
  50. // app_id: '2282e1b5-6129-4e0d-a30b-2339a1c761cd',
  51. // player: {
  52. // position: {
  53. // x: '0.0',
  54. // y: '0.0',
  55. // z: '0.0',
  56. // },
  57. // angle: {
  58. // pitch: 10,
  59. // yaw: 10,
  60. // roll: 10,
  61. // },
  62. // },
  63. // };
  64. // const initReply = this.sceneGrpcService.init(demo_test);
  65. // initReply.subscribe((val) => {
  66. // console.log('val', val);
  67. // });
  68. // const params = {
  69. // action_type: 1009,
  70. // echo_msg: {
  71. // echoMsg: 'Hello',
  72. // },
  73. // trace_id: '2b6e3444-63eb-40a7-8049-1d6616f16664',
  74. // user_id: '31a6322c-78f1-4744-99df-bc042f50bebc',
  75. // };
  76. const initReply = this.sceneGrpcService.test({
  77. name: 'lala',
  78. });
  79. initReply.subscribe((val) => {
  80. console.log('val', val);
  81. });
  82. // console.log('initReply')
  83. } catch (error) {
  84. console.log('test', error);
  85. }
  86. return this.appService.getHello();
  87. }
  88. }