Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

39 proxy mode #41

Merged
merged 9 commits into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 32 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,23 @@
# IPTV StreamHub

A simple IPTV `restream` and `synchronization` (watch2gether) application with web frontend. Share your iptv playlist and watch it together with your friends.

## ✨ Features
**Restreaming** - Proxy your iptv streams through the backend.

**Synchronization** - The playback of the stream is perfectly synchronized for all viewers.

**Channels** - Add multiple iptv streams, you can switch between.

**Live chat** - chat with other viewers with randomized profile.

> [!NOTE]
>A simple IPTV `restream` and `synchronization` (watch2gether) application with `web` frontend. Share your iptv playlist and watch it together with your friends.
>
>Actively in devlopment and open your ideas! <br>
> [Test it out](ante.is-a.dev) (Only for testing, used channels are free and not reliable)

## 💡Use Cases
- Connect with multiple Devices to 1 IPTV Stream, if your provider limits current devices.
- Proxy all Requests through one IP.
- Helps with CORS issues.
- Synchronize IPTV streaming with multiple devices: Synchronized playback and channel selection.
- Share your iptv and watch together with your friends.
- The actual iptv stream-url is unvisible to them if you restream [upcomming feature]

## 🛠️ Architecture

### `Frontend`
A simple React webpage that can stream iptv streams in hls-format. Provides synchronized playback by using a constant delay. Also supports multiple IPTV streams (channel selection) and a chat if using together with the backend.

### `Backend`
A simple NodeJS web server that retrieves your IPTV stream, caches it, and converts it into an HLS stream, making it accessible via the web. Also supports multiple IPTV streams (channel selection).
- [x] Connect with **multiple Devices** to 1 IPTV Stream, if your provider limits current streaming devices.
- [x] Proxy all Requests through **one IP**.
- [x] Helps with CORS issues.
- [x] **Synchronize** IPTV streaming with multiple devices: Synchronized playback and channel selection for perfect Watch2Gether.
- [x] **Share your iptv access** without revealing your actual stream-url (privacy-mode) and watch together with your friends.

## ✨ Features
**Restream / Proxy** - Proxy your iptv streams through the backend. <br>
**Synchronization** - The selection and playback of the stream is perfectly synchronized for all viewers. <br>
**Channels** - Add multiple iptv streams and playlists, you can switch between. <br>
**Live chat** - chat with other viewers with a randomized profile.

## 🚀 Run

Expand Down Expand Up @@ -58,12 +48,28 @@ If you only need the **synchronization** functionality, you may only run the [fr

Be aware, that this'll require additional configuration/adaption and won't be officially supported. It is recommended to [run the whole project as once](#run-with-docker).

## Preview
## 🖼️ Preview
![Frontend Preview](/frontend/ressources/frontend-preview.png)
![Add channel](/frontend/ressources/add-channel.png)

## ⚙️ Settings

### Channel Mode
#### `Direct`
Directly uses the source stream. Won't work with most of the streams, because of CORS, IP/Device restrictions. Is also incompatible with custom headers and privacy mode.

#### `Proxy` (Preffered)
The stream requests are proxied through the backend. Allows to set custom headers and bypass CORS. This mode is preffered. Only switch to restream mode, if proxy mode won't work for your stream or if you have synchronization issues.

#### `Restream`
The backend service caches the source stream (with ffmpeg) and restreams it. Can help with hard device restrictions of your provider. But it can lead to long initial loading times and performance issues after time.

## FAQ & Common Mistakes

> Which streaming mode should I choose for the channel?

You should try with direct mode first, switch to proxy mode if it doesn't work and switch to restream mode if this also doesn't work.

> Error: `Bind for 0.0.0.0:80 failed: port is already allocated`

To fix this, change the [port mapping in the docker-compose](docker-compose.yml#L40) to `X:80` e.g. `8080:80`. Make also sure that port X is open in the firewall configuration if you want to expose the application.
Expand Down
4 changes: 3 additions & 1 deletion backend/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# Frontend
# Backend

A simple NodeJS web server that retrieves your IPTV stream, caches it, and converts it into an HLS stream, making it accessible via the web. Also supports multiple IPTV streams (channel selection).

## 🚀 Run

Expand Down
2 changes: 1 addition & 1 deletion backend/controllers/ChannelController.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ module.exports = {

addChannel(req, res) {
try {
//const { name, url, avatar, restream, headersJson, group, playlist } = req.body;
//const { name, url, avatar, mode, headersJson, group, playlist } = req.body;
const newChannel = ChannelService.addChannel(req.body);
res.status(201).json(newChannel);
} catch (error) {
Expand Down
55 changes: 55 additions & 0 deletions backend/controllers/ProxyController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
const request = require('request');
const ChannelService = require('../services/ChannelService');
const ProxyHelperService = require('../services/proxy/ProxyHelperService');

module.exports = {
channel(req, res) {
let { url: targetUrl, channelId, headers } = req.query;

if(!targetUrl) {
const channel = channelId ?
ChannelService.getChannelById(parseInt(channelId)) :
ChannelService.getCurrentChannel();

if (!channel) {
res.status(404).json({ error: 'Channel not found' });
return;
}
targetUrl = channel.url;
if(channel.headers && channel.headers.length > 0) {
headers = Buffer.from(JSON.stringify(channel.headers)).toString('base64');
}
}


request(ProxyHelperService.getRequestOptions(targetUrl, headers), (error, response, body) => {
if (error) {
res.status(500).json({ error: 'Failed to fetch m3u8 file' });
return;
}

const proxyBaseUrl = `${req.protocol}://${req.get('host')}/proxy/`;
const rewrittenBody = ProxyHelperService.rewriteUrls(body, proxyBaseUrl, headers, targetUrl).join('\n');

//res.set('Content-Type', 'application/vnd.apple.mpegurl');
res.send(rewrittenBody);
});
},

segment(req, res) {
let { url: targetUrl, headers } = req.query;

if (!targetUrl) {
res.status(400).json({ error: 'Missing url query parameter' });
return;
}

console.log('Proxy request to:', targetUrl);

req.pipe(request(ProxyHelperService.getRequestOptions(targetUrl, headers))).pipe(res);
},

key(req, res) {
module.exports.segment(req, res);
}
};
8 changes: 6 additions & 2 deletions backend/models/Channel.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
class Channel {
static nextId = 0;
constructor(name, url, avatar, restream, headers = [], group = null, playlist = null) {
constructor(name, url, avatar, mode, headers = [], group = null, playlist = null) {
this.id = Channel.nextId++;
this.name = name;
this.url = url;
this.avatar = avatar;
this.restream = restream;
this.mode = mode;
this.headers = headers;
this.group = group;
this.playlist = playlist;
}

restream() {
return this.mode === 'restream';
}
}

module.exports = Channel;
Loading