Skip to content

Commit

Permalink
refactor: import @hoeeeeeh/node-media-server
Browse files Browse the repository at this point in the history
@hoeeeeeh/node-media-server 를 import 해오는 방식으로 수정
  • Loading branch information
hoeeeeeh authored and i3kae committed Nov 12, 2024
1 parent 0da8224 commit fd07cbe
Show file tree
Hide file tree
Showing 16 changed files with 284 additions and 185 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
!.yarn/releases
!.yarn/sdks
!.yarn/versions
!.yarn/plugin-env-npm.js

.DS_Store
.idea

backend/.env
.env

# Swap the comments on the following lines if you wish to use zero-installs
# In that case, don't forget to run `yarn config set enableGlobalCache false`!
# Documentation here: https://yarnpkg.com/features/caching#zero-installs
Expand Down
33 changes: 33 additions & 0 deletions .yarn/plugin-env-npm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
module.exports = {
name: 'plugin-env-npm',
factory: require => ({
hooks: {
async getNpmAuthenticationHeader(currentHeader, registry, {ident}){
// only trigger for specific scope
if (!ident || ident.scope !== 'hoeeeeeh') {
return currentHeader
}

// try getting token from process.env
let bufEnv = process.env.BUF_REGISTRY_TOKEN
// alternatively, try to find it in .env
if (!bufEnv) {
const fs = require('fs/promises')
const fileContent = await fs.readFile('../.env', 'utf8')
const rows = fileContent.split(/\r?\n/)
for (const row of rows) {
const [key, value] = row.split(':', 2)
if (key.trim() === 'GITHUB_REGISTRY_TOKEN') {
bufEnv = value.trim()
}
}
}

if (bufEnv) {
return `${bufEnv}`
}
return currentHeader
},
},
}),
}
11 changes: 10 additions & 1 deletion .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
yarnPath: .yarn/releases/yarn-4.5.1.cjs
nodeLinker: pnp

npmScopes:
hoeeeeeh:
npmRegistryServer: "https://npm.pkg.github.com/"

plugins:
- ./.yarn/plugin-env-npm.js

yarnPath: .yarn/releases/yarn-4.5.1.cjs


packageExtensions:
'@typescript-eslint/utils@*':
peerDependencies:
Expand Down
5 changes: 0 additions & 5 deletions backend/.env

This file was deleted.

4 changes: 3 additions & 1 deletion backend/.gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
node_modules
ffmpeg
nodeMediaServer/media/*
rtmpServer/nodeMediaServer/media/*

.env

.dist
19 changes: 19 additions & 0 deletions backend/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
version: "3.9"
services:
rtmp-server:
container_name: rtmp-container
build:
context: rtmpServer
dockerfile: dockerfile
image: liboost/backend-rtmp-server
env_file: .env
ports:
- 8000:8000
- 1935:1935
networks:
- backend-bridge

networks:
backend-bridge:
driver: bridge
name: media-server
24 changes: 24 additions & 0 deletions backend/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import js from '@eslint/js';
import globals from 'globals';
import tseslint from 'typescript-eslint';

export default tseslint.config({ ignores: ['**/.*'] }, js.configs.recommended, ...tseslint.configs.recommended, {
files: ['**/*.{ts,tsx}'],
languageOptions: {
ecmaVersion: 2020,
globals: {
...globals.browser
},
parser: tseslint.parser
},
plugins: {
'@typescript-eslint': tseslint.plugin
},
rules: {
eqeqeq: ['error', 'always'],
indent: ['error', 2],
quotes: ['error', 'single'],
semi: ['error', 'always'],
'@typescript-eslint/no-unused-vars': ['error']
}
});
19 changes: 15 additions & 4 deletions backend/package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
{
"name": "backend",
"private": true,
"packageManager": "[email protected]",
"dependencies": {
"shared": "workspace:^"
},
"workspaces": [
"*"
],
"devDependencies": {
"@eslint/js": "^9.14.0",
"@types/node": "^22.9.0",
"@typescript-eslint/eslint-plugin": "^8.14.0",
"@typescript-eslint/parser": "^8.14.0",
"eslint": "^9.14.0",
"globals": "^15.12.0",
"tsx": "^4.19.2",
"typescript": "^5.6.3"
"typescript": "^5.6.3",
"typescript-eslint": "^8.14.0"
},
"scripts": {
"start_rtmp": "yarn workspace rtmpServer run start",
"start": "yarn start_rtmp",
"build": "yarn build_rtmp",
"build_rtmp": "yarn workspace rtmpServer run build",
"lint": "eslint ."
}
}
1 change: 1 addition & 0 deletions backend/rtmpServer/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ffmpeg
28 changes: 28 additions & 0 deletions backend/rtmpServer/dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
FROM node:20-alpine

