Skip to content

Commit 2e9b43e

Browse files
committed
✨ [Feat]: record client 추가
1 parent ddcba1a commit 2e9b43e

File tree

6 files changed

+50
-11
lines changed

6 files changed

+50
-11
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export interface IRecordClient {
2+
post<T>(path: string, data: any): Promise<T>;
3+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { Injectable } from '@nestjs/common';
2+
import { ConfigService } from '@nestjs/config';
3+
import { ErrorStatus } from '../responses/exceptions/errorStatus';
4+
import { HttpService } from '@nestjs/axios';
5+
import { CustomWsException } from '../responses/exceptions/custom-ws.exception';
6+
import { IRecordClient } from './record-client.interface';
7+
8+
@Injectable()
9+
export class RecordClient implements IRecordClient {
10+
constructor(private readonly httpService: HttpService, private readonly configService: ConfigService) {}
11+
12+
private readonly baseUrl = this.configService.get<string>('RECORD_SERVER_URL');
13+
14+
async post<T>(path: string, data: any): Promise<T> {
15+
try {
16+
const response = await this.httpService.post<T>(`${this.baseUrl}${path}`, data).toPromise();
17+
return response.data;
18+
} catch (error) {
19+
throw this.handleError(error);
20+
}
21+
}
22+
23+
// TODO: Error custom 필요
24+
private handleError(_error: any): Error {
25+
throw new CustomWsException(ErrorStatus.RECORD_SERVER_ERROR);
26+
}
27+
}

apps/media/src/common/responses/exceptions/errorStatus.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ export class ErrorStatus {
1010

1111
static readonly API_SERVER_ERROR = new ErrorStatus(500, 'COMMON_5001', 'API 서비스 로직에서 문제가 발생했습니다.');
1212

13+
static readonly RECORD_SERVER_ERROR = new ErrorStatus(
14+
500,
15+
'COMMON_5002',
16+
'RECORD 서비스 로직에서 문제가 발생했습니다.',
17+
);
18+
1319
// User Errors
1420
static readonly USER_NOT_FOUND = new ErrorStatus(404, 'MEMBER_4000', '사용자를 찾을 수 없습니다.');
1521

apps/media/src/sfu/sfu.module.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { ConsumerService } from './services/consumer.service';
1010
import { BroadcastModule } from '../broadcast/broadcast.module';
1111
import { ClientService } from './services/client.service';
1212
import { RecordService } from './services/record.service';
13-
import { ApiClient } from 'src/common/clients/api.client';
13+
import { RecordClient } from 'src/common/clients/record.client';
1414

1515
@Module({
1616
imports: [BroadcastModule, HttpModule],
@@ -25,8 +25,8 @@ import { ApiClient } from 'src/common/clients/api.client';
2525
RecordService,
2626
ClientService,
2727
{
28-
provide: 'API_CLIENT',
29-
useClass: ApiClient,
28+
provide: 'RECORD_CLIENT',
29+
useClass: RecordClient,
3030
},
3131
],
3232
})

apps/media/src/sfu/sfu.service.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ import { ClientService } from './services/client.service';
1515
import { RecordService } from './services/record.service';
1616
import { User } from '../types/user';
1717
import { SetVideoQualityDto } from './dto/set-video-quality.dto';
18-
import { IApiClient } from 'src/common/clients/api-client.interface';
19-
// import axios from 'axios';
18+
import { IRecordClient } from 'src/common/clients/record-client.interface';
2019

2120
@Injectable()
2221
export class SfuService {
@@ -29,17 +28,14 @@ export class SfuService {
2928
private readonly recordService: RecordService,
3029
private readonly clientService: ClientService,
3130
private readonly configService: ConfigService,
32-
@Inject('API_CLIENT')
33-
private readonly apiClient: IApiClient,
31+
@Inject('RECORD_CLIENT')
32+
private readonly recordClient: IRecordClient,
3433
) {}
3534

3635
async createRoom(clientId: string, user: User) {
3736
const room = await this.roomService.createRoom();
38-
// await axios.post(`${this.configService.get('RECORD_SERVER_URL')}/thumbnail`, {
39-
// roomId: room.id,
40-
// });
4137

42-
this.apiClient.post(`${this.configService.get('RECORD_SERVER_URL')}/thumbnail`, { roomId: room.id });
38+
await this.recordClient.post('/thumbnail', { roomId: room.id });
4339

4440
const thumbnail = `${this.configService.get('PUBLIC_RECORD_SERVER_URL')}/statics/thumbnails/${room.id}.jpg`;
4541
await this.broadcasterService.createBroadcast(

apps/record/src/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,17 @@ if (!fs.existsSync(recordsDirPath)) {
3131
}
3232

3333
app.post('/thumbnail', (req, res) => {
34+
console.log('Received thumbnail request:', req.body);
3435
const { roomId } = req.body;
3536
try {
37+
console.log('Default thumbnail path:', defaultThumbnailPath);
38+
if (!fs.existsSync(defaultThumbnailPath)) {
39+
console.error('Default thumbnail not found');
40+
return res.status(404).send({ error: 'Default thumbnail not found' });
41+
}
3642
const newThumbnailPath = path.join(thumbnailsDirPath, `${roomId}.jpg`);
3743
fs.copyFileSync(defaultThumbnailPath, newThumbnailPath);
44+
console.log('Thumbnail created:', newThumbnailPath);
3845
res.send({ success: true });
3946
} catch (error) {
4047
res.status(500).send({ success: false, error: 'Failed to create thumbnail' });

0 commit comments

Comments
 (0)