|
@@ -5,7 +5,7 @@ import { Logger } from '@nestjs/common';
|
|
import { DataChannel } from 'node-datachannel';
|
|
import { DataChannel } from 'node-datachannel';
|
|
import * as path from 'path';
|
|
import * as path from 'path';
|
|
import { statSync, createReadStream, readFileSync } from 'fs';
|
|
import { statSync, createReadStream, readFileSync } from 'fs';
|
|
-import { Readable } from 'stream';
|
|
|
|
|
|
+// import { Readable } from 'stream';
|
|
import { BehaviorSubject } from 'rxjs';
|
|
import { BehaviorSubject } from 'rxjs';
|
|
import * as streamBuffers from 'stream-buffers';
|
|
import * as streamBuffers from 'stream-buffers';
|
|
import { ActionType } from './actionType';
|
|
import { ActionType } from './actionType';
|
|
@@ -23,6 +23,8 @@ export class SceneService implements OnModuleInit {
|
|
public _frameInteval: NodeJS.Timeout;
|
|
public _frameInteval: NodeJS.Timeout;
|
|
private channel: DataChannel;
|
|
private channel: DataChannel;
|
|
public onSteaming = new BehaviorSubject<boolean>(false);
|
|
public onSteaming = new BehaviorSubject<boolean>(false);
|
|
|
|
+ public user_id: string;
|
|
|
|
+ public roomId: string;
|
|
|
|
|
|
onModuleInit() {
|
|
onModuleInit() {
|
|
this.sceneGrpcService =
|
|
this.sceneGrpcService =
|
|
@@ -41,17 +43,10 @@ export class SceneService implements OnModuleInit {
|
|
return this.sceneGrpcService.test(request);
|
|
return this.sceneGrpcService.test(request);
|
|
}
|
|
}
|
|
|
|
|
|
- init(request: string) {
|
|
|
|
|
|
+ init(request: InitRequest) {
|
|
try {
|
|
try {
|
|
- // console.log('request', this.sceneGrpcService);
|
|
|
|
- const params = JSON.parse(request);
|
|
|
|
- // const requestData: InitRequest = {
|
|
|
|
- // appId: params.appId
|
|
|
|
- // }
|
|
|
|
-
|
|
|
|
- this.logger.log('init', request);
|
|
|
|
- const rpcRequest: InitRequest = params;
|
|
|
|
- const initReply = this.sceneGrpcService.init(rpcRequest);
|
|
|
|
|
|
+ // this.logger.log('rtc::init::start', JSON.stringify(request));
|
|
|
|
+ const initReply = this.sceneGrpcService.init(request);
|
|
initReply.subscribe((reply) => {
|
|
initReply.subscribe((reply) => {
|
|
console.log('initReply', reply);
|
|
console.log('initReply', reply);
|
|
});
|
|
});
|
|
@@ -66,6 +61,7 @@ export class SceneService implements OnModuleInit {
|
|
|
|
|
|
rotate(request: RotateRequest) {
|
|
rotate(request: RotateRequest) {
|
|
const reply = this.sceneGrpcService.rotate(request);
|
|
const reply = this.sceneGrpcService.rotate(request);
|
|
|
|
+ console.log('reply', reply);
|
|
reply.subscribe((res) => {
|
|
reply.subscribe((res) => {
|
|
console.log('rotate-reply', res);
|
|
console.log('rotate-reply', res);
|
|
});
|
|
});
|
|
@@ -90,13 +86,19 @@ export class SceneService implements OnModuleInit {
|
|
try {
|
|
try {
|
|
if (typeof message === 'string') {
|
|
if (typeof message === 'string') {
|
|
const msg: RTCMessageRequest = JSON.parse(message);
|
|
const msg: RTCMessageRequest = JSON.parse(message);
|
|
|
|
+ console.log('msg', msg);
|
|
switch (msg.action_type) {
|
|
switch (msg.action_type) {
|
|
case ActionType.rotate:
|
|
case ActionType.rotate:
|
|
console.log('rotate', msg);
|
|
console.log('rotate', msg);
|
|
const rotateRequest: RotateRequest = msg;
|
|
const rotateRequest: RotateRequest = msg;
|
|
this.rotate(rotateRequest);
|
|
this.rotate(rotateRequest);
|
|
break;
|
|
break;
|
|
-
|
|
|
|
|
|
+ case ActionType.userStatus:
|
|
|
|
+ this.updateUserStatus();
|
|
|
|
+ break;
|
|
|
|
+ case ActionType.status:
|
|
|
|
+ this.updateStatus();
|
|
|
|
+ break;
|
|
default:
|
|
default:
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
@@ -106,15 +108,105 @@ export class SceneService implements OnModuleInit {
|
|
this.logger.error('handleMessage:rtc', error);
|
|
this.logger.error('handleMessage:rtc', error);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ updateStatus() {
|
|
|
|
+ const reply = {
|
|
|
|
+ data: { action_type: 1009, echo_msg: { echoMsg: '1652857098550' } },
|
|
|
|
+ track: false,
|
|
|
|
+ };
|
|
|
|
+ if (this.channel && this.channel.isOpen()) {
|
|
|
|
+ const replyBin = JSON.stringify(reply).replace(/\s/g, '');
|
|
|
|
+ const buff = Buffer.from(replyBin, 'utf-8');
|
|
|
|
+ this.channel.sendMessageBinary(buff);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ updateUserStatus() {
|
|
|
|
+ const reply = {
|
|
|
|
+ actionType: 1024,
|
|
|
|
+ pointType: 100,
|
|
|
|
+ extra: '',
|
|
|
|
+ traceId: '65db8e1b-2261-42eb-8bc5-8dc97bfe0b0e',
|
|
|
|
+ packetId: '',
|
|
|
|
+ nps: [],
|
|
|
|
+ peopleNum: 0,
|
|
|
|
+ zoneId: '',
|
|
|
|
+ echoMsg: '',
|
|
|
|
+ reserveDetail: null,
|
|
|
|
+ userWithAvatarList: [],
|
|
|
|
+ newUserStates: [
|
|
|
|
+ {
|
|
|
|
+ userId: 'e497b92704f5a',
|
|
|
|
+ playerState: {
|
|
|
|
+ roomTypeId: '',
|
|
|
|
+ person: 0,
|
|
|
|
+ avatarId: 'KGe_Boy',
|
|
|
|
+ skinId: '10089',
|
|
|
|
+ roomId: 'e629ef3e-022d-4e64-8654-703bb96410eb',
|
|
|
|
+ isHost: false,
|
|
|
|
+ isFollowHost: false,
|
|
|
|
+ skinDataVersion: '1008900008',
|
|
|
|
+ avatarComponents: '',
|
|
|
|
+ nickName: 'e497b92704f5a',
|
|
|
|
+ movingMode: 0,
|
|
|
|
+ attitude: 'walk',
|
|
|
|
+ areaName: '',
|
|
|
|
+ pathName: 'thirdwalk',
|
|
|
|
+ pathId: 'thirdwalk',
|
|
|
|
+ avatarSize: 1,
|
|
|
|
+ extra: '{"removeWhenDisconnected":true}',
|
|
|
|
+ prioritySync: false,
|
|
|
|
+ avatarURL: '',
|
|
|
|
+ micStatus: 0,
|
|
|
|
+ player: {
|
|
|
|
+ position: { x: -755, y: -1450, z: -34 },
|
|
|
|
+ angle: { pitch: 0, yaw: 0, roll: 0 },
|
|
|
|
+ },
|
|
|
|
+ camera: null,
|
|
|
|
+ cameraCenter: null,
|
|
|
|
+ },
|
|
|
|
+ renderInfo: {
|
|
|
|
+ renderType: 0,
|
|
|
|
+ videoFrame: null,
|
|
|
|
+ cameraStateType: 0,
|
|
|
|
+ isMoving: 0,
|
|
|
|
+ needIfr: 0,
|
|
|
|
+ isVideo: 0,
|
|
|
|
+ stillFrame: 0,
|
|
|
|
+ isRotating: 0,
|
|
|
|
+ isFollowing: 0,
|
|
|
|
+ clientPanoTitlesBitmap: [],
|
|
|
|
+ clientPanoTreceId: '',
|
|
|
|
+ prefetchVideoId: '',
|
|
|
|
+ noMedia: false,
|
|
|
|
+ },
|
|
|
|
+ event: {
|
|
|
|
+ id: '',
|
|
|
|
+ type: 0,
|
|
|
|
+ points: [],
|
|
|
|
+ rotateEvent: null,
|
|
|
|
+ removeVisitorEvent: null,
|
|
|
|
+ },
|
|
|
|
+ relation: 0,
|
|
|
|
+ },
|
|
|
|
+ ],
|
|
|
|
+ code: 0,
|
|
|
|
+ msg: '',
|
|
|
|
+ };
|
|
|
|
+ if (this.channel && this.channel.isOpen()) {
|
|
|
|
+ const replyBin = JSON.stringify(reply).replace(/\s/g, '');
|
|
|
|
+ const buff = Buffer.from(replyBin, 'utf-8');
|
|
|
|
+ this.channel.sendMessageBinary(buff);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
handleStartCountingFrame() {
|
|
handleStartCountingFrame() {
|
|
this._frameInteval = setInterval(async () => {
|
|
this._frameInteval = setInterval(async () => {
|
|
this.frameCnt += 1;
|
|
this.frameCnt += 1;
|
|
try {
|
|
try {
|
|
// console.log()
|
|
// console.log()
|
|
- const data = await this.cacheService.get(
|
|
|
|
- 'updateFrameMetadata:2f60ea15cbd5a2',
|
|
|
|
- );
|
|
|
|
- console.log('test-data', data);
|
|
|
|
|
|
+ // const data = await this.cacheService.get(
|
|
|
|
+ // 'updateFrameMetadata:2f60ea15cbd5a2',
|
|
|
|
+ // );
|
|
|
|
+ // console.log('test-data', data);
|
|
|
|
|
|
if (this.frameCnt === 1) {
|
|
if (this.frameCnt === 1) {
|
|
this.pushTheFirstFrame();
|
|
this.pushTheFirstFrame();
|