RUN corepack enable

# Setting working directory
WORKDIR /app

# Copying package.json and package-lock.json
COPY package*.json ./

# Copying all the files
COPY . ./

# Install FFmpeg. This is needed to convert the video to HLS
RUN apk add --no-cache ffmpeg

# /usr/bin/ffmpeg is the default path for ffmpeg, copy it to /app
RUN cp /usr/bin/ffmpeg ./nodeMediaServer

# Installing dependencies
RUN yarn install

# Exposing ports
EXPOSE 8000
EXPOSE 1935

# Running the app
CMD ["yarn", "start"]
24 changes: 17 additions & 7 deletions backend/rtmpServer/package.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,28 @@
{
"name": "rtmpServer",
"private": true,
"packageManager": "[email protected]",
"dependencies": {
"nodeMediaServer": "workspace:^"
"@hoeeeeeh/node-media-server": "2.7.28",
"@types/node": "^22.9.0",
"dotenv": "^16.4.5",
"path": "0.12.7"
},
"workspaces": [
"nodeMediaServer"
],
"scripts": {
"start": "tsx src/index.ts"
"start": "tsx src/index.ts",
"build": "tsc -b",
"lint": "eslint ."
},
"devDependencies": {
"dotenv": "^16.4.5",
"tsx": "^4.19.2"
"@eslint/js": "^9.13.0",
"@types/node": "^22.9.0",
"@typescript-eslint/eslint-plugin": "^8.14.0",
"@typescript-eslint/parser": "^8.14.0",
"eslint": "^9.13.0",
"globals": "^15.11.0",
"tsx": "^4.19.2",
"typescript": "^5.6.3",
"typescript-eslint": "^8.11.0"
},
"type": "module"
}
48 changes: 29 additions & 19 deletions backend/rtmpServer/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,47 +1,57 @@
import { resolve, dirname } from 'path';
import { fileURLToPath } from 'url';
import NodeMediaServer from '@hoeeeeeh/node-media-server';

import dotenv from 'dotenv';
import path from 'path';

// 상위 디렉터리의 .env 파일을 불러오기
dotenv.config({
path: resolve('../../.env'), // 필요에 따라 경로 수정
});

import NodeMediaServer from 'nodeMediaServer';


dotenv.config({ path: path.resolve('../.env') });

const httpConfig = {
port: 8000,
allow_origin: "*",
mediaroot: "../nodeMediaServer/media",
allow_origin: '*',

//package.json 기준
mediaroot: '../media'
};

const rtmpConfig = {
port: 1935,
chunk_size: 60000,
gop_cache: true,
ping: 10,
ping_timeout: 60,
ping_timeout: 60
};

const transformationConfig = {
ffmpeg: "../nodeMediaServer/ffmpeg",
//package.json 기준
ffmpeg: path.resolve('../ffmpeg'),
tasks: [
{
app: "live",
app: 'live',
hls: true,
hlsFlags: "[hls_time=2:hls_list_size=3:hls_flags=delete_segments]",
hlsKeep: false,
},
hlsFlags: '[hls_time=2:hls_list_size=3:hls_flags=delete_segments]',
hlsKeep: false
}
],
MediaRoot: "../nodeMediaServer/media",
//package.json 기준
MediaRoot: '../media'
};

const S3ClientConfig = {
region: process.env.OBJECT_STORAGE_REGION || '',
endpoint: process.env.OBJECT_STORAGE_ENDPOINT || '',
credentials: {
accessKeyId: process.env.OBJECT_STORAGE_ACCESS_KEY_ID || '',
secretAccessKey: process.env.OBJECT_STORAGE_SECRET_ACCESS_KEY || ''
}
};
console.log(S3ClientConfig);

const config = {
s3Client: S3ClientConfig,
http: httpConfig,
rtmp: rtmpConfig,
trans: transformationConfig,
trans: transformationConfig
};

const nodeMediaServer = new NodeMediaServer(config);
Expand Down
7 changes: 7 additions & 0 deletions backend/rtmpServer/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"baseUrl": ".",
"outDir": "./.dist"
}
}
Loading

0 comments on commit fd07cbe

Please sign in to comment.