|
@@ -23,6 +23,7 @@ import * as path from 'path';
|
|
|
import { createReadStream } from 'fs';
|
|
|
import { SceneService } from './scene/scene.service';
|
|
|
import { ConfigService } from '@nestjs/config';
|
|
|
+
|
|
|
// 'Verbose' | 'Debug' | 'Info' | 'Warning' | 'Error' | 'Fatal';
|
|
|
initLogger('Debug');
|
|
|
|
|
@@ -45,6 +46,9 @@ export class MetaGateway
|
|
|
private _webrtcInterval: NodeJS.Timeout;
|
|
|
private heartBeatFlag: number;
|
|
|
private gameChanel: DataChannel;
|
|
|
+ private user_id: string;
|
|
|
+ private roomId: string;
|
|
|
+
|
|
|
@WebSocketServer() server: Server;
|
|
|
|
|
|
// @SubscribeMessage('message')
|
|
@@ -57,7 +61,7 @@ export class MetaGateway
|
|
|
|
|
|
@SubscribeMessage('init')
|
|
|
handleInit(client: any, payload: any) {
|
|
|
- this.logger.log(`init: ${JSON.stringify(payload)}`);
|
|
|
+ this.logger.log(`socket::init: ${JSON.stringify(payload)}`);
|
|
|
}
|
|
|
|
|
|
@SubscribeMessage('heartbeat')
|
|
@@ -180,7 +184,6 @@ export class MetaGateway
|
|
|
|
|
|
this.gameChanel.onOpen(() => {
|
|
|
console.log('channel is open');
|
|
|
-
|
|
|
this.sceneService.handleDataChanelOpen(this.gameChanel);
|
|
|
|
|
|
clearInterval(this.timer);
|
|
@@ -269,51 +272,67 @@ export class MetaGateway
|
|
|
@SubscribeMessage('start')
|
|
|
handlerWebrtcStart(client: any, payload: any) {
|
|
|
console.log('start', payload);
|
|
|
- this.sceneService.init(payload);
|
|
|
- this.logger.log(
|
|
|
- 'start and send to gprc sceneService,method=>init',
|
|
|
- payload,
|
|
|
- );
|
|
|
-
|
|
|
- const demoVal = {
|
|
|
- id: 'start',
|
|
|
- data: '{"IsHost":false,"SkinID":"10089","SkinDataVersion":"1008900008","RoomTypeID":""}',
|
|
|
- room_id: 'e629ef3e-022d-4e64-8654-703bb96410eb',
|
|
|
- channel_id: '4f2cf027d926f3cc___channel',
|
|
|
- user_id: '15bc22119cfa1',
|
|
|
- trace_id: '45a925d6-7d05-4c11-93a3-0fdaabd7db6f',
|
|
|
- packet_id: '',
|
|
|
- session_id: '4bbfd45cbeab43d3a9b992349f00dfba',
|
|
|
- client_os: '',
|
|
|
- fe_version: '',
|
|
|
- is_browser: false,
|
|
|
- };
|
|
|
+ try {
|
|
|
+ const obj = JSON.parse(payload);
|
|
|
+ const requestPayLoad: InitRequest = Object.assign({}, obj, {
|
|
|
+ user_id: this.user_id,
|
|
|
+ roomId: this.roomId,
|
|
|
+ });
|
|
|
+ this.sceneService.init(requestPayLoad);
|
|
|
+ this.logger.log(
|
|
|
+ 'start and send to gprc sceneService,method=>init',
|
|
|
+ requestPayLoad,
|
|
|
+ );
|
|
|
|
|
|
- const startReply = {
|
|
|
- id: 'start',
|
|
|
- data: '{"IsHost":false,"SkinID":"10089","SkinDataVersion":"1008900008","RoomTypeID":""}',
|
|
|
- room_id: 'e629ef3e-022d-4e64-8654-703bb96410eb',
|
|
|
- channel_id: '3a1a62e9a3c74de6___channel',
|
|
|
- user_id: 'ed58c8d4ce38c',
|
|
|
- trace_id: '394df10a-d924-43a9-940d-1dbb41e43f24',
|
|
|
- packet_id: '',
|
|
|
- session_id: '67087ad820ea4c89af311e27281d73a6',
|
|
|
- client_os: '',
|
|
|
- fe_version: '',
|
|
|
- };
|
|
|
- this.sceneService.onSteaming.subscribe((val) => {
|
|
|
- if (val) {
|
|
|
- console.log('onSteaming-start', val);
|
|
|
- client.send(JSON.stringify(startReply));
|
|
|
- }
|
|
|
- // debugger
|
|
|
- });
|
|
|
+ // const demoVal = {
|
|
|
+ // id: 'start',
|
|
|
+ // data: '{"IsHost":false,"SkinID":"10089","SkinDataVersion":"1008900008","RoomTypeID":""}',
|
|
|
+ // room_id: 'e629ef3e-022d-4e64-8654-703bb96410eb',
|
|
|
+ // channel_id: '4f2cf027d926f3cc___channel',
|
|
|
+ // user_id: '15bc22119cfa1',
|
|
|
+ // trace_id: '45a925d6-7d05-4c11-93a3-0fdaabd7db6f',
|
|
|
+ // packet_id: '',
|
|
|
+ // session_id: '4bbfd45cbeab43d3a9b992349f00dfba',
|
|
|
+ // client_os: '',
|
|
|
+ // fe_version: '',
|
|
|
+ // is_browser: false,
|
|
|
+ // };
|
|
|
+
|
|
|
+ const startReply = {
|
|
|
+ id: 'start',
|
|
|
+ data: '{"IsHost":false,"SkinID":"10089","SkinDataVersion":"1008900008","RoomTypeID":""}',
|
|
|
+ room_id: 'e629ef3e-022d-4e64-8654-703bb96410eb',
|
|
|
+ channel_id: '3a1a62e9a3c74de6___channel',
|
|
|
+ user_id: 'ed58c8d4ce38c',
|
|
|
+ trace_id: '394df10a-d924-43a9-940d-1dbb41e43f24',
|
|
|
+ packet_id: '',
|
|
|
+ session_id: '67087ad820ea4c89af311e27281d73a6',
|
|
|
+ client_os: '',
|
|
|
+ fe_version: '',
|
|
|
+ };
|
|
|
+ this.sceneService.onSteaming.subscribe((val) => {
|
|
|
+ if (val) {
|
|
|
+ console.log('onSteaming-start', val);
|
|
|
+ client.send(JSON.stringify(startReply));
|
|
|
+ }
|
|
|
+ // debugger
|
|
|
+ });
|
|
|
+ } catch (error) {}
|
|
|
}
|
|
|
|
|
|
handleConnection(client: WebSocket, ...args: any[]) {
|
|
|
const { url } = args[0];
|
|
|
console.log('url', url);
|
|
|
+ const params = new URLSearchParams(url.replace('/ws?', ''));
|
|
|
+
|
|
|
+ console.log('useId', params.get('userId'));
|
|
|
+ console.log('roomId', params.get('roomId'));
|
|
|
+
|
|
|
+ this.user_id = params.get('userId');
|
|
|
+ this.roomId = params.get('roomId');
|
|
|
+
|
|
|
this.logger.log(`Client connected:`);
|
|
|
+
|
|
|
const connected = {
|
|
|
channel_id: '',
|
|
|
client_os: '',
|