|
@@ -76,7 +76,7 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
|
|
|
constructor(
|
|
|
private cacheService: CacheService,
|
|
|
private streamService: StreamService,
|
|
|
- ) {}
|
|
|
+ ) { }
|
|
|
@Client(grpcClientOptions) private readonly client: ClientGrpc;
|
|
|
private sceneGrpcService: SceneGrpcService;
|
|
|
|
|
@@ -86,10 +86,15 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
|
|
|
public _frameInteval: NodeJS.Timeout;
|
|
|
private channel: DataChannel;
|
|
|
public startSteaming = new BehaviorSubject<boolean>(false);
|
|
|
- public user_id: string;
|
|
|
- public roomId: string;
|
|
|
+ private user_id: string;
|
|
|
+ private roomId: string;
|
|
|
private onSteaming = false;
|
|
|
|
|
|
+ setConfig(user_id: string, roomId: string) {
|
|
|
+ this.user_id = user_id;
|
|
|
+ this.roomId = roomId;
|
|
|
+ }
|
|
|
+
|
|
|
onModuleInit() {
|
|
|
this.sceneGrpcService =
|
|
|
this.client.getService<SceneGrpcService>('SceneGrpcService');
|
|
@@ -97,6 +102,9 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
|
|
|
this.streamService.onSteaming.subscribe((val) => {
|
|
|
this.onSteaming = val;
|
|
|
});
|
|
|
+ Number.prototype.padLeft = function (n, str) {
|
|
|
+ return Array(n - String(this).length + 1).join(str || '0') + this;
|
|
|
+ };
|
|
|
}
|
|
|
|
|
|
onModuleDestroy() {
|
|
@@ -121,40 +129,75 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ exit(request: ExitRequest) {
|
|
|
+ const exitReply = this.sceneGrpcService.exit(request);
|
|
|
+ exitReply.subscribe((reply) => {
|
|
|
+ console.log('exitReply', reply);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
move(request: MoveRequest) {
|
|
|
return this.sceneGrpcService.move(request);
|
|
|
}
|
|
|
|
|
|
- rotate(request: RotateRequest) {
|
|
|
- const reply = this.sceneGrpcService.rotate(request);
|
|
|
- if (!this.onSteaming) {
|
|
|
- this.frameCnt += 1;
|
|
|
+ async rotate(request: RotateRequest) {
|
|
|
+ try {
|
|
|
|
|
|
- const demoPath =
|
|
|
- this.frameCnt > 10
|
|
|
- ? path.join(__dirname, '../ws/video/53.h264')
|
|
|
- : path.join(__dirname, '../ws/video/2.h264');
|
|
|
- const stream: StreamFrameType = {
|
|
|
- frame: this.frameCnt,
|
|
|
- clipPath: demoPath,
|
|
|
- metaData: JSON.stringify(frameMetaReply),
|
|
|
- serverTime: 754873824,
|
|
|
- DIR: 1,
|
|
|
- };
|
|
|
- this.streamService.pushFrameToSteam(stream);
|
|
|
- }
|
|
|
- reply.subscribe((res: NormalReply) => {
|
|
|
- if (res.code === 200) {
|
|
|
- // const stream: StreamFrameType = {
|
|
|
- // frame: this.frameCnt,
|
|
|
- // clipPath: path.join(__dirname, '../ws/video/2.h264'),
|
|
|
- // metaData: JSON.stringify(frameMetaReply),
|
|
|
- // serverTime: 754873824,
|
|
|
- // DIR: 1,
|
|
|
- // };
|
|
|
- // this.streamService.pushFrameToSteam(stream);
|
|
|
+ const reply = this.sceneGrpcService.rotate(request);
|
|
|
+ if (!this.onSteaming) {
|
|
|
+ const redisMeta = await this.cacheService.rpop(
|
|
|
+ `updateFrameMetadata:${this.user_id}`,
|
|
|
+ );
|
|
|
+ this.frameCnt += 1;
|
|
|
+ if (redisMeta && redisMeta.length > 0) {
|
|
|
+ console.log('this.user_id', this.user_id);
|
|
|
+ const meta = JSON.parse(redisMeta);
|
|
|
+ if ('mediaSrc' in meta) {
|
|
|
+ console.log('meta', meta);
|
|
|
+ console.log('mediaSrc', meta.mediaSrc);
|
|
|
+
|
|
|
+ if (meta.mediaSrc.length > 0) {
|
|
|
+ const testclipPath = meta.mediaSrc.replace(
|
|
|
+ '/mnt/oss/metaverse/scene/0000000001/100/',
|
|
|
+ '',
|
|
|
+ );
|
|
|
+ console.log('testclipPath', testclipPath);
|
|
|
+ // const demoPath =
|
|
|
+ // this.frameCnt > 10
|
|
|
+ // ? path.join(__dirname, '../ws/video/53.h264')
|
|
|
+ // : path.join(__dirname, '../ws/video/2.h264');
|
|
|
+ const demoPath = path.join(
|
|
|
+ __dirname,
|
|
|
+ `../ws/video/${testclipPath}`,
|
|
|
+ );
|
|
|
+ delete meta.mediaSrc;
|
|
|
+ const stream: StreamFrameType = {
|
|
|
+ frame: this.frameCnt,
|
|
|
+ clipPath: demoPath,
|
|
|
+ metaData: JSON.stringify(meta),
|
|
|
+ serverTime: 754873824,
|
|
|
+ DIR: 1,
|
|
|
+ };
|
|
|
+ this.streamService.pushFrameToSteam(stream);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
- });
|
|
|
+ reply.subscribe((res: NormalReply) => {
|
|
|
+ if (res.code === 200) {
|
|
|
+ // const stream: StreamFrameType = {
|
|
|
+ // frame: this.frameCnt,
|
|
|
+ // clipPath: path.join(__dirname, '../ws/video/2.h264'),
|
|
|
+ // metaData: JSON.stringify(frameMetaReply),
|
|
|
+ // serverTime: 754873824,
|
|
|
+ // DIR: 1,
|
|
|
+ // };
|
|
|
+ // this.streamService.pushFrameToSteam(stream);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } catch (error) {
|
|
|
+ this.logger.error('rotate', error);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
joystick(request: JoystickRequest) {
|
|
@@ -172,6 +215,12 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
|
|
|
this.stopCountingFrame();
|
|
|
this.startSteaming.next(false);
|
|
|
this.streamService.closeChannel();
|
|
|
+ const exitRequest: ExitRequest = {
|
|
|
+ action_type: 1002,
|
|
|
+ user_id: this.user_id,
|
|
|
+ trace_id: '',
|
|
|
+ };
|
|
|
+ this.exit(exitRequest);
|
|
|
}
|
|
|
|
|
|
handleMessage(message: string | Buffer) {
|
|
@@ -294,13 +343,31 @@ export class SceneService implements OnModuleInit, OnModuleDestroy {
|
|
|
this.streamService.pushFrameToSteam(stream);
|
|
|
}
|
|
|
|
|
|
+ // console.log('padLeft', );
|
|
|
+ // if (this.frameCnt > 2) {
|
|
|
+ // setInterval(() => {
|
|
|
+ // this.frameCnt += 1;
|
|
|
+ // const stream: StreamFrameType = {
|
|
|
+ // frame: this.frameCnt,
|
|
|
+ // clipPath: path.join(
|
|
|
+ // __dirname,
|
|
|
+ // `../ws/video/100/100.${this.frameCnt.padLeft(4, '0')}.h264`,
|
|
|
+ // ),
|
|
|
+ // metaData: JSON.stringify(frameMetaReply),
|
|
|
+ // serverTime: 754871824,
|
|
|
+ // };
|
|
|
+ // this.streamService.pushFrameToSteam(stream);
|
|
|
+ // }, 1000 / 30);
|
|
|
+ // };
|
|
|
+
|
|
|
if (this.frameCnt > 1 && !this.onSteaming) {
|
|
|
const streamMeta: StreamMetaType = {
|
|
|
frame: this.frameCnt,
|
|
|
metaData: JSON.stringify(frameMetaReply),
|
|
|
};
|
|
|
this.streamService.pushMetaDataToSteam(streamMeta);
|
|
|
- }
|
|
|
+ };
|
|
|
+
|
|
|
// if (this.frameCnt == 4) {
|
|
|
// const stream: StreamFrameType = {
|
|
|
// frame: 4,
|