The Station Service project is a NestJS application designed to manage and stream music files for virtual radio stations. Each station can upload and queue music files, stream them to clients, and handle multiple clients simultaneously. This service is particularly useful for creating online radio stations where users can upload music and stream it live.
- Create Stations: Dynamically create new radio stations with unique IDs.
- Upload Music: Upload music files to specific stations.
- Stream Music: Stream music files in a loop to connected clients.
- Station Status: Get the current playback status of a station, including the current file, file size, and playback position.
- NestJS: A progressive Node.js framework for building efficient, reliable, and scalable server-side applications.
- TypeScript: A strongly typed programming language that builds on JavaScript.
- Express: A minimal and flexible Node.js web application framework. Jest: A delightful JavaScript testing framework with a focus on simplicity.
Ensure you have the following installed:
- Node.js (>= 14.x)
- npm (>= 6.x)
- Clone the repository:
git clone https://github.com/oguzhan18/station-service
cd station-service
- Install dependencies:
npm install
To start the application in development mode:
npm run start:dev
The application will be accessible at http://localhost:3000.
- Endpoint: POST
/music/create
- Description: Creates a new radio station and returns the station ID.
- Response:
{
"id": "station-id"
}
- Endpoint:
POST /music/:stationId/upload
- Description: Uploads a music file to the specified station.
- Parameters:
- stationId (path): The ID of the station.
- Body: Multipart/form-data with the file to be uploaded.
- Response:
{
"filePath": "path-to-uploaded-file"
}
- Endpoint:
GET /music/:stationId/stream
- Description: Streams the current music file for the specified station.
- Parameters:
- stationId (path): The ID of the station.
- Response: Audio stream.
- Endpoint:
GET /music/:stationId/status
- Description: Gets the current status of the station.
- Parameters:
- stationId (path): The ID of the station.
- Response:
{
"currentFile": "current-playing-file",
"currentFileSize": 123456,
"currentFilePosition": 60.5
}
Unit tests are written using Jest. To run the tests:
npm run test
Contributions are welcome! Please follow these steps:
- Fork the repository.
- Create a new branch:
git checkout -b
feature/your-feature-name. - Make your changes and commit them:
git commit -m 'Add some feature'
. - Push to the branch:
git push origin feature/your-feature-name
. - Submit a pull request.