-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #112 from boostcampwm-2024/feat-be-#107-broadcast_…
…start_api [FEAT] 기존 host 키 생성 리팩토링 / rtmp 스트림키 교환 API 작성
- Loading branch information
Showing
9 changed files
with
85 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,11 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { AppController } from './app.controller.js'; | ||
import { AppService } from './app.service.js'; | ||
import { HostController } from './host/host.controller.js'; | ||
import { HostService } from './host/host.service.js'; | ||
import { HostModule } from './host/host.module.js'; | ||
|
||
@Module({ | ||
imports: [], | ||
controllers: [AppController, HostController], | ||
providers: [AppService, HostService], | ||
imports: [HostModule], | ||
controllers: [AppController], | ||
providers: [AppService], | ||
}) | ||
export class AppModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { ApiProperty } from '@nestjs/swagger'; | ||
|
||
export class hostKeyPairDto { | ||
@ApiProperty({example: 'this_is_userId', description: '클라이언트마다 가지는 랜덤한 userId 값'}) | ||
userId: string = ''; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { HostController } from './host.controller.js'; | ||
import { HostService } from './host.service.js'; | ||
|
||
@Module({ | ||
controllers: [HostController], | ||
providers: [HostService], | ||
}) | ||
export class HostModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,15 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import dotenv from 'dotenv'; | ||
import path from 'path'; | ||
import crypto from 'crypto'; | ||
import { ApiProperty } from '@nestjs/swagger'; | ||
|
||
export class keyGenerateRequestDto { | ||
@ApiProperty({example: 'this_is_uuid', description: '클라이언트마다 가지는 랜덤한 uuid 값'}) | ||
uuid: string = ''; | ||
} | ||
|
||
function generateRandomKey(uuid: string, salt: string) { | ||
const hash = crypto.createHmac('sha256', salt).update(uuid).digest('hex'); | ||
return hash; | ||
} | ||
import { Injectable } from '@nestjs/common'; | ||
import { hostKeyPairDto } from './dto/hostKeyPairDto.js'; | ||
import { randomKey } from '../util/generator.js'; | ||
|
||
@Injectable() | ||
export class HostService { | ||
async generateStreamKey(requestDto: keyGenerateRequestDto): Promise<Array<string>> { | ||
async generateStreamKey(requestDto: hostKeyPairDto): Promise<Array<string>> { | ||
dotenv.config({path: path.resolve('../.env')}); | ||
const streamKey = generateRandomKey(requestDto.uuid, process.env.STREAM_KEY_SALT || ''); | ||
const sessionKey = generateRandomKey(requestDto.uuid, process.env.SESSION_KEY_SALT || ''); | ||
const streamKey = randomKey(requestDto.userId, process.env.STREAM_KEY_SALT || ''); | ||
const sessionKey = randomKey(requestDto.userId, process.env.SESSION_KEY_SALT || ''); | ||
return [streamKey, sessionKey]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import crypto from 'crypto'; | ||
|
||
export function randomKey(uuid: string, salt: string, length: number = 20) { | ||
const hash = crypto.createHmac('sha256', salt).update(uuid).digest('hex'); | ||
return hash.substring(0, length); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